Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent example uses DeepSeek. #3192

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ jobs:
cargo clippy --all-targets --all-features --target x86_64-unknown-linux-gnu --locked
cd agent
cargo fmt -- --check
cargo clippy --all-targets --all-features --locked

lint-cargo-clippy:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions examples/agent/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 examples/agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clap = { version = "4.5.26", features = ["derive"] }
reqwest = { version = "0.11.24", default-features = false, features = [
"rustls-tls",
] }
rig-core = "0.6.1"
rig-core = "0.7.0"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
tokio = { version = "1.25.0", features = ["macros", "rt-multi-thread"] }
Expand Down
45 changes: 33 additions & 12 deletions examples/agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use anyhow::Result;
use clap::Parser;
use reqwest::Client;
use rig::{

Check warning on line 9 in examples/agent/src/main.rs

View workflow job for this annotation

GitHub Actions / lint-wasm-applications

Diff in /home/runner/work/linera-protocol/linera-protocol/examples/agent/src/main.rs
agent::AgentBuilder,
completion::{Chat, Message, ToolDefinition},
providers::openai,
providers::{openai, deepseek},
tool::Tool,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -146,8 +146,7 @@
async fn main() {
let opt = Opt::parse();

let openai = openai::Client::from_env();
let model = openai.completion_model(&opt.model);
// let model = agent_from_opts(&opt.model);
let node_service = LineraNodeService::new(opt.node_service_url.parse().unwrap()).unwrap();

let graphql_def = node_service.get_graphql_definition().await.unwrap();
Expand All @@ -156,15 +155,7 @@
graphql_def
);

// Configure the agent
let agent = AgentBuilder::new(model)
.preamble(PREAMBLE)
.context(LINERA_CONTEXT)
.context(&graphql_context)
.tool(node_service)
.build();

chat(agent).await;
start_chat(&opt.model, &graphql_context, node_service).await;
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -239,6 +230,36 @@
}
}

async fn start_chat(model_name: &str, graphql_context: &str, node_service: LineraNodeService) {
match model_name {
_ if model_name.starts_with("gpt") => {
let openai = openai::Client::from_env();
let model = openai.completion_model(model_name);
let agent = AgentBuilder::new(model)
.preamble(PREAMBLE)
.context(LINERA_CONTEXT)
.context(graphql_context)
.tool(node_service)
.build();

chat(agent).await;
}
_ if model_name.starts_with("deepseek") => {
let deepseek = deepseek::Client::from_env();
let model = deepseek.completion_model(model_name);
let agent = AgentBuilder::new(model)
.preamble(PREAMBLE)
.context(LINERA_CONTEXT)
.context(graphql_context)
.tool(node_service)
.build();

chat(agent).await;
}
_ => panic!("Model {model_name} not recoginised. Try `gpt-*` or `deepseek-*`"),
}
}

pub async fn chat(chatbot: impl Chat) {
let stdin = io::stdin();
let mut stdout = io::stdout();
Expand Down
Loading