Skip to content

Commit

Permalink
Merge branch 'main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
chardoncs committed Jul 26, 2024
2 parents 7b09c26 + 9a34e41 commit cff8818
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 32 deletions.
38 changes: 14 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ollama-rest"
version = "0.1.1"
version = "0.3.0"
edition = "2021"
description = "Asynchronous Rust bindings of Ollama REST API"
authors = ["Charles Dong <[email protected]>"]
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@ and [chrono](https://github.com/chronotope/chrono).
## Install

```bash
cargo add ollama-rest@0.1
cargo add ollama-rest@0.3
```

## Features

| name | status |
|----------------|-----------------|
| Completion | Working ✅ |
| Embedding | Working ✅ |
| Model creation | Working ✅ |
| Model deletion | Working ✅ |
| Model pulling | Working ✅ |
| Model copying | Working ✅ |
| Local models | Working ✅ |
| Running models | Working ✅ |
| Model pushing | Experimental 🧪 |
| Tools | Experimental 🧪 |

## At a glance

> See [source](./examples/generate_streamed.rs) of this example.
Expand Down Expand Up @@ -44,3 +59,4 @@ println!();
```

Or, make your own chatbot interface! See [this example](./examples/interactive-chat_streamed.rs) (CLI) and [this example](./examples/streaming-relay.rs) (REST API).

3 changes: 2 additions & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ pub mod create;
pub mod embeddings;
pub mod errors;
pub mod generate;
pub mod json_schema;
pub mod model;

/// Request format
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum RequestFormat {
/// JSON
///
/// Currently the one and only format support by Ollama
#[serde(rename = "json")]
Json,
}

Expand Down
25 changes: 20 additions & 5 deletions src/models/chat.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use std::{fmt::Display, str::FromStr};
use std::{collections::BTreeMap, fmt::Display, str::FromStr};

use chrono::{DateTime, Local};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};

use super::{errors::ParsingError, RequestFormat};
use super::{errors::ParsingError, json_schema::DataStructure, RequestFormat};

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Role {
#[serde(rename = "system")]
System,
#[serde(rename = "user")]
User,
#[serde(rename = "assistant")]
Assistant,
}

Expand All @@ -39,11 +37,24 @@ impl FromStr for Role {
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ToolCall {
Function {
name: String,
arguments: BTreeMap<String, Value>,
},
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Message {
pub role: Role,
pub content: String,
pub images: Option<Vec<String>>,
/// Tool calls
///
/// Since 0.3.0
pub tool_calls: Option<Vec<ToolCall>>,
}

/// Chat completion request
Expand All @@ -56,6 +67,10 @@ pub struct ChatRequest {
pub options: Option<Map<String, Value>>,
pub stream: Option<bool>,
pub keep_alive: Option<String>,
/// Tool definition
///
/// Since 0.3.0
pub tools: Option<Vec<DataStructure>>,
}

/// Chat completion response
Expand Down
40 changes: 40 additions & 0 deletions src/models/json_schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

/// Function definition
///
/// Since 0.3.0
#[derive(Debug, Serialize, Deserialize)]
pub struct FunctionDef {
pub name: String,
pub description: Option<String>,
pub parameters: Option<Box<DataStructure>>,
}

/// Partially implemented data structure definition
/// used in JSON schema
///
/// Since 0.3.0
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum DataStructure {
Function {
function: FunctionDef,
},
Integer {
description: Option<String>,
},
Number {
description: Option<String>,
},
Object {
properties: BTreeMap<String, DataStructure>,
required: Option<Vec<String>>,
},
String {
description: Option<String>,
#[serde(rename = "enum")]
enumeration: Option<Vec<String>>,
},
}

0 comments on commit cff8818

Please sign in to comment.