xiaolv commited on
Commit
d6bbdb0
1 Parent(s): bc73251

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -45,20 +45,20 @@ def request_to_v2(message, cookie, user_id, channel_id,context=[]):
45
 
46
  try:
47
  response = requests.post(post_msg_url, headers=headers, data=post_msg_data, verify=False,timeout = timeout,impersonate="chrome110")
48
- bots = ""
49
- print("a"*100)
50
- for data in response.iter_lines():
51
- if data:
52
- # 将字节字符串转换为字符串
53
- data_str = data.decode('utf-8')
54
- # 删除开头的 "data: " 部分
55
- data_str = data_str.replace("data: ", "")
56
- data_json = json.loads(data_str)
57
- # print(data_json)
58
- bots += data_json["completion"]
59
  print(bots)
60
  context += [bots]
61
  responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
 
62
  return responses, context
63
 
64
  except Exception as e:
 
45
 
46
  try:
47
  response = requests.post(post_msg_url, headers=headers, data=post_msg_data, verify=False,timeout = timeout,impersonate="chrome110")
48
+ decoded_data = response.content.decode("utf-8")
49
+ decoded_data = re.sub('\n+', '\n', decoded_data).strip()
50
+ data_strings = decoded_data.split('\n')
51
+ completions = []
52
+ for data_string in data_strings:
53
+ json_str = data_string[6:].strip()
54
+ data = json.loads(json_str)
55
+ if 'completion' in data:
56
+ completions.append(data['completion'])
57
+ bots = ''.join(completions)
 
58
  print(bots)
59
  context += [bots]
60
  responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
61
+ print("a"*100)
62
  return responses, context
63
 
64
  except Exception as e: