File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed
Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ appdirs==1.4.4
77webchatgpt == 0.2.7
88GoogleBard == 1.4.0
99colorama == 0.4.6
10- g4f >= 0.2.0.6
10+ g4f >= 0.2.0.6
11+ pyyaml == 6.0.1
Original file line number Diff line number Diff line change 4747 "GoogleBard==1.4.0" ,
4848 "colorama==0.4.6" ,
4949 "g4f>=0.2.0.6" ,
50+ "pyyaml==6.0.1" ,
5051 ],
5152 python_requires = ">=3.9" ,
5253 keywords = [
Original file line number Diff line number Diff line change 11import re
22import json
3+ import yaml
34import requests
45from pytgpt .utils import Optimizers
56from pytgpt .utils import Conversation
@@ -150,6 +151,7 @@ def for_stream():
150151 ):
151152 try :
152153 modified_value = re .sub ("data:" , "" , value )
154+ print (modified_value )
153155 json_modified_value = json .loads (modified_value )
154156 retrieved_text = self .get_message (json_modified_value )
155157 if not retrieved_text :
@@ -218,8 +220,24 @@ def get_message(self, response: dict) -> str:
218220 str: Message extracted
219221 """
220222 assert isinstance (response , dict ), "Response should be of dict data-type only"
221- return (
222- response ["choices" ][0 ]["delta" ]["content" ]
223- if response ["choices" ][0 ]["finish_reason" ] is None
223+ delta : dict = response ["choices" ][0 ]["delta" ]
224+
225+ if not delta :
226+ return ''
227+
228+ elif delta .get ('function_call' ):
229+ function_call : dict = delta ['function_call' ]
230+ if function_call .get ('name' ):
231+ return function_call ['name' ]
232+ elif function_call .get ('arguments' ):
233+ return function_call .get ('arguments' )
234+
235+ elif delta .get ('metadata' ):
236+ return yaml .dump (delta ['metadata' ])
237+
238+ else :
239+ return (
240+ response ["choices" ][0 ]["delta" ].get ("content" )
241+ if response ["choices" ][0 ].get ("finish_reason" ) is None
224242 else ""
225- )
243+ )
You can’t perform that action at this time.
0 commit comments