Updates client to use the generateContent endpoint when not streaming

This commit is contained in:
2024-02-23 14:42:51 +00:00
parent 83335e65dc
commit 93285e53dd
4 changed files with 54 additions and 59 deletions

View File

@@ -21,13 +21,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let prompt = "Tell me the story of the genesis of the universe as a bedtime story.";
let request = GenerateContentRequest::from_prompt(prompt, None);
let queue = gemini
.streaming_stream_generate_content(&request, Model::GeminiPro)
.stream_generate_content(&request, Model::GeminiPro)
.await;
while let Some(chunk) = queue.pop().await {
if let ResponseStreamChunk::Ok(ok_response) = chunk {
let text = ok_response
.candidates
while let Some(response) = queue.pop().await {
if let GenerateContentResponse::Ok {
candidates,
usage_metadata: _,
} = response
{
let text = candidates
.iter()
.filter_map(|c| c.get_text())
.collect::<String>();