| Crates.io | sakura-ai-rs |
| lib.rs | sakura-ai-rs |
| version | 0.1.2 |
| created_at | 2025-09-26 12:26:14.890987+00 |
| updated_at | 2025-09-27 06:49:31.814808+00 |
| description | A Rust library for interacting with the Sakura AI Engine |
| homepage | https://github.com/stn/sakura-ai-rs |
| repository | https://github.com/stn/sakura-ai-rs |
| max_upload_size | |
| id | 1855817 |
| size | 88,383 |
ollama-rsと互換性を持つことで既存のコードを最小限の変更で再利用できるようにしています。
※現在はChat Completionのみをサポート
ollama-rsとsakura-ai-rsをCargo.tomlのdependenciesに追加
cargo add sakura-ai-rs
cargo add ollama-rs
アカウントトークンを作成し、環境変数SAKURA_AI_ENGINE_API_KEYに設定します。
# macOS / Linux
export SAKURA_AI_ENGINE_API_KEY='...'
# Windows PowerShell
$env:SAKURA_AI_ENGINE_API_KEY = '...'
use sakura_ai_rs::SakuraAI;
let sakura = SakuraAI::default();
send_chat_messagesを用いてSakura AI EngineのChat Completionを呼び出す。
use ollama_rs::generation::chat::{ChatMessage, ChatMessageRequest};
use ollama_rs::history::ChatHistory;
use sakura_ai_rs::SakuraAI;
let sakura = SakuraAI::default();
let model = "gpt-oss-120b".to_string();
let prompt = "Why is the sky blue?".to_string();
let res = sakura
.send_chat_messages(
ChatMessageRequest::new(
model,
vec![ChatMessage::user(prompt)],
),
)
.await;
if let Ok(res) = res {
println!("{}", res.message.content);
}
send_chat_messages_streamの使用例はexamples/chat_api_chatbot.rsを参考に。
> cargo run --example chat_api_chatbot
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
Running `target\debug\examples\chat_api_chatbot.exe`
> こんにちは
こんにちは!今日はどのようなお手伝いが必要ですか?
>
send_chat_messages_with_historyを用いると会話履歴も管理される。
use ollama_rs::generation::chat::{ChatMessage, ChatMessageRequest};
use ollama_rs::history::ChatHistory;
let model = "llama2:latest".to_string();
let prompt = "Why is the sky blue?".to_string();
// `Vec<ChatMessage>` implements `ChatHistory`,
// but you could also implement it yourself on a custom type
let mut history = vec![];
let res = sakura
.send_chat_messages_with_history(
&mut history, // <- messages will be saved here
ChatMessageRequest::new(
model,
vec![ChatMessage::user(prompt)], // <- You should provide only one message
),
)
.await;
if let Ok(res) = res {
println!("{}", res.message.content);
}
examples/chat_with_history.rsとexamples/chat_with_history_stream.rsを参考に。
上の例をollama-rsと比較すると分かる通り、ollama_rs::Ollamaの代わりにsakura_ai_rs::SakuraAIを使用すればよい。
入出力のオブジェクトには同じものを使用しているため、それ以外のコードは同じ。
現在、send_chat_messages, send_chat_messages_stream, send_chat_messages_with_history, send_chat_messages_with_history_stream がサポートされている。