-
Notifications
You must be signed in to change notification settings - Fork 140
/
cohere_connector.rs
50 lines (42 loc) · 1.65 KB
/
cohere_connector.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::env;
use rig::{
completion::{Completion, Prompt},
providers::cohere::Client as CohereClient,
};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
// Create Cohere client
let cohere_api_key = env::var("COHERE_API_KEY").expect("COHERE_API_KEY not set");
let cohere_client = CohereClient::new(&cohere_api_key);
let klimadao_agent = cohere_client
.agent("command-r")
.temperature(0.0)
.additional_params(json!({
"connectors": [{"id":"web-search", "options":{"site": "https://docs.klimadao.finance"}}]
}))
.build();
// Prompt the model and print the response
// We use `prompt` to get a simple response from the model as a String
let response = klimadao_agent.prompt("Tell me about BCT tokens?").await?;
println!("\n\nCoral: {:?}", response);
// Prompt the model and get the citations
// We use `completion` to allow use to customize the request further and
// get a more detailed response from the model.
// Here the response is of type CompletionResponse<cohere::CompletionResponse>
// which contains `choice` (Message or ToolCall) as well as `raw_response`,
// the underlying providers' raw response.
let response = klimadao_agent
.completion("Tell me about BCT tokens?", vec![])
.await?
.additional_params(json!({
"connectors": [{"id":"web-search", "options":{"site": "https://docs.klimadao.finance"}}]
}))
.send()
.await?;
println!(
"\n\nCoral: {:?}\n\nCitations:\n{:?}",
response.choice, response.raw_response.citations
);
Ok(())
}