youngtsai commited on
Commit
61cea89
1 Parent(s): b90df65

response = openai.ChatCompletion.create(

Browse files
Files changed (1) hide show
  1. app.py +6 -3
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.Completion.create(
30
  model="gpt-3.5-turbo",
31
- prompt=prompt,
32
  max_tokens=500 # 設定一個較大的值,可根據需要調整
33
  )
34
 
35
  print(response)
36
 
37
- response_text = response.choices[0].text.strip()
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)