-
Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathmain.rs
More file actions
69 lines (65 loc) · 2.07 KB
/
main.rs
File metadata and controls
69 lines (65 loc) · 2.07 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use rig::{
client::{CompletionClient, ProviderClient},
embeddings::EmbeddingsBuilder,
providers::{cohere, deepseek},
vector_store::in_memory_store::InMemoryVectorStore,
};
use tracing_appender::rolling::{RollingFileAppender, Rotation};
pub mod chat;
pub mod config;
pub mod mcp_adaptor;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let file_appender = RollingFileAppender::new(
Rotation::DAILY,
"logs",
format!("{}.log", env!("CARGO_CRATE_NAME")),
);
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::from_default_env()
.add_directive(tracing::Level::INFO.into()),
)
.with_writer(file_appender)
.with_file(false)
.with_ansi(false)
.init();
let config = config::Config::retrieve("config.toml").await?;
let deepseek_client = {
if let Some(key) = config.deepseek_key {
deepseek::Client::new(&key)?
} else {
deepseek::Client::from_env()
}
};
let cohere_client = {
if let Some(key) = config.cohere_key {
cohere::Client::new(&key)?
} else {
cohere::Client::from_env()
}
};
let mcp_manager = config.mcp.create_manager().await?;
tracing::info!(
"MCP Manager created, {} servers started",
mcp_manager.clients.len()
);
let tool_set = mcp_manager.get_tool_set().await?;
let embedding_model =
cohere_client.embedding_model(cohere::EMBED_MULTILINGUAL_V3, "search_document");
let embeddings = EmbeddingsBuilder::new(embedding_model.clone())
.documents(tool_set.schemas()?)?
.build()
.await?;
let store = InMemoryVectorStore::from_documents_with_id_f(embeddings, |f| {
tracing::info!("store tool {}", f.name);
f.name.clone()
});
let index = store.index(embedding_model);
let dpsk = deepseek_client
.agent(deepseek::DEEPSEEK_CHAT)
.dynamic_tools(4, index, tool_set)
.build();
chat::cli_chatbot(dpsk).await?;
Ok(())
}