XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

emojin encoding problem idk how to fix it

659e2f4f
Bagus Indrayana <bagusindrayanaindo@gmail.com>
提交于

代码差异

3 个文件 +26 -22
Modified testing/binghuan/BingHuan.py +3 -3
@@ -13,13 +13,13 @@ def _create_completion(model: str, messages: list, stream: bool, **kwargs):
13 13 config = json.dumps({
14 14 'messages': messages,
15 15 'model': model}, separators=(',', ':'))
16
17 16 cmd = ['python', f'{path}/helpers/binghuan.py', config]
18 17
19 18 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
20
19
21 20 for line in iter(p.stdout.readline, b''):
22 yield line.decode('cp1252') #[:-1]
21 yield line.decode('utf-8')
22
23 23
24 24
25 25 # params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
Modified testing/binghuan/helpers/binghuan.py +6 -4
@@ -210,10 +210,12 @@ async def run(optionSets, messages):
210 210 prompt = messages[-1]['content']
211 211 if(len(messages) > 1):
212 212 prompt = convert(messages)
213 async for value in AsyncCompletion.create(prompt=prompt,
214 optionSets=optionSets):
215
216 print(value, flush=True, end = '')
213 async for value in AsyncCompletion.create(prompt=prompt, optionSets=optionSets):
214 try:
215 print(value, flush=True, end='')
216 except UnicodeEncodeError as e:
217 # emoji encoding problem
218 print(value.encode('utf-8'), flush=True, end='')
217 219
218 220 optionSet = conversationstyles[config['model']]
219 221 asyncio.run(run(optionSet, config['messages']))
Modified testing/binghuan/testing.py +17 -15
@@ -1,12 +1,14 @@
1 1 from BingHuan import ChatCompletion
2 # text = "Hello, this is Bing. I can help you find information on the web, generate content such as poems, stories, code, essays, songs, celebrity parodies and more. I can also help you with rewriting, improving, or optimizing your content. Is there anything specific you would like me to help you with? 😊"
3 # print(text.encode('utf-8'))
2 4
3 # Test 1
4 response = ChatCompletion.create(model="gpt-3.5-turbo",
5 provider="BingHuan",
6 stream=False,
7 messages=[{'role': 'user', 'content': 'who are you?'}])
5 # # Test 1
6 # response = ChatCompletion.create(model="gpt-3.5-turbo",
7 # provider="BingHuan",
8 # stream=False,
9 # messages=[{'role': 'user', 'content': 'who are you?'}])
8 10
9 print(response)
11 # print(response)
10 12
11 13 # Test 2
12 14 response = ChatCompletion.create(model="gpt-3.5-turbo",
@@ -18,13 +20,13 @@ print(response)
18 20
19 21
20 22 # Test 3
21 response = ChatCompletion.create(model="gpt-4",
22 provider="BingHuan",
23 stream=False,
24 messages=[
25 {'role': 'user', 'content': 'now your name is Bob'},
26 {'role': 'assistant', 'content': 'Hello Im Bob, you asistant'},
27 {'role': 'user', 'content': 'what your name again?'},
28 ])
23 # response = ChatCompletion.create(model="gpt-4",
24 # provider="BingHuan",
25 # stream=False,
26 # messages=[
27 # {'role': 'user', 'content': 'now your name is Bob'},
28 # {'role': 'assistant', 'content': 'Hello Im Bob, you asistant'},
29 # {'role': 'user', 'content': 'what your name again?'},
30 # ])
29 31
30 print(response)
32 # print(response)