Skip to content

dravenk/ollama-zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ollama Zig Library

The Ollama Zig library provides the easiest way to integrate Zig 1.13+ projects with Ollama.

Prerequisites

  • Ollama should be installed and running
  • Pull a model to use with the library: ollama pull <model> e.g. ollama pull llama3.2
    • See Ollama.com for more information on the models available.

Install

zig fetch --save git+https://github.com/dravenk/ollama-zig.git

Usage

Adding to build.zig

    const ollama = b.dependency("ollama-zig", .{
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("ollama", ollama.module("ollama"));

Import it in your code:

const ollama = @import("ollama");

See types.zig for more information on the response types.

Streaming responses

Response streaming can be enabled by setting stream=True.

API

The Ollama Zig library's API is designed around the Ollama REST API

Chat

const message = &[_]Ollama.chatOptions.message{
    .{ .role = "user", .content = "Why is the sky blue?" },
};
const response = try ollama.chat(.{ .model = "llama3.2", .messages = message });

Generate

ollama.generate(model='llama3.2', prompt='Why is the sky blue?')

List

ollama.list()

Show

ollama.show('llama3.2')

Create

modelfile='''
FROM llama3.2
SYSTEM You are mario from super mario bros.
'''

ollama.create(model='example', modelfile=modelfile)

Copy

ollama.copy('llama3.2', 'user/llama3.2')

Delete

ollama.delete('llama3.2')

Pull

ollama.pull('llama3.2')

Push

ollama.push('user/llama3.2')

Embed

ollama.embed(model='llama3.2', input='The sky is blue because of rayleigh scattering')

Embed (batch)

ollama.embed(model='llama3.2', input=['The sky is blue because of rayleigh scattering', 'Grass is green because of chlorophyll'])

Ps

ollama.ps()

Errors

Errors are raised if requests return an error status or if an error is detected while streaming.

About

Ollama Zig library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages