Google AI LLM Gemini

获取API KEY

通过下面地址生成调用API所需的KEY。

https://ai.google.dev/

代码实现

import google.generativeai as genai

genai.configure(api_key="GOOGLE_API_KEY")

def chat_gemini(input):
    model = genai.GenerativeModel('gemini-pro')
    chat = model.start_chat(history=[])
    response = chat.send_message(input, stream=True)

    try:
        for chunk in response:
            print(chunk.text)
    except Exception as e:
        print(e)

使用

chat_gemini('What is the meaning of life?')

源码地址 https://github.com/capricorncd/chat-google-gemini


capricorncd
38 声望5 粉丝