avastmick / google-generative-ai-rs

An unofficial rust-based client library to interact with the Google Gemini generative AI API
https://docs.rs/google-generative-ai-rs/
MIT License
21 stars 7 forks source link

stream output miss first text #36

Closed xmlandroid closed 3 months ago

xmlandroid commented 3 months ago

use the code: GeminiClient::for_each_async(json_stream, move |response: GeminiResponse| async move { println!( "{}", response.candidates[0].content.parts[0] .text .clone() .unwrap() .as_str() ); }) output miss first text:

P60`7 }F73I$N)NO__3{KU8

this is the aistudio output:

K1E32A_ 0}4MZ_N_{`Y8SWW

try a lot of example ,the problem continue

avastmick commented 3 months ago

Thanks, I'll investigate when I get time over the weekend.

avastmick commented 3 months ago

Hi, @xmlandroid, I cannot replicate this in any way. I always see all of the response from the API.

So I can help you further, can you give more techical details on your usage? Please include:

xmlandroid commented 3 months ago

I find the problem is when I use serde_json::from_value convert the Value to GeminiResponse the first chunk will return Err not Ok

xmlandroid commented 3 months ago

other chunk is ok,just the first Gemini return struct is different ,convert the value to GeminiResponse get Err

xmlandroid commented 3 months ago

1717162098155

xmlandroid commented 3 months ago

1717162214055

xmlandroid commented 3 months ago

By the way, do you have any examples of conversations with pictures?