Skip to content

Commit

Permalink
Merge pull request #47 from erhant/erhant/fix-serde-flatten
Browse files Browse the repository at this point in the history
Flatten final response data
  • Loading branch information
pepperoni21 authored May 9, 2024
2 parents 0dc8b91 + 8c22fa7 commit 5ecb6e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/basic_chatbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
stdout.write_all(ele.response.as_bytes()).await?;
stdout.flush().await?;

if let Some(final_data) = ele.final_data {
context = Some(final_data.context);
if ele.context.is_some() {
context = ele.context;
}
}
}
Expand Down
23 changes: 8 additions & 15 deletions src/generation/completion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,16 @@ pub struct GenerationResponse {
pub response: String,
/// Whether the completion is done. If the completion is streaming, this will be false until the last response.
pub done: bool,
#[serde(flatten)]
/// The final data of the completion. This is only present if the completion is done.
pub final_data: Option<GenerationFinalResponseData>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerationFinalResponseData {
/// An encoding of the conversation used in this response, this can be sent in the next request to keep a conversational memory
pub context: GenerationContext,
pub context: Option<GenerationContext>,
/// Time spent generating the response
pub total_duration: u64,
pub total_duration: Option<u64>,
/// Number of tokens in the prompt
pub prompt_eval_count: u16,
pub prompt_eval_count: Option<u16>,
/// Time spent in nanoseconds evaluating the prompt
pub prompt_eval_duration: u64,
/// Number of tokens the response
pub eval_count: u16,
/// Time in nanoseconds spent generating the response
pub eval_duration: u64,
pub prompt_eval_duration: Option<u64>,
/// Number of tokens in the response
pub eval_count: Option<u16>,
/// Time spent in nanoseconds generating the response
pub eval_duration: Option<u64>,
}

0 comments on commit 5ecb6e1

Please sign in to comment.