Skip to content

Unexpected finish reason values returned for Gemini via VertexAI #95

@sam-veezoo

Description

@sam-veezoo

When using Gemini via Vertex AI, the OpenAiChatCompletionService returns unexpected finish reason values of the form "1: ", "2: ", etc., but I would expect to get the Gemini reason names "STOP", "MAX_TOKENS", etc. as listed here.

Code example:

val service: OpenAIChatCompletionService = VertexAIServiceFactory.asOpenAI(
    projectId = ...,
    location = ...
)
val settings = CreateChatCompletionSettings(model = "gemini-1.5-flash-001")
val response = Await.result(
    service.createChatCompletion(Seq(domain.UserMessage("Just reply with 'ABC'")), settings),
    Duration.Inf
)

// finishReason is '1: ' here
val finishReason = response.choices.head.finish_reason.get

Similarly, the streaming library returns a finish_reason with value Some(0: ) on all but the last ChatCompletionChoiceChunkInfo object, however I think this should be None.

Looking at the code, I see that this line uses getFinishMessage to construct the reason name, however this message is an empty string for Gemini.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions