aboutsummaryrefslogtreecommitdiff
path: root/src/app/llm.rs
diff options
context:
space:
mode:
authorOxbian <oxbian@mailbox.org>2025-05-17 23:30:07 -0400
committerOxbian <oxbian@mailbox.org>2025-05-17 23:30:07 -0400
commitfecb211130ec487c7c617d28419c6d0097f19783 (patch)
treeade91c5eefb7d9af6f68357f897d4b670f325f81 /src/app/llm.rs
parentdd9808b10c98c28a493eac78742fc403efc70e32 (diff)
downloadNAI-fecb211130ec487c7c617d28419c6d0097f19783.tar.gz
NAI-fecb211130ec487c7c617d28419c6d0097f19783.zip
feat: wikipedia module
Diffstat (limited to 'src/app/llm.rs')
-rw-r--r--src/app/llm.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/app/llm.rs b/src/app/llm.rs
index 9c6d222..979b790 100644
--- a/src/app/llm.rs
+++ b/src/app/llm.rs
@@ -15,7 +15,7 @@ pub struct LLM {
}
impl LLM {
- pub fn new(config_file: String) -> LLM {
+ pub fn new(config_file: &str) -> LLM {
let contents = fs::read_to_string(config_file).unwrap();
serde_json::from_str(&contents).unwrap()
}
@@ -40,7 +40,7 @@ impl LLM {
while let Some(chunk) = res.chunk().await? {
let answer: Value = serde_json::from_slice(chunk.as_ref())?;
- warn(answer.to_string());
+ //warn(answer.to_string());
if answer["done"].as_bool().unwrap_or(false) {
break;
}
@@ -59,7 +59,7 @@ impl LLM {
// Use tools functionnality of Ollama, only some models supports it:
// https://ollama.com/search?c=tools
- pub async fn ask_format(&self, messages: &Vec<Message>) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
+ pub async fn ask_tools(&self, messages: &Vec<Message>) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
let client = Client::new();
let response = client
.post(&self.url)
@@ -72,7 +72,7 @@ impl LLM {
.send()
.await?.json::<Value>().await?;
- warn(response.to_string());
+ //warn(response.to_string());
if let Some(tool_calls) = response
.get("message")
@@ -105,8 +105,8 @@ impl fmt::Display for MessageType {
#[derive(Debug, Serialize, Clone)]
pub struct Message {
- role: MessageType,
- content: String,
+ pub role: MessageType,
+ pub content: String,
}
impl Message {
@@ -114,6 +114,13 @@ impl Message {
Message { role, content }
}
+ pub fn default() -> Message {
+ Message {
+ role: MessageType::USER,
+ content: "".to_string(),
+ }
+ }
+
pub fn save_message(&self, conv_id: String) -> Result<(), Box<dyn std::error::Error>> {
// Create conv directory if doesn't exist
create_dir_all("conv")?;
ArKa projects. All rights to me, and your next child right arm.