AI Module (@microfn/ai)
@microfn/ai
Section titled “@microfn/ai”The @microfn/ai
module allows you to send queries to an AI language model and receive intelligent responses. Use it for text generation, data analysis, content summarization, translation, and more.
Import
Section titled “Import”import { askAi } from "@microfn/ai";
Quick Snippet
Section titled “Quick Snippet”async function getResponse({ query }) { const response = await askAi(query); return { query, response };}
Examples
Section titled “Examples”Here are a few useful things you can do with @microfn/ai
:
1. Summarize content
Section titled “1. Summarize content”Quickly summarize long articles or text.
import { askAi } from "@microfn/ai";
export default async function main({ articleContent }) { const summary = await askAi( `Summarize this article in 3 bullet points: ${articleContent}`, { temperature: 0.3 } ); return { summary };}
2. Translate text
Section titled “2. Translate text”Translate text between different languages.
import { askAi } from "@microfn/ai";
export default async function main({ text, targetLanguage }) { const translation = await askAi( `Translate to ${targetLanguage}: ${text}`, { systemPrompt: "You are a professional translator. Provide accurate, natural-sounding translations.", temperature: 0.2 } ); return { original: text, translated: translation };}
3. Generate code
Section titled “3. Generate code”Create code snippets based on a description.
import { askAi } from "@microfn/ai";
export default async function main({ description, language }) { const code = await askAi( `Write a ${language} function that: ${description}`, { systemPrompt: "You are an expert programmer. Generate clean, efficient, well-commented code.", temperature: 0.4 } ); return { description, code };}