youngtsai commited on
Commit
d8ab087
1 Parent(s): f4b741f

print(json_response)

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -34,6 +34,30 @@ def update_buttons(df_string):
34
 
35
  def generate_questions(df_string):
36
  # 使用 OpenAI 生成基于上传数据的问题
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  # 这里需要编写代码来实现此功能
38
  questions = ["问题 1", "问题 2", "问题 3"] # 示例问题列表
39
  return questions
 
34
 
35
  def generate_questions(df_string):
36
  # 使用 OpenAI 生成基于上传数据的问题
37
+
38
+ sys_content = f"你是一個資料分析師,請用 {df_string_output} 為資料進行對話,使用 zh-TW"
39
+ messages = [
40
+ {"role": "system", "content": sys_content},
41
+ {"role": "user", "content": "請根據 {df_string_output} 生成三個問題,並用 JSON 格式返回 questions:[q1, q2, q3]"}
42
+ ]
43
+ response_format = { "type": "json_object" }
44
+
45
+ print("=====messages=====")
46
+ print(messages)
47
+ print("=====messages=====")
48
+
49
+
50
+ request_payload = {
51
+ "model": "gpt-4-1106-preview",
52
+ "messages": messages,
53
+ "max_tokens": 2000,
54
+ "response_format": response_format
55
+ }
56
+
57
+ json_response = client.chat.completions.create(**request_payload)
58
+ print("=====json_response=====")
59
+ print(json_response)
60
+
61
  # 这里需要编写代码来实现此功能
62
  questions = ["问题 1", "问题 2", "问题 3"] # 示例问题列表
63
  return questions