Skip to content

Commit

Permalink
Lint and tweak wording
Browse files Browse the repository at this point in the history
  • Loading branch information
theoforger committed Sep 20, 2024
1 parent 0ee9238 commit 0001861
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/api/chat_completions.rs
Original file line number Diff line number Diff line change
@@ -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].
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/api/json_models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod language_model;
pub mod chat_completion;
pub mod language_model;
8 changes: 3 additions & 5 deletions src/clue.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<Self> {
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;
Expand All @@ -46,7 +44,7 @@ impl Clue {
}

impl ClueCollection {
/// Create an instance of `ClueCollection` from `Vec<String>`, which contains lines of clue response from the API
/// Create a new instance of `ClueCollection` from `Vec<String>`, which contains lines of clues from the API
pub fn new(clue_strings: Vec<String>, usage: Usage) -> Self {
let mut clues: Vec<Clue> = clue_strings.iter().filter_map(|s| Clue::new(s)).collect();

Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ pub fn write_content_to_file(
) -> Result<(), Box<dyn std::error::Error>> {
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());
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.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?");
Expand Down

0 comments on commit 0001861

Please sign in to comment.