Spaces:
Runtime error
Runtime error
response = openai.ChatCompletion.create(
Browse files
app.py
CHANGED
@@ -25,16 +25,19 @@ def create_chat_dialogue(rounds, role1, role2, theme="購物"):
|
|
25 |
|
26 |
# 初始化對話
|
27 |
prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"A\", content: \".....\"}}, {{role:\"B\", content: \".....\"}}]"
|
|
|
|
|
|
|
28 |
|
29 |
-
response = openai.
|
30 |
model="gpt-3.5-turbo",
|
31 |
-
|
32 |
max_tokens=500 # 設定一個較大的值,可根據需要調整
|
33 |
)
|
34 |
|
35 |
print(response)
|
36 |
|
37 |
-
response_text = response.choices[0].
|
38 |
dialogue = extract_json_from_response(response_text)
|
39 |
|
40 |
print(dialogue)
|
|
|
25 |
|
26 |
# 初始化對話
|
27 |
prompt = f"您將進行一場以{theme}為主題的對話。{role1}和{role2}將是參與者。請依次交談{rounds}輪。以json格式儲存對話。並回傳對話JSON文件。格式為:[{{role:\"A\", content: \".....\"}}, {{role:\"B\", content: \".....\"}}]"
|
28 |
+
messages = [
|
29 |
+
{"role": "user", "content": prompt}
|
30 |
+
]
|
31 |
|
32 |
+
response = openai.ChatCompletion.create(
|
33 |
model="gpt-3.5-turbo",
|
34 |
+
messages=messages,
|
35 |
max_tokens=500 # 設定一個較大的值,可根據需要調整
|
36 |
)
|
37 |
|
38 |
print(response)
|
39 |
|
40 |
+
response_text = response.choices[0].message['content'].strip()
|
41 |
dialogue = extract_json_from_response(response_text)
|
42 |
|
43 |
print(dialogue)
|