Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: 64bit/async-openai
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: TabbyML/async-openai
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 1 file changed
  • 3 contributors

Commits on Jan 6, 2025

  1. Copy the full SHA
    8e2414a View commit details

Commits on Jan 7, 2025

  1. Copy the full SHA
    15fcb50 View commit details
  2. Merge pull request #1 from TabbyML/fix/empty-string-stop-reason

    fix(completion): accept empty string as None stop reason
    wsxiaoys authored Jan 7, 2025
    Copy the full SHA
    0368621 View commit details
Showing with 19 additions and 1 deletion.
  1. +19 −1 async-openai/src/types/chat.rs
20 changes: 19 additions & 1 deletion async-openai/src/types/chat.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use std::{collections::HashMap, pin::Pin};

use derive_builder::Builder;
use futures::Stream;
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Deserializer, Serialize};

use crate::error::OpenAIError;

@@ -764,11 +764,29 @@ pub struct ChatChoiceStream {
/// The index of the choice in the list of choices.
pub index: u32,
pub delta: ChatCompletionStreamResponseDelta,
#[serde(deserialize_with = "deserialize_finish_reason")]
pub finish_reason: Option<FinishReason>,
/// Log probability information for the choice.
pub logprobs: Option<ChatChoiceLogprobs>,
}

fn deserialize_finish_reason<'de, D>(deserializer: D) -> Result<Option<FinishReason>, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
match s.as_str() {
"stop" => Ok(Some(FinishReason::Stop)),
"length" => Ok(Some(FinishReason::Length)),
"tool_calls" => Ok(Some(FinishReason::ToolCalls)),
"content_filter" => Ok(Some(FinishReason::ContentFilter)),
"function_call" => Ok(Some(FinishReason::FunctionCall)),

// treat any other value as None
_ => Ok(None),
}
}

#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
/// Represents a streamed chunk of a chat completion response returned by model, based on the provided input.
pub struct CreateChatCompletionStreamResponse {