Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -31,8 +31,7 @@ from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
| 31 |
# ==========================
|
| 32 |
|
| 33 |
# 設置 Google AI API 金鑰
|
| 34 |
-
os.environ["GOOGLE_API_KEY"]
|
| 35 |
-
|
| 36 |
# 設置 Line Bot 的 API 金鑰和秘密金鑰
|
| 37 |
line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
|
| 38 |
line_handler = WebhookHandler(os.environ["CHANNEL_SECRET"])
|
|
@@ -102,7 +101,7 @@ def generate_and_upload_image(prompt: str) -> str:
|
|
| 102 |
生成圖片的 URL。
|
| 103 |
"""
|
| 104 |
try:
|
| 105 |
-
genai_client = genai.Client(api_key=
|
| 106 |
response = genai_client.models.generate_content(
|
| 107 |
model="gemini-2.0-flash-exp",
|
| 108 |
contents=prompt,
|
|
@@ -174,7 +173,7 @@ def analyze_image_with_text(image_path: str, user_text: str) -> str:
|
|
| 174 |
tools = [generate_and_upload_image, analyze_image_with_text]
|
| 175 |
|
| 176 |
# 建立 LLM 模型實例
|
| 177 |
-
llm = ChatGoogleGenerativeAI(model="gemini-
|
| 178 |
|
| 179 |
# 建立提示模板
|
| 180 |
prompt_template = ChatPromptTemplate.from_messages([
|
|
|
|
| 31 |
# ==========================
|
| 32 |
|
| 33 |
# 設置 Google AI API 金鑰
|
| 34 |
+
google_api = os.environ["GOOGLE_API_KEY"]
|
|
|
|
| 35 |
# 設置 Line Bot 的 API 金鑰和秘密金鑰
|
| 36 |
line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
|
| 37 |
line_handler = WebhookHandler(os.environ["CHANNEL_SECRET"])
|
|
|
|
| 101 |
生成圖片的 URL。
|
| 102 |
"""
|
| 103 |
try:
|
| 104 |
+
genai_client = genai.Client(api_key=google_api)
|
| 105 |
response = genai_client.models.generate_content(
|
| 106 |
model="gemini-2.0-flash-exp",
|
| 107 |
contents=prompt,
|
|
|
|
| 173 |
tools = [generate_and_upload_image, analyze_image_with_text]
|
| 174 |
|
| 175 |
# 建立 LLM 模型實例
|
| 176 |
+
llm = ChatGoogleGenerativeAI(google_api_key=google_api, model="gemini-2.0-flash", temperature=0.2)
|
| 177 |
|
| 178 |
# 建立提示模板
|
| 179 |
prompt_template = ChatPromptTemplate.from_messages([
|