No description
Find a file
2024-09-25 15:41:39 -04:00
.github/workflows main 2024-09-25 15:40:59 -04:00
examples add examples 2024-09-25 14:46:28 -04:00
src tidy up docs 2024-09-25 14:56:25 -04:00
tests make content optional for image-only requests 2024-07-28 17:33:11 -04:00
.gitignore ignore *.out files 2023-06-15 10:38:23 -07:00
LICENSE update template 2023-01-01 00:53:13 -06:00
llama_leap.nimble v1.2.0 2024-09-25 15:41:39 -04:00
README.md add examples 2024-09-25 14:46:28 -04:00

llama_leap

  • Nim library to work with the Ollama API

Example

  • API baseurl defaults to http://localhost:11434/api
  • you may pass an alternate to newOllamaAPI()
import llama_leap

let ollama = newOllamaAPI()
echo ollama.generate("llama2", "How are you today?")

Generate

  • Only the non-streaming generate API is currently supported
    • streaming is coming soon (TM)
# simple interface
echo ollama.generate("llama2", "How are you today?")

# structured interface
let req = GenerateReq(
  model: "llama2",
  prompt: "How are you today?",
  options: option(ModelParameters(
    temperature: option(0.0f),
  )),
  system: option("Please talk like a pirate. You are Longbeard the llama.")
)
let resp = ollama.generate(req)
echo "> " & resp.response

Chat

let req = ChatReq(
  model: "llama2",
  messages: @[
    ChatMessage(
      role: "system",
      content: "Please talk like a pirate. You are Longbeard the llama."
  ),
  ChatMessage(
    role: "user",
    content: "How are you today?"
  ),
],
  options: option(ModelParameters(
    temperature: option(0.0f),
    seed: option(42)
  ))
)
let resp = ollama.chat(req)
echo "> " & resp.message.content.strip()

Pull

ollama.pullModel("llama2")

Embeddings

let resp = ollama.generateEmbeddings("llama2", "How are you today?")
echo "Embedding Length: " & $resp.embedding.len

Testing

  • ensure ollama is running on the default port
    • ./ollama serve
  • run nimble test
  • llama_leap is a Nim client for the OpenAI API.
  • vertex_leap is a client for Google's VertexAI API.
  • mono_llm is a higher-level Nim library that creates a unified interface for OpenAI, Ollama, and VertexAI.