@amatelic/oa
v0.0.203
Published
Libary for easies interaction with Ollama api
Readme
OA
A library for easier construction and interaction with Ollama.
Table of Contents
Installation
npm install @amatelic/oaBasi Usage
The api supports two types of responses. Streaming and non-streaming. Below you can see the example of the streaming version
Streaming Response
import { oa } from "@amatelic/oa";
async function main() {
const { prompt } = await oa({
model: "qwen2.5vl:3b",
stream: true,
});
const iterator = await prompt("What is the capital of Slovenia?").call();
for await (const part of iterator) {
console.log(part);
}
}
main();Non-Streaming Response
// non streaming version
import { oa } from "@amatelic/oa";
async function main() {
const { prompt } = await oa({
model: "qwen2.5vl:3b",
stream: false,
});
const prompt = await prompt("What is the capital of Slovenia?").call();
console.log(promptConfig.message.content));
}
main()
Tool Calling
const { tool, prompt } = await oa({
...config,
model: "qwen3:4b",
stream: false,
});
const weatherTool = {
type: "string",
function: {
name: "weather",
description: "Get the weather for a given city",
parameters: {
type: "object",
properties: {
city: {
type: "string",
description: "The city to get the weather for",
},
},
required: ["city"],
},
},
};
const weatherToolPrompt = tool({
tools: [weatherTool],
exec: {
[weatherTool.function.name]: (args: { city: string }) => {
return Promise.resolve(args.city);
},
},
});
const response = await weatherToolPrompt(
prompt("Get the weather for New York"),
);
console.log(response.message.content) // "New York"Data Sources
Utility functions for importing data into prompts:
- search: Get multiple links related to the query (uses Ollama API)
import { oa, source, utils } from "@amatelic/oa";
const { search } = source;
const { pipe } = utils;
const { prompt } = await oa({
model: "qwen2.5-coder:7b",
stream: false,
});
const url = "https://gdo-studio.si";
const data = await pipe(search(url), [
prompt("Make a readme for the links"),
]);
- web: Get content from a single website (uses Ollama API)
- csv: Support for importing CSV files to prompts
- generateText: Helper function for generating random text
Ollama Search
To use Ollama search functionality, you need to provide an Ollama API key.
Generate API Key
You can generate an API key at ollama.ai
Environment Variable
OLLAMA_KEY=your_api_key_here