Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prefer stop over eos_token to align with openai finish_reason #2344

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

drbh
Copy link
Collaborator

@drbh drbh commented Jul 31, 2024

This PR aligns the finish_reason value with openai. Currently TGI returns the string eos_token rather than stop as a finish_reason.

Fixes: #2296

The discrepancy between the values is easier to noticed when a strongly typed client is used. Currently the incorrect finish_value will cause the following request to fail since it expects stop rather than eos_token, these changes resolve this example.

use async_openai::config::OpenAIConfig;
use async_openai::types::CreateCompletionRequestArgs;
use async_openai::Client;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client = Client::with_config(OpenAIConfig::new().with_api_base("http://localhost:3000/v1"));

    let request = CreateCompletionRequestArgs::default()
        .model("meta-llama/Meta-Llama-3-8B-Instruct")
        .prompt("What is Hugging Face and what does it do?")
        .max_tokens(2000_u32) // <- increased
        .seed(1337)
        .build()?;

    let response = client.completions().create(request).await?;

    println!("\nResponse (single):\n");
    for choice in response.choices {
        println!("{}", choice.text);
    }

    Ok(())
}

Copy link
Member

@ErikKaum ErikKaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense to me 👍

@drbh drbh merged commit f8a5b38 into main Aug 6, 2024
9 checks passed
@drbh drbh deleted the improve-finish-reson-value branch August 6, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FinishReason enum not compatible with OAI api
2 participants