alanchen1115 commited on
Commit
f4e9cbd
·
verified ·
1 Parent(s): e977dbe

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +2 -28
main.py CHANGED
@@ -82,28 +82,6 @@ def get_previous_message(user_id):
82
  @tool
83
  def generate_and_upload_image(prompt: str) -> str:
84
  """根據文字提示生成圖片。"""
85
- # # Gemini image 模型需付費
86
- # try:
87
- # response = genai_client.models.generate_content(
88
- # model="gemini-2.5-flash-image",
89
- # contents=prompt,
90
- # config=types.GenerateContentConfig(response_modalities=['IMAGE'])
91
- # )
92
- # image_binary = None
93
- # for part in response.candidates[0].content.parts:
94
- # if part.inline_data:
95
- # image_binary = part.inline_data.data
96
- # break
97
- # if image_binary:
98
- # image = PIL.Image.open(io.BytesIO(image_binary))
99
- # file_name = f"static/{os.urandom(8).hex()}.png"
100
- # image.save(file_name, format="PNG")
101
- # base_url = os.getenv("HF_SPACE", "http://localhost:7860").rstrip("/")
102
- # return f"{base_url}/{file_name}"
103
- # else:
104
- # return "圖片生成失敗:模型未回傳數據。"
105
- # except Exception as e:
106
- # return f"圖片生成失敗: {e}"
107
 
108
  # Free api - pixazo.ai/getImage/v1/getSDXLImage
109
  try:
@@ -246,13 +224,9 @@ def handle_message(event):
246
  image_path = previous_message["content"]
247
  user_text = f"請分析這張圖片 {image_path},問題是:{user_text}"
248
  user_message_history[user_id].pop()
249
- else:
250
- agent_input = {"messages": [("user", user_text)]}
251
- # try:
252
- # response = agent_executor.invoke(agent_input)
253
- # out = response["output"]
254
 
255
- # 1. 修正輸入格式:LangGraph 預期接收 'messages',格式為 (角色, 內容) 的列表
 
256
  try:
257
  response = agent_executor.invoke(agent_input)
258
 
 
82
  @tool
83
  def generate_and_upload_image(prompt: str) -> str:
84
  """根據文字提示生成圖片。"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  # Free api - pixazo.ai/getImage/v1/getSDXLImage
87
  try:
 
224
  image_path = previous_message["content"]
225
  user_text = f"請分析這張圖片 {image_path},問題是:{user_text}"
226
  user_message_history[user_id].pop()
 
 
 
 
 
227
 
228
+ agent_input = {"messages": [("user", user_text)]}
229
+
230
  try:
231
  response = agent_executor.invoke(agent_input)
232