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

Method ask

demos/chatgpt.py:78–92  ·  view source on GitHub ↗

Send a message to chatgpt and get the reply in string :param message: The message to send :param model_kwargs: Other parameters to pass to openai.ChatCompletion.create() :return: The reply from chatgpt

(self, message: str, **model_kwargs)

Source from the content-addressed store, hash-verified

76 return resp
77
78 def ask(self, message: str, **model_kwargs) -> str:
79 """
80 Send a message to chatgpt and get the reply in string
81
82 :param message: The message to send
83 :param model_kwargs: Other parameters to pass to openai.ChatCompletion.create()
84 :return: The reply from chatgpt
85 """
86 resp = self._ask(message, stream=False, **model_kwargs)
87 reply = resp['choices'][0]
88 reply_content = reply['message']['content']
89 self._messages.append({"role": "assistant", "content": reply_content})
90 self.latest_nonstream_finish_reason = reply['finish_reason']
91
92 return reply_content
93
94 def ask_stream(self, message: str, **model_kwargs) -> ChatGPTStreamResponse:
95 """

Callers

nothing calls this directly

Calls 2

_askMethod · 0.95
appendMethod · 0.80

Tested by

no test coverage detected