Access local LLMs through Ollama's OpenAI-compatible API.
ollama serveollama pull mistral (or any model you want)ollama = require("ollama")
response = ollama.prompt("What is Ollama?")
print(response)
ollama = require("ollama")
// One-shot query
response = ollama.prompt("Explain machine learning simply")
// Multi-turn conversation
chat = ollama.session({
system = "You are a helpful coding assistant",
model = "mistral"
})
response1 = chat.prompt("How do I write a loop?")
response2 = chat.prompt("Can you show an example?")
print(chat.usage)
Default: http://localhost:11434
To use a different host/port, modify the endpoint in ollama.du.
Run ollama list to see what you have installed. Popular choices:
mistral (default) - Fast and capablellama2 - Meta's Llama 2neural-chat - Intel's modelorca-mini - Small and quickdolphin-mixtral - Uncensored MixtralPull new models: ollama pull <model-name>
Ollama runs locally - no authentication needed.
Same as OpenAI module - see openai.md for full reference.
Key differences:
mistralhttp://localhost:11434/v1/chat/completions