logo
chatglm
repo-copy-icon

copied

Browse Source

Debug

Signed-off-by: Jael Gu <mengjia.gu@zilliz.com>
main
Jael Gu 2 years ago
parent
commit
0a352c2e12
  1. 13
      zhipuai_chat.py

13
zhipuai_chat.py

@ -41,16 +41,13 @@ class ZhipuaiChat(PyOperator):
prompt=messages,
**self.kwargs
)
return self.stream_output(response)
else:
response = zhipuai.model_api.invoke(
model=self._model,
prompt=messages,
**self.kwargs
)
if self.stream:
for x in response.events():
yield {'event': x.event, 'id': x.id, 'data': x.data, 'meta': x.meta}
else:
return response
def parse_inputs(self, messages: List[dict]):
@ -67,12 +64,14 @@ class ZhipuaiChat(PyOperator):
elif k == 'answer':
new_m = {'role': 'assistant', 'content': v}
else:
'Invalid message key: only accept key value from ["question", "answer"].'
raise KeyError('Invalid message key: only accept key value from ["question", "answer"].')
new_messages.append(new_m)
return new_messages
def stream_output(self, response):
raise RuntimeError('Stream is not yet supported.')
@staticmethod
def stream_output(response):
for x in response.events():
yield {'event': x.event, 'id': x.id, 'data': x.data, 'meta': x.meta}
@staticmethod
def supported_model_names():

Loading…
Cancel
Save