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

invalid type: map, expected a string #116

Open
Wandalen opened this issue Oct 12, 2024 · 9 comments
Open

invalid type: map, expected a string #116

Wandalen opened this issue Oct 12, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@Wandalen
Copy link

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

@Wandalen Wandalen added the bug Something isn't working label Oct 12, 2024
@dongri
Copy link
Owner

dongri commented Oct 13, 2024

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
Copy link
Author

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
Copy link
Owner

dongri commented Oct 13, 2024

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

Please try use v5.0.12

@Wandalen
Copy link
Author

Wandalen commented Oct 13, 2024

Thank you for the quick response, Jin.

Unfortunately, the change prints the entire response, so it's unclear exactly which line serde failed to parse. I’ve removed sensitive information and published the first 30 lines and the slice near 90 line, though I’m not sure if the data I’ve provided is detailed enough to be helpful.

Error: CustomError { message: "Failed to parse JSON: invalid type: map, expected a string at line 90 column 25 / response {
  \"object\": \"list\",
  \"data\": [
    {
      \"id\": \"...\",
      \"object\": \"assistant\",
      \"created_at\": 1728325306,
      \"name\": \"Image Describe\",
      \"description\": null,
      \"model\": \"gpt-4o-2024-08-06\",
      \"instructions\": \"# Image Describe\

...

Write your detailed image description here:\
\
<image_description>\
{{IMAGE_DESCRIPTION}}\
</image_description>\
\

...

By the way, the list of files works perfectly fine.

@dongri
Copy link
Owner

dongri commented Oct 13, 2024

Ok, send me the response dump at [email protected] and I'll look into it. (Please edit confidential information)

@Wandalen
Copy link
Author

I've just sent it. I hope that helps.

Programmatically selecting lines would address other similar issues.

@dongri
Copy link
Owner

dongri commented Oct 15, 2024

@Wandalen
Thank you sent me log
I fixed the response in the tools section a bit, mainly around functions.
Could you please try again with v5.0.13?

@Wandalen
Copy link
Author

Hi, I haven't had the chance to try it yet. Could you let me know what the issue was? Also, could you share the link to the commit with the fix?

@dongri
Copy link
Owner

dongri commented Oct 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants