Skip to content

AI Module (@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 { askAi } from "@microfn/ai";
async function getResponse({ query }) {
const response = await askAi(query);
return { query, response };
}

Here are a few useful things you can do with @microfn/ai:

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 };
}

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 };
}

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 };
}