youngtsai commited on
Commit
6c63c7c
·
verified ·
1 Parent(s): f95c054

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -18,12 +18,12 @@ install_and_import("groq")
18
  from notion_client import Client
19
  from groq import Groq
20
 
21
- # 設定 Notion API 和資料庫 ID
22
- NOTION_API_KEY = os.getenv("NOTION_API_KEY", "your_notion_api_key")
23
- NOTION_DB_ID = os.getenv("NOTION_DB_ID", "your_database_id")
24
 
25
- if NOTION_API_KEY == "your_notion_api_key" or NOTION_DB_ID == "your_database_id":
26
- raise ValueError("請設置 Notion API Key 和資料庫 ID!")
27
 
28
  # 初始化 Notion 客戶端
29
  notion = Client(auth=NOTION_API_KEY)
@@ -51,7 +51,7 @@ class SimpleChatBot:
51
 
52
  # 使用 groq 的 chat.completions API 生成回應
53
  completion = client.chat.completions.create(
54
- model="llama-3.1-70b-versatile",
55
  messages=messages,
56
  temperature=1,
57
  max_tokens=1024,
@@ -59,7 +59,8 @@ class SimpleChatBot:
59
  stream=False,
60
  )
61
 
62
- response_content = completion["choices"][0]["message"]["content"]
 
63
  return response_content
64
 
65
  chatbot = SimpleChatBot()
 
18
  from notion_client import Client
19
  from groq import Groq
20
 
21
+ # 從環境變數中提取 Notion API Key 和資料庫 ID
22
+ NOTION_API_KEY = os.getenv("NOTION_API_KEY")
23
+ NOTION_DB_ID = os.getenv("NOTION_DB_ID")
24
 
25
+ if not NOTION_API_KEY or not NOTION_DB_ID:
26
+ raise ValueError("請設置 NOTION_API_KEY NOTION_DB_ID 環境變數!")
27
 
28
  # 初始化 Notion 客戶端
29
  notion = Client(auth=NOTION_API_KEY)
 
51
 
52
  # 使用 groq 的 chat.completions API 生成回應
53
  completion = client.chat.completions.create(
54
+ model="llama3-8b-8192",
55
  messages=messages,
56
  temperature=1,
57
  max_tokens=1024,
 
59
  stream=False,
60
  )
61
 
62
+ # 修正:正確提取 completion 的內容
63
+ response_content = completion.choices[0].message.content
64
  return response_content
65
 
66
  chatbot = SimpleChatBot()