Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
.PHONY: fmt test prepare _ensure_ollama_create _ensure_ollama_model

fmt:
cargo fmt
cargo clippy --fix --allow-dirty
cargo clippy --fix --allow-dirty

test: prepare
cargo test

prepare:
@$(MAKE) _ensure_ollama_create NAME=mario MODELFILE=ollama-rs/tests/model/Modelfile.mario
@$(MAKE) _ensure_ollama_create NAME=test_model MODELFILE=ollama-rs/tests/model/Modelfile.test_model
@$(MAKE) _ensure_ollama_model MODEL=llama2:latest
@$(MAKE) _ensure_ollama_model MODEL=granite-code:3b
@$(MAKE) _ensure_ollama_model MODEL=llava:latest

_ensure_ollama_create:
@ollama list 2>/dev/null | awk 'NR>1 {print $$1}' | grep -qxF '$(if $(strip $(MODEL)),$(MODEL),$(NAME):latest)' || ollama create '$(NAME)' -f '$(MODELFILE)'

_ensure_ollama_model:
@ollama list 2>/dev/null | awk 'NR>1 {print $$1}' | grep -qxF '$(MODEL)' || ollama pull '$(MODEL)'
16 changes: 15 additions & 1 deletion ollama-rs/src/generation/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ impl<'de> Deserialize<'de> for FormatType {
/// Represents a serialized JSON schema. You can create this by converting
/// a JsonSchema:
/// ```rust
/// use schemars::{JsonSchema, schema_for};
/// use ollama_rs::generation::parameters::JsonStructure;
///
/// #[derive(JsonSchema)]
/// struct Output {
/// foo: i32
/// }
///
/// let json_schema = schema_for!(Output);
/// let serialized: SerializedJsonSchema = json_schema.into();
/// let serialized: JsonStructure = json_schema.into();
/// ```
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct JsonStructure {
Expand All @@ -105,6 +113,12 @@ impl JsonStructure {
}
}

impl From<Schema> for JsonStructure {
fn from(schema: Schema) -> Self {
Self { schema }
}
}

/// Used to control how long a model stays loaded in memory, by default models are unloaded after 5 minutes of inactivity
#[derive(Debug, Clone, PartialEq)]
pub enum KeepAlive {
Expand Down
2 changes: 1 addition & 1 deletion ollama-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod models;
///
/// ```
/// use url::Url;
/// use ollama_rs::IntoUrl;
/// use ollama_rs::IntoUrlSealed;
///
/// let url: Url = "http://example.com".into_url().unwrap();
/// ```
Expand Down
9 changes: 9 additions & 0 deletions ollama-rs/tests/model/Modelfile.mario
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM llama2

# set to 1 (higher is more creative, lower is more coherent)
PARAMETER temperature 1

# set the system prompt
SYSTEM """
You are Mario from Super Mario Bros. Anser as Mario, the asistant, only.
"""
1 change: 1 addition & 0 deletions ollama-rs/tests/model/Modelfile.test_model
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM llama2
9 changes: 7 additions & 2 deletions ollama-rs/tests/push_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ use tokio_stream::StreamExt;

#[tokio::test]
/// This test needs a local model named `test_model:latest` to work, and requires registering for ollama.ai and adding a public key first.
/// The model name should be in the form of `<username>/<model>:<tag>`.
async fn test_push_model() {
let ollama = Ollama::default();

let mut res = ollama
.push_model_stream("test_model:latest".into(), false)
let model_name = format!("{}/test_model:latest", env!("USER"));

ollama
.copy_model("test_model".into(), model_name.clone())
.await
.unwrap();

let mut res = ollama.push_model_stream(model_name, false).await.unwrap();

while let Some(res) = res.next().await {
match res {
Ok(res) => println!("{res:?}"),
Expand Down
Loading