MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / ask_stream

Method ask_stream

demos/chatgpt.py:94–105  ·  view source on GitHub ↗

Send a message to chatgpt and get the reply in stream :param message: The message to send :param model_kwargs: Other parameters to pass to openai.ChatCompletion.create() :return: A iterator that yields the reply from chatgpt. The iterator will be exhausted

(self, message: str, **model_kwargs)

Source from the content-addressed store, hash-verified

92 return reply_content
93
94 def ask_stream(self, message: str, **model_kwargs) -> ChatGPTStreamResponse:
95 """
96 Send a message to chatgpt and get the reply in stream
97
98 :param message: The message to send
99 :param model_kwargs: Other parameters to pass to openai.ChatCompletion.create()
100 :return: A iterator that yields the reply from chatgpt.
101 The iterator will be exhausted when the reply is complete.
102 """
103 resp = self._ask(message, stream=True, **model_kwargs)
104 self.pending_stream_reply = ChatGPTStreamResponse(resp)
105 return self.pending_stream_reply
106
107 def latest_finish_reason(self) -> str:
108 """The finish reason for the latest reply of chatgpt.

Callers 1

mainFunction · 0.95

Calls 2

_askMethod · 0.95

Tested by

no test coverage detected