Skip to content

Commit

Permalink
content extracted from json
Browse files Browse the repository at this point in the history
  • Loading branch information
Endle committed Aug 24, 2024
1 parent af26c0e commit b31e5fe
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
1 change: 1 addition & 0 deletions fire_seq_search_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ pdf-extract-temporary-mitigation-panic = "0.7.1"
sha256 = "1.5.0"
reqwest = { version = "0.12", features = ["json"] }
futures = "0.3"
serde_derive = "1.0.209"
70 changes: 51 additions & 19 deletions fire_seq_search_server/src/local_llm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@ use std::collections::HashMap;
use std::collections::VecDeque;


// Generated by https://transform.tools/json-to-rust-serde
use serde_derive::Deserialize;
use serde_derive::Serialize;
use serde;

#[derive(Debug, Serialize, Deserialize)]
pub struct OpenAiData {
pub model: String,
pub messages: Vec<Message>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LlamaResponse {
pub choices: Vec<Choice>,
pub created: i64,
pub id: String,
pub model: String,
pub object: String,
pub usage: Usage,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Choice {
pub finish_reason: String,
pub index: i64,
pub message: Message,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Message {
pub content: String,
pub role: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Usage {
pub completion_tokens: i64,
pub prompt_tokens: i64,
pub total_tokens: i64,
}

// End genereated

const LLM_SERVER_PORT: &str = "8081"; // TODO Remove this magic number
use std::sync::Arc;
Expand Down Expand Up @@ -39,19 +81,8 @@ pub struct LlmEngine {
//job_cache :Arc<Mutex<HashMap<String, Option<String> >>>,
}

use serde::{Serialize, Deserialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct OpenAiData {
pub model: String,
pub messages: Vec<Message>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Message {
pub role: String,
pub content: String,
}

use tokio::task::yield_now;
use tokio::task;
Expand Down Expand Up @@ -132,7 +163,6 @@ impl LlmEngine {
}
}

use axum::debug_handler;
impl LlmEngine{
pub async fn summarize(&self, full_text: &str) -> String {
info!("summarize called");
Expand All @@ -145,10 +175,16 @@ impl LlmEngine{
.send()
.await
.unwrap();
info!(" response {:?}", &res);
//info!(" response {:?}", &res);
let content = res.text().await.unwrap();
info!(" text {:?}", &content);
content
//info!(" text {:?}", &content);
let parsed: LlamaResponse = serde_json::from_str(&content).unwrap();
//info!(" parsed {:?}", &parsed);
let v = parsed.choices;
let v0 = v.into_iter().next().unwrap();
v0.message.content


//TODO remove unwrap
}

Expand All @@ -157,10 +193,6 @@ impl LlmEngine{
let mut jcache = self.job_cache.lock().await;//.unwrap();
jcache.add(doc);
drop(jcache);

//TODO why can't I call self.poll in this function?
//yield_now().await;
//self.poll().await;
}

pub async fn call_llm_engine(&self) {
Expand Down

0 comments on commit b31e5fe

Please sign in to comment.