dongri / openai-api-rs

OpenAI API client library for Rust (unofficial)
https://docs.rs/openai-api-rs
MIT License
312 stars 59 forks source link

Update API for GPT4 Vision Preview #45

Closed zh4ngx closed 11 months ago

zh4ngx commented 11 months ago

Describe the bug

When using the GPT 4 Vision Preview API, the finish_reason field is missing. It needs to be optional, and a new finish_details field needs to be added (and also optional).

To Reproduce

Follow the example in the Quickstart: https://platform.openai.com/docs/guides/vision/quick-start

  1. Start a completion using the GPT4_VISION_PREVIEW model
  2. Use the text and image_url in the example
  3. Note the error about the missing field

Code snippets

let req = ChatCompletionRequest {
        model: GPT4_VISION_PREVIEW.to_string(),
        messages: vec![
            chat_completion::ChatCompletionMessage {
            role: MessageRole::user,
            content: String::from(
                r#"[
          {
            "type": "text",
            "text": "What's in this image?"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
        }
        }
]"#,
            ),
            name: None,
            function_call: None,
        }],
        functions: None,
        function_call: None,
        temperature: None,
        top_p: None,
        n: None,
        response_format: None,
        stream: None,
        stop: None,
        max_tokens: Some(300),
        presence_penalty: None,
        frequency_penalty: None,
        logit_bias: None,
        user: None,
    };

OS

Linux

Rust version

Rust v1.73.0

Library version

openai-api-rs v2.1.1

zh4ngx commented 11 months ago

I have a PR: #46

dongri commented 11 months ago

@zh4ngx Thanks! https://platform.openai.com/docs/api-reference/chat/object Screenshot 2023-11-22 at 11 57 57 It seems the document and the API response do not match.

dongri commented 11 months ago

https://github.com/dongri/openai-api-rs/pull/46 Merged