Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dravenk/ollama-zig
Ollama Zig library
https://github.com/dravenk/ollama-zig
Last synced: 12 days ago
JSON representation
Ollama Zig library
- Host: GitHub
- URL: https://github.com/dravenk/ollama-zig
- Owner: dravenk
- License: mit
- Created: 2025-01-07T11:18:13.000Z (28 days ago)
- Default Branch: main
- Last Pushed: 2025-01-15T15:49:48.000Z (20 days ago)
- Last Synced: 2025-01-19T16:29:04.389Z (16 days ago)
- Language: Zig
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - ollama-zig
README
# Ollama Zig Library
The Ollama Zig library provides the easiest way to integrate Zig 1.13+ projects with [Ollama](https://github.com/ollama/ollama).
## Prerequisites
- [Ollama](https://ollama.com/download) should be installed and running
- Pull a model to use with the library: `ollama pull ` e.g. `ollama pull llama3.2`
- See [Ollama.com](https://ollama.com/search) for more information on the models available.## Install
```sh
zig fetch --save git+https://github.com/dravenk/ollama-zig.git
```## Usage
Adding to build.zig
```zig
const ollama = b.dependency("ollama-zig", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("ollama", ollama.module("ollama"));
```Import it in your code:
```zig
const ollama = @import("ollama");
```See [types.zig](ollama/src/types.zig) for more information on the response types.
## Streaming responses
Response streaming can be enabled by setting `stream=True`.
```zig
```## API
The Ollama Zig library's API is designed around the [Ollama REST API](https://github.com/ollama/ollama/blob/main/docs/api.md)
### Chat
```zig
const message = &[_]Ollama.chatOptions.message{
.{ .role = "user", .content = "Why is the sky blue?" },
};
const response = try ollama.chat(.{ .model = "llama3.2", .messages = message });
```### Generate
```zig
ollama.generate(model='llama3.2', prompt='Why is the sky blue?')
```### List
```zig
ollama.list()
```### Show
```zig
ollama.show('llama3.2')
```### Create
```zig
modelfile='''
FROM llama3.2
SYSTEM You are mario from super mario bros.
'''ollama.create(model='example', modelfile=modelfile)
```### Copy
```zig
ollama.copy('llama3.2', 'user/llama3.2')
```### Delete
```zig
ollama.delete('llama3.2')
```### Pull
```zig
ollama.pull('llama3.2')
```### Push
```zig
ollama.push('user/llama3.2')
```### Embed
```zig
ollama.embed(model='llama3.2', input='The sky is blue because of rayleigh scattering')
```### Embed (batch)
```zig
ollama.embed(model='llama3.2', input=['The sky is blue because of rayleigh scattering', 'Grass is green because of chlorophyll'])
```### Ps
```zig
ollama.ps()
```## Errors
Errors are raised if requests return an error status or if an error is detected while streaming.
```zig
```