我在使用 Gemini API,需要一些帮助。当我运行从文档中获取的代码时,返回了:
<google.generativeai.types.generation_types.GenerateContentResponse>
。这是我的代码
import pathlibimport textwrapimport google.generativeai as genaifrom IPython.display import displayfrom IPython.display import Markdowndef to_markdown(text): text = text.replace('•', ' *') return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))genai.configure(api_key='AN API KEY WAS HERE')model = genai.GenerativeModel('gemini-pro')response = model.generate_content("What is the meaning of life?")print(response)
我运行了这个代码,得到了上面的响应。
回答:
你得到的是一个 Google 对象的响应。你需要使用 response.text 来获取实际的文本内容。
像这样:
print(response.text)