dongri / openai-api-rs

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

Assistant API: Assistant with File Search throws parsing error #125

Closed niklasHack2810 closed 1 week ago

niklasHack2810 commented 1 week ago

Describe the bug

Creating a run with an assistant with file search throws an error:

Error: OpenAI: APIError: Failed to parse JSON: invalid type: map, expected a string at line 20 column 21 / response

This happens in the tools property. The actual content of the property is the following:

  "tools": [
    {
      "type": "file_search",
      "file_search": {
        "ranking_options": {
          "ranker": "default_2024_08_21",
          "score_threshold": 0.0
        }
      }
    }
  ],

In the library, it is defined as

pub tools: Vec<HashMap<String, String>>,

To Reproduce

  1. Create an assistant with a file search
  2. Execute create_run()

Code snippets

No response

OS

Linux

Rust version

1.82.0

Library version

5.2.1

dongri commented 1 week ago

@niklasHack2810 Could you paste the snippet of code you executed? Like https://github.com/dongri/openai-api-rs/blob/main/examples/assistant.rs#L12-L24

niklasHack2810 commented 1 week ago

@dongri This line fails:

let run = self.client.create_run(thread_id.clone(), CreateRunRequest::new(ASSISTANT_ID.to_string())).await?;

self.client is your OpenAIClient, thread_id is from a previous request to client.create_thread. The ASSISTANT_ID is just a constant &str.

dongri commented 1 week ago

Fixed Please use v5.2.2

niklasHack2810 commented 1 week ago

Thank you, it works now :)