Revert back to text summarizing model

It sucks at summarizing but llama was blowing through tokens way too
fast and didn't really work.
This commit is contained in:
2025-03-06 21:48:46 -05:00
parent a67b289f38
commit 7e30886d8a
2 changed files with 21 additions and 45 deletions

View File

@@ -94,11 +94,11 @@ async fn fetch_content(
Ok(content.content) Ok(content.content)
} }
// #[derive(Serialize)] #[derive(Serialize)]
// struct SummarizeRequest { struct SummarizeRequest {
// input_text: String, input_text: String,
// max_length: u64, max_length: u64,
// } }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct Message { struct Message {
@@ -106,38 +106,27 @@ struct Message {
content: String, content: String,
} }
// #[derive(Deserialize)] #[derive(Deserialize)]
// struct SummarizeResult { struct SummarizeResult {
// summary: String, summary: String,
// }
//
// #[derive(Deserialize)]
// struct SummarizeResponse {
// result: SummarizeResult,
// }
#[derive(Serialize)]
struct AIChatRequest {
messages: Vec<Message>,
max_tokens: u64,
} }
#[derive(Serialize, Deserialize)] #[derive(Deserialize)]
struct AIChatResponse { struct SummarizeResponse {
response: String, result: SummarizeResult,
} }
async fn request_ai_summarization( async fn request_ai_summarization(
base_url: &str, base_url: &str,
api_key: &str, api_key: &str,
model: &str, model: &str,
messages: Vec<Message>, input: String,
) -> std::result::Result<String, Box<dyn std::error::Error>> { ) -> std::result::Result<String, Box<dyn std::error::Error>> {
console_log!("request_ai_summarization"); console_log!("request_ai_summarization");
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let request_body = AIChatRequest { let request_body = SummarizeRequest {
messages, input_text: input,
max_tokens: 1024, max_length: 2048,
}; };
let response = client let response = client
@@ -150,12 +139,8 @@ async fn request_ai_summarization(
if response.status().is_success() { if response.status().is_success() {
console_log!("request_ai_summarization success"); console_log!("request_ai_summarization success");
let summarize_response: AIChatResponse = response.json().await?; let summarize_response: SummarizeResponse = response.json().await?;
console_log!( Ok(summarize_response.result.summary)
"request_ai_summarization response: {}",
summarize_response.response
);
Ok(summarize_response.response)
} else { } else {
let error_message = response.text().await?; let error_message = response.text().await?;
console_log!("request_ai_summarization error: {}", error_message); console_log!("request_ai_summarization error: {}", error_message);
@@ -217,23 +202,14 @@ async fn generate_and_update_entry(
return Ok(()); return Ok(());
} }
} }
let input = format!("{}\n\n{}", &entry.title, content);
let messages = vec![ // Generate summary
Message {
role: "system".to_string(),
content: "You are an experienced and knowledgeable internet blogger that writes short and easy-to-read summaries for articles from various RSS feeds. Please summarize the content of the article in 1000 words or less. Format your output in CommonMark compliant markdown. Do not give any extra comments, headers, or prefix. Only return the actual summary text. Similar to the blurbs on the back of books, highlight any aspects of the articles that may be of interest and grab the attention to any readers perusing.".to_string(),
},
Message {
role: "user".to_string(),
content: format!("{}\n\n{}", &entry.title, &entry.content),
},
];
if let Ok(summary) = request_ai_summarization( if let Ok(summary) = request_ai_summarization(
&config.cloudflare_ai.url, &config.cloudflare_ai.url,
&config.cloudflare_ai.token, &config.cloudflare_ai.token,
&config.cloudflare_ai.model, &config.cloudflare_ai.model,
messages, input,
) )
.await .await
{ {

View File

@@ -17,4 +17,4 @@ enabled = true
head_sampling_rate = 1 # optional. default = 1. head_sampling_rate = 1 # optional. default = 1.
[vars] [vars]
CF_AI_MODEL = "@hf/meta-llama/meta-llama-3-8b-instruct" CF_AI_MODEL = "@cf/facebook/bart-large-cnn"