dongri / openai-api-rs

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

invalid type: map, expected a string #116

Open Wandalen opened 17 hours ago

Wandalen commented 17 hours ago

Describe the bug

List of assistants does not work. Looks like serde error? How can I see more verbose output?

Error: ReqwestError(reqwest::Error { kind: Decode, source: Error("invalid type: map, expected a string", line: 90, column: 25) })

To Reproduce

let response = client.list_assistant( None, None, None, None ).await?;

Code snippets

let response = client.list_assistant( None, None, None, None ).await?;

OS

windows

Rust version

1.83

Library version

5.0.11

dongri commented 14 hours ago

Are you using rust version 1.83?

https://github.com/rust-lang/rust/blob/master/RELEASES.md Latest version is 1.81

Rust version: 1.81 Library version: 5.011

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = OpenAIClient::new(env::var("OPENAI_API_KEY").unwrap().to_string());

    let response = client.list_assistant(None,None,None,None).await?;
    println!("List Assistants: {:?}", response);

    return Ok(());
}

The output was correct.

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.14s                                                                                                                                              
     Running `target/debug/examples/assistant`                                                                                                                                                                       
List Assistants: ListAssistant { object: "list", data: [AssistantObject { id: "asst_ryF3DSKvHzNzcJ1VYTWGmVtP", object: "assistant", created_at: 1721519486, name: None, description: Some("this is a test assistant")
, model: "gpt-4o", instructions: Some("You are a personal math tutor. When asked a question, write and run Python code to answer the question."), tools: [{"type": "code_interpreter"}], tool_resources: Some(ToolRes
ource { code_interpreter: Some(CodeInterpreter { file_ids: Some([]) }), file_search: None }), metadata: Some({}), headers: None }, AssistantObject { id: "asst_HO75Y4iznskvHWk6VBkesYag", object: "assistant", create
d_at: 1721519310, name: None, description: Some("this is a test assistant"), model: "gpt-4o", instructions: Some("You are a personal math tutor. When asked a question, write and run Python code to answer the quest
ion. please json format"), tools: [{"type": "code_interpreter"}], tool_resources: Some(ToolResource { code_interpreter: Some(CodeInterpreter { file_ids: Some([]) }), file_search: None }), metadata: Some({}), heade
rs: None }, AssistantObject { id: "asst_VSz98VLPbxeRWx8wr51hQGeD", object: "assistant", created_at: 1721519020, name: None, description: Some("this is a test assistant"), model: "gpt-4o", instructions: Some("You a
.......
Wandalen commented 2 hours ago

Hi Jin! How are you doing? Thanks for this open-source project.

I'm encountering an issue with the code, which results in the following error:

Error: ReqwestError(reqwest::Error { kind: Decode, source: Error("invalid type: map, expected a string", line: 90, column: 25) })

I'm using the nightly version, and the stable 1.81 version gives the same results.

My best guess is that the response from OpenAI contains something that serde can't parse, and the error report doesn't clearly indicate what is different in the response I'm receiving from OpenAI. I tried using curl, and the response looks fine, but it seems that openai-api-rs fails to parse it.

Another possibility is the size of the response. Perhaps I have too many assistants, and the way the response is handled doesn't account for something.

I suggest improving the quality of the error message by including a slice of the response that caused the error, so it's clear how to fix the bug. For example, miette does a great job formatting slices of text.

serde_json
dongri commented 1 hour ago

@Wandalen Fixed error response https://github.com/dongri/openai-api-rs/pull/117/files

Please try use v5.0.12