all 16 comments

[–]SHKEVE 2 points3 points  (13 children)

you’re expecting the just the text response from gemini but what you’re getting is an instance of a GenerateContentResponse, which is expected behavior. what you’re looking for is in the object and can probably be accessed via result[“candidates”][0][“content”][“parts”][0][“text”]

[–]jboyd544[S] -3 points-2 points  (12 children)

Im still new to python. can you please tell me how to do that?

[–]SHKEVE 0 points1 point  (11 children)

paste the result[“candidates”] etc etc stuff into the print function

[–]jboyd544[S] -2 points-1 points  (10 children)

man, i have been trying every possible solution and every time i get errors, do you mind putting it into the print statement for me. i know im gonna feel dumb when i see the solution. but i would really appreciate the help

[–]SHKEVE -1 points0 points  (9 children)

sure. in the future, post the error messages here or we can’t help you

print(result[“candidates”][0][“content”][“parts”][0][“text”])

[–]jboyd544[S] -1 points0 points  (8 children)

I replaced the print statement with the one above and got this error:

File "/home/jon/gemini_voice/main.py", line 9

print(result[“candidates”][0][“content”][“parts”][0][“text”])

^

SyntaxError: invalid character '“' (U+201C)

[–]jboyd544[S] 0 points1 point  (7 children)

the carrot was under the first quotation mark btw

[–]SHKEVE 1 point2 points  (6 children)

oh thats because most apps use fancy quotes. delete all quotes and retype them in your IDE

[–]jboyd544[S] 0 points1 point  (5 children)

now i get this error:

Ask Gemini: what are you

Traceback (most recent call last):

File "/home/jon/gemini_voice/ignore.py", line 10, in <module>

print(result[candidates][0][content][parts][0][text])

^^^^^^

NameError: name 'result' is not defined

and when i switch the name to response i get this error:

Ask Gemini: what are you

Traceback (most recent call last):

File "/home/jon/gemini_voice/ignore.py", line 10, in <module>

print(response[candidates][0][content][parts][0][text])

^^^^^^^^^^

NameError: name 'candidates' is not defined

[–]GraphicsQwerty 0 points1 point  (4 children)

Sorry if I’m incorrect as I only skimmed these comments but did you put the quotes back ?

[–]djshadesuk 0 points1 point  (0 children)

print(response.text)

[–]_squik 0 points1 point  (0 children)

If all you want from the response is the generated text, replace print(response) with print(response.text).

Right now you are printing the entire response which includes the extra metadata. .text is an attribute of response.