-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from raphaelmansuy:feat/ollamaoptions
Feat/ollamaoptions
- Loading branch information
Showing
14 changed files
with
621 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use futures::TryStreamExt; | ||
use std::io::{self, Write}; | ||
|
||
use crate::ollama::{ChatRequestBuilder, Message, OllamaClient, OllamaError, OptionsBuilder}; | ||
|
||
pub async fn demo_chat_with_ollama_with_stream() -> Result<(), OllamaError> { | ||
let client = OllamaClient::new("http://localhost:11434".to_string()); | ||
|
||
let messages = vec![Message::new( | ||
"user".to_string(), | ||
"What is the capital of France? " | ||
.to_string(), | ||
)]; | ||
|
||
let options = OptionsBuilder::new() | ||
.num_predict(100) // Limit the number of predicted tokens | ||
.temperature(0.4); | ||
|
||
let request = ChatRequestBuilder::new("mistral".to_string()) | ||
.messages(messages.to_owned()) | ||
.options_from_builder(options) | ||
.build(); | ||
|
||
let response_stream = client.chat(request).await?; | ||
|
||
let result = response_stream | ||
.try_for_each(|chunk| async { | ||
let message = chunk.message; | ||
print!("{}", message.content); | ||
// Flush the output to ensure the prompt is displayed. | ||
io::stdout().flush().unwrap(); | ||
Ok(()) | ||
}) | ||
.await; | ||
|
||
result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[tokio::test] | ||
async fn test_demo_chat_with_ollama_with_stream() { | ||
let _ = demo_chat_with_ollama_with_stream().await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
pub mod simple_examples; | ||
|
||
pub mod demo_ollama; | ||
pub mod demo_chat_with_ollama; | ||
pub mod demo_ollama_embedding; | ||
pub mod demo_bedrock_raw_generate; | ||
pub mod demo_bedrock_raw_stream; | ||
pub mod demo_bedrock_raw_mistral; | ||
pub mod demo_claude_chat; | ||
pub mod demo_claude_chat_stream; | ||
pub mod demo_claude_multimedia; | ||
pub mod demo_ollama_embedding; | ||
pub mod demo_mistral_stream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
pub mod ollama_client; | ||
pub mod model; | ||
pub mod error; | ||
pub mod options; | ||
|
||
pub use error::OllamaError; | ||
pub use ollama_client::OllamaClient; | ||
pub use model::{ GenerateRequest, GenerateRequestBuilder, GenerateResponse }; | ||
pub use model::{ ChatRequest, ChatRequestBuilder, ChatResponse, Message }; | ||
pub use model::{ EmbeddingsRequest,EmbeddingsResponse, EmbeddingsRequestBuilder}; | ||
pub use model::{ EmbeddingsRequest,EmbeddingsResponse, EmbeddingsRequestBuilder}; | ||
pub use options::OptionsBuilder; |
Oops, something went wrong.