Jiana commited on
Commit
7825a73
·
1 Parent(s): 6927855

Update app.py

Browse files

不用user有不同的info;用set和get的方式存储和修改user info

Files changed (1) hide show
  1. app.py +80 -13
app.py CHANGED
@@ -47,28 +47,91 @@ predefined_prompts = [
47
  prompt_4
48
  ]
49
 
50
- user_response = ["pred def" for _ in range(6)]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- count_i = 1
53
 
54
  def get_info(p, qid, uid):
55
- global predefined_prompts
56
- global user_response
57
- global count_i
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- user_response[count_i-1] = p
60
 
61
- next_prompt = predefined_prompts[count_i]
62
- count_i += 1
 
 
 
 
63
  logger.info(f"In get info loop: get from user: {p}")
64
- logger.info(f"In get info loop: Our next prompt: {next_prompt}, count_i={count_i}")
65
  return ["text", next_prompt]
66
 
67
 
68
 
69
  def chat(p, qid, uid):
70
- global user_response
71
- global count_i
 
 
 
 
 
72
 
73
  if count_i <= 4:
74
  ret = get_info(p, qid, uid)
@@ -77,7 +140,8 @@ def chat(p, qid, uid):
77
 
78
 
79
  if count_i == 5: # 5
80
- user_response[4] = p
 
81
  prompt_0_response = user_response[0]
82
  prompt_1_response = user_response[1]
83
  prompt_2_response = user_response[2]
@@ -101,7 +165,10 @@ def chat(p, qid, uid):
101
  logger.info(f"history: {msgs}")
102
  logger.info(f"p: {p}")
103
  logger.info(f"response: {response}")
104
- count_i += 1
 
 
 
105
  return ["text", response]
106
 
107
 
 
47
  prompt_4
48
  ]
49
 
50
+ _user_response = ["pred def" for _ in range(6)]
51
+
52
+ # count_i = 1
53
+ count_i_dict = dict()
54
+
55
+ def init_user_info(uid):
56
+ global count_i_dict
57
+ count_i_dict[uid] = dict()
58
+ count_i_dict[uid]["count_i"] = 1
59
+ count_i_dict[uid]["user_response"] = _user_response
60
+
61
+
62
+ def get_count_i(uid):
63
+ global count_i_dict
64
+ if uid not count_i_dict:
65
+ return 1
66
+ return count_i_dict[uid]["count_i"]
67
+
68
+ def set_count_i(uid, delta=1):
69
+ global count_i_dict
70
+ if uid not in count_i_dict:
71
+ # TODO: call user prof init
72
+ return
73
+
74
+ count_i_dict[uid]["count_i"] += delta
75
+
76
+
77
+ def get_user_response(uid, i=0):
78
+ global count_i_dict
79
+
80
+ if uid not in count_i_dict:
81
+ return ""
82
+
83
+ return count_i_dict[uid]["user_response"][i]
84
+
85
+ def set_user_response(uid, i, current_p):
86
+ global count_i_dict
87
+ if uid not in count_i_dict:
88
+ # TODO: call user prof init
89
+ return
90
+
91
+ count_i_dict[uid]["user_response"][i] = current_p
92
+
93
+
94
 
 
95
 
96
  def get_info(p, qid, uid):
97
+ global predefined_prompts
98
+ # global user_response
99
+ # global count_i
100
+ global count_i_dict
101
+
102
+ if uid not in count_i_dict:
103
+ init_user_info(uid)
104
+ logger.info(f"Init info for user {uid}")
105
+
106
+ # current_count_i = count_i_dict[uid]["count_i"]
107
+ current_count_i = get_count_i(uid)
108
+ # count_i_dict[uid]["user_response"][current_count_i-1] = p
109
+ set_user_response(uid, current_count_i-1, p)
110
+
111
+ # user_response[current_count_i-1] = p
112
+ # user_response[count_i-1] = p
113
 
 
114
 
115
+ next_prompt = predefined_prompts[current_count_i]
116
+ set_count_i(uid, 1)
117
+
118
+ # count_i += 1
119
+ # count_i_dict[uid]["count_i"] += 1
120
+
121
  logger.info(f"In get info loop: get from user: {p}")
122
+ logger.info(f"In get info loop: Our next prompt: {next_prompt}, uid={uid}, count_i={get_count_i(uid)}")
123
  return ["text", next_prompt]
124
 
125
 
126
 
127
  def chat(p, qid, uid):
128
+ # global user_response
129
+ # global count_i
130
+
131
+ global count_i_dict
132
+
133
+ count_i = get_count_i(uid)
134
+ # count_i = count_i_dict[uid]["count_i"]
135
 
136
  if count_i <= 4:
137
  ret = get_info(p, qid, uid)
 
140
 
141
 
142
  if count_i == 5: # 5
143
+ # user_response[4] = p
144
+ set_user_response(uid, count_i-1, p)
145
  prompt_0_response = user_response[0]
146
  prompt_1_response = user_response[1]
147
  prompt_2_response = user_response[2]
 
165
  logger.info(f"history: {msgs}")
166
  logger.info(f"p: {p}")
167
  logger.info(f"response: {response}")
168
+ # count_i_dict[uid]["count_i"] += 1
169
+ set_count_i(uid,1)
170
+
171
+
172
  return ["text", response]
173
 
174