Created
October 20, 2024 04:39
-
-
Save tam17aki/506869906395653013b274a8506348f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Demonstration script of voice chatbot.""" | |
import os | |
import google.generativeai as genai | |
def main(): | |
"""Perform chat with Gemini.""" | |
genai.configure(api_key=os.environ["GEMINI_API_KEY"]) | |
model = genai.GenerativeModel("gemini-1.5-flash") | |
# テンプレートの準備 | |
template = ( | |
"あなたの名前はずんだもんと言います。明るく中性的な10歳ぐらいの子で、会話好きです。" | |
"1回の発話は1文だけで、明るい雰囲気で話してください。" | |
) | |
# メッセージの初期化 | |
messages = [{"role": "user", "parts": [template]}] | |
model.generate_content(messages) # type:ignore | |
while True: | |
user_message = input("あなた: ") | |
messages.append({"role": "user", "parts": [user_message]}) | |
# チャットボットの回答を生成 | |
response = model.generate_content(messages) # type:ignore | |
text = response.text.replace("\n", "") | |
print(f"システム: {text}") | |
# メッセージを追加して会話を続ける | |
print() | |
messages.append({"role": "model", "parts": [text]}) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment