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

bug: [0.5.8] OpenAI .Net library chokes on "finish_reason": null in response from Jan server #3946

Closed
1 of 3 tasks
debruyckere opened this issue Nov 4, 2024 · 8 comments
Closed
1 of 3 tasks
Assignees
Labels
category: local API server Server page UI UX needs info Not enough info, more logs/data required type: bug Something isn't working

Comments

@debruyckere
Copy link

debruyckere commented Nov 4, 2024

Jan version

v0.5.6

Describe the Bug

The response from the Jan server looks like so (from the built-in example):

{
  "choices": [
    {
      "finish_reason": null,
      "index": 0,
      "message": {
        "content": "Hello user. What can I help you with?",
        "role": "assistant"
      }
    }
  ],
  "created": 1700193928,
  "id": "ebwd2niJvJB1Q2Whyvkz",
  "model": "_",
  "object": "chat.completion",
  "system_fingerprint": "_",
  "usage": {
    "completion_tokens": 500,
    "prompt_tokens": 33,
    "total_tokens": 533
  }
}

It is parsed by the OpenAI library (https://www.nuget.org/packages/OpenAI, v2.1.0-beta). The response contains 'null' for 'finish_reason' and the library attemps to parse that in ChatFinishReasonExtensions.ToChatFinishReason, using this code:

public static ChatFinishReason ToChatFinishReason(this string value)
{
    if (StringComparer.OrdinalIgnoreCase.Equals(value, "stop")) return ChatFinishReason.Stop;
    if (StringComparer.OrdinalIgnoreCase.Equals(value, "length")) return ChatFinishReason.Length;
    if (StringComparer.OrdinalIgnoreCase.Equals(value, "tool_calls")) return ChatFinishReason.ToolCalls;
    if (StringComparer.OrdinalIgnoreCase.Equals(value, "content_filter")) return ChatFinishReason.ContentFilter;
    if (StringComparer.OrdinalIgnoreCase.Equals(value, "function_call")) return ChatFinishReason.FunctionCall;
    throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ChatFinishReason value.");
}

Consequently, an ArgumentOutOfRangeException is thrown because the value is null. The expected value is 'stop'.

Steps to Reproduce

  1. Start local server with 'llama3.2-3b-instruct' model
  2. Run this code in .Net, using the official OpenAI library:

var uri = new Uri("http://127.0.0.1:1337/v1");
var credential = new ApiKeyCredential("123");
var client = new ChatClient("llama3.2-3b-instruct", credential, new OpenAIClientOptions {Endpoint = uri});

var messages = new ChatMessage[] { ChatMessage.CreateUserMessage("Say something") };
var response = client.CompleteChat(messages);

Screenshots / Logs

System.ArgumentOutOfRangeException: Unknown ChatFinishReason value.
Parameter name: value
    at OpenAI.Chat.ChatFinishReasonExtensions.ToChatFinishReason(String value)
   at OpenAI.Chat.InternalCreateChatCompletionResponseChoice.DeserializeInternalCreateChatCompletionResponseChoice(JsonElement element, ModelReaderWriterOptions options)
   at OpenAI.Chat.ChatCompletion.DeserializeChatCompletion(JsonElement element, ModelReaderWriterOptions options)
   at OpenAI.Chat.ChatCompletion.FromResponse(PipelineResponse response)
   at OpenAI.Chat.ChatClient.CompleteChat(IEnumerable`1 messages, ChatCompletionOptions options, CancellationToken cancellationToken)
   at OpenAI.Chat.ChatClient.CompleteChat(ChatMessage[] messages)

What is your OS?

  • MacOS
  • Windows
  • Linux
@debruyckere debruyckere added the type: bug Something isn't working label Nov 4, 2024
@imtuyethan imtuyethan added the category: local API server Server page UI UX label Nov 5, 2024
@imtuyethan imtuyethan added this to Menlo Nov 5, 2024
@imtuyethan imtuyethan moved this to Investigating in Menlo Nov 5, 2024
@louis-jan
Copy link
Contributor

Hi @debruyckere, please update to version 0.5.8 and see if the issue persists.
Screenshot 2024-11-17 at 11 54 48
Screenshot 2024-11-17 at 11 55 08

@louis-jan louis-jan self-assigned this Nov 17, 2024
@debruyckere
Copy link
Author

Same behavior in 0.5.8.

@imtuyethan imtuyethan added this to the v0.5.11 milestone Nov 27, 2024
@louis-jan
Copy link
Contributor

@debruyckere Could you kindly share the stream response on your end?

@imtuyethan imtuyethan added the needs info Not enough info, more logs/data required label Nov 28, 2024
@imtuyethan imtuyethan changed the title OpenAI .Net library chokes on "finish_reason": null in response from Jan server bug: [0.5.8] OpenAI .Net library chokes on "finish_reason": null in response from Jan server Nov 28, 2024
@debruyckere
Copy link
Author

The JSON returned by the server is in the description. Or are you referring to something else?

@louis-jan
Copy link
Contributor

The JSON returned by the server is in the description. Or are you referring to something else?

Yes, @debruyckere, please ensure that the JSON response from the server indicates a successful request.

CleanShot 2024-11-29 at 09 50 47@2x

@imtuyethan imtuyethan removed this from the v0.5.11 milestone Nov 29, 2024
@louis-jan
Copy link
Contributor

Hi @debruyckere, it would be great to have the response json so that we can take a look at.

@debruyckere
Copy link
Author

Using v0.5.11 I can no longer reproduce the issue, thanks for fixing!

The API Playground documentation still mentions 'null' for 'finish_reason', but that is no big deal of course:
afbeelding

@louis-jan
Copy link
Contributor

Thanks @debruyckere, we are going to replace that swagger page with a better one. #3895

@louis-jan louis-jan closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2024
@github-project-automation github-project-automation bot moved this from Investigating to QA in Menlo Dec 10, 2024
@imtuyethan imtuyethan moved this from QA to Completed in Menlo Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: local API server Server page UI UX needs info Not enough info, more logs/data required type: bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants