From 000186185684946732060f37896bcafb183b0e8f Mon Sep 17 00:00:00 2001 From: theoforger Date: Thu, 19 Sep 2024 21:15:06 -0400 Subject: [PATCH] Lint and tweak wording --- src/api/chat_completions.rs | 9 +++------ src/api/json_models/mod.rs | 2 +- src/clue.rs | 8 +++----- src/lib.rs | 6 +----- src/main.rs | 1 - 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/api/chat_completions.rs b/src/api/chat_completions.rs index faa7e43..cc1f9dc 100644 --- a/src/api/chat_completions.rs +++ b/src/api/chat_completions.rs @@ -1,10 +1,8 @@ -use super::json_models::chat_completion::{ChatCompletionResponse}; +use super::json_models::chat_completion::ChatCompletionResponse; use super::Instance; use crate::clue::ClueCollection; use serde_json::json; - - const SYSTEM_PROMPT: &str = r#" You are the spymaster in Codenames. I will give you a list of [agent word], followed by a list of [avoid word]. @@ -48,12 +46,11 @@ impl Instance { // Extract usage information from the parsed response let token_usage = parsed_response.usage; - // Extract clue strings from the parsed response let clue_strings = parsed_response .choices - .get(0) - .ok_or("No choices returned from API")? + .first() + .ok_or("Failed to parse clues from API server")? .message .content .lines() diff --git a/src/api/json_models/mod.rs b/src/api/json_models/mod.rs index c19183e..7381405 100644 --- a/src/api/json_models/mod.rs +++ b/src/api/json_models/mod.rs @@ -1,2 +1,2 @@ -pub mod language_model; pub mod chat_completion; +pub mod language_model; diff --git a/src/clue.rs b/src/clue.rs index 4736355..b8e361c 100644 --- a/src/clue.rs +++ b/src/clue.rs @@ -1,7 +1,7 @@ +use crate::api::json_models::chat_completion::Usage; use comfy_table::modifiers::UTF8_ROUND_CORNERS; use comfy_table::presets::UTF8_FULL; use comfy_table::{Attribute, Cell, CellAlignment, ContentArrangement, Table}; -use crate::api::json_models::chat_completion::Usage; struct Clue { clue_word: String, count: usize, @@ -14,12 +14,10 @@ pub struct ClueCollection { } impl Clue { - /// Create a new instance of `Clue` from a single line of clue responses from the API + /// Create a new instance of `Clue` from a single line of clue out of the API response pub fn new(clue_line: &str) -> Option { let chunks: Vec<&str> = clue_line.split(", ").collect(); - - // Discard empty lines as well as clues with only one word linked if chunks.len() < 4 { return None; @@ -46,7 +44,7 @@ impl Clue { } impl ClueCollection { - /// Create an instance of `ClueCollection` from `Vec`, which contains lines of clue response from the API + /// Create a new instance of `ClueCollection` from `Vec`, which contains lines of clues from the API pub fn new(clue_strings: Vec, usage: Usage) -> Self { let mut clues: Vec = clue_strings.iter().filter_map(|s| Clue::new(s)).collect(); diff --git a/src/lib.rs b/src/lib.rs index 14e64f0..2e66e45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,11 +57,7 @@ pub fn write_content_to_file( ) -> Result<(), Box> { if let Ok(existing_content) = fs::read_to_string(&path) { if !existing_content.is_empty() { - return Err(format!( - "File is not empty: {}", - path.to_string_lossy() - ) - .into()); + return Err(format!("File is not empty: {}", path.to_string_lossy()).into()); } } diff --git a/src/main.rs b/src/main.rs index 983c8f3..d50ad8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,6 @@ async fn main() -> Result<(), Box> { .fetch_clue_collection(link_words, avoid_words) .await?; - // Output if clue_collection.is_empty() { println!("The language model didn't return any useful clues. Maybe try again?");