Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,12 +18,12 @@ install_and_import("groq")
|
|
| 18 |
from notion_client import Client
|
| 19 |
from groq import Groq
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
NOTION_API_KEY = os.getenv("NOTION_API_KEY"
|
| 23 |
-
NOTION_DB_ID = os.getenv("NOTION_DB_ID"
|
| 24 |
|
| 25 |
-
if NOTION_API_KEY
|
| 26 |
-
raise ValueError("請設置
|
| 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="
|
| 55 |
messages=messages,
|
| 56 |
temperature=1,
|
| 57 |
max_tokens=1024,
|
|
@@ -59,7 +59,8 @@ class SimpleChatBot:
|
|
| 59 |
stream=False,
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
|
|
|
| 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()
|