diff --git a/devchat/assistant.py b/devchat/assistant.py index 10a94f00..ec20e55a 100755 --- a/devchat/assistant.py +++ b/devchat/assistant.py @@ -104,7 +104,10 @@ def iterate_response(self) -> Iterator[str]: if self._chat.config.stream: created_time = int(time.time()) config_params = self._chat.config.dict(exclude_unset=True) - for chunk in self._chat.stream_response(self._prompt): + stream_responses = self._chat.stream_response(self._prompt) + if not stream_responses: + raise RuntimeError("No response returned from the chat API") + for chunk in stream_responses: try: if hasattr(chunk, "dict"): chunk = chunk.dict() diff --git a/devchat/openai/http_openai.py b/devchat/openai/http_openai.py index e5ebdacd..c405b315 100755 --- a/devchat/openai/http_openai.py +++ b/devchat/openai/http_openai.py @@ -36,7 +36,8 @@ def stream_response(connection: http.client.HTTPSConnection, data, headers): response = connection.getresponse() if response.status != 200: - print(f"Error: {response.status} - {response.reason}") + print(f"Error: {response.status} - {response.reason} {response.read()}", + end="\n\n", file=sys.stderr) return None return LineReader(response=response)