Skip to content

Commit

Permalink
Llm chat node 90%
Browse files Browse the repository at this point in the history
  • Loading branch information
dialogflowchatbot committed Aug 19, 2024
1 parent 2f3882b commit 4c855f0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/ai/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async fn ollama(
map.insert(String::from("options"), Value::from(num_predict));
let obj = Value::Object(map);
let body = serde_json::to_string(&obj)?;
log::info!("Request Ollama body {}", &body);
// log::info!("Request Ollama body {}", &body);
let req = client.post(u).body(body);
let res = req.send().await?;
match result_receiver {
Expand Down
18 changes: 11 additions & 7 deletions src/flow/rt/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl RuntimeNode for LlmChatNode {
return false;
}
let s = s_op.unwrap();
let ticket = String::new();
// let ticket = String::new();
let robot_id = req.robot_id.clone();
let prompt = self.prompt.clone();
let connect_timeout = self.connect_timeout.clone();
Expand All @@ -453,6 +453,7 @@ impl RuntimeNode for LlmChatNode {
});
false
} else {
let now = std::time::Instant::now();
let mut s = String::with_capacity(1024);
if let Err(e) = tokio::task::block_in_place(|| {
// log::info!("prompt |{}|", &self.prompt);
Expand All @@ -464,7 +465,7 @@ impl RuntimeNode for LlmChatNode {
ResultReceiver::StrBuf(&mut s),
))
}) {
log::info!("LlmChatNode response failed, err: {:?}", &e);
log::error!("LlmChatNode response failed, err: {:?}", &e);
match &self.when_timeout_then {
LlmChatNodeWhenTimeoutThen::GotoAnotherNode => {
ctx.node = None;
Expand All @@ -475,11 +476,14 @@ impl RuntimeNode for LlmChatNode {
LlmChatNodeWhenTimeoutThen::DoNothing => return false,
}
}
log::info!("LLM response {}", &s);
response.answers.push(AnswerData {
text: s,
answer_type: AnswerType::TextPlain,
});
log::info!("LLM response |{}|", &s);
if !s.is_empty() {
response.answers.push(AnswerData {
text: s,
answer_type: AnswerType::TextPlain,
});
}
log::info!("Llm response took {:?}", now.elapsed());
// let (s, rev) = std::sync::mpsc::channel::<String>();
// let robot_id = req.robot_id.clone();
// let prompt = self.prompt.clone();
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 4c855f0

Please sign in to comment.