Added error handling for scenarios where the key 'completion' is not present in the 'claude_response' dictionary. This exception was causing the program to crash when the application tried to access the 'completion' key in the 'claude_response' dictionary.
Now, the 'get' method is used on the dictionary which allows the program to provide a default value of an empty string if the 'completion' key is not present. This prevents a KeyError from being raised and allows the program to continue execution. The affected methods are 'claude_to_chatgpt_response_stream' and 'claude_to_chatgpt_response'.
This is an important fix that improves the robustness of the code by handling potential exceptions arising from unexpected data structures.
Implemented a timeout for the HTTPX client to avoid ReadTimeout errors. This change ensures the client operations do not hang indefinitely when there are network issues, by providing a predefined time limit for the request to either succeed or raise a timeout exception.
In both functions claude_to_chatgpt_response_stream and claude_to_chatgpt_response, claude_response.get("completion", "") is used instead of claude_response["completion"] to prevent KeyError if completion is not in claude_response. If completion is not present, it will return an empty string as default, and this empty string is then passed to num_tokens_from_string. Please adjust the default value according to your requirements.
In this PR, we've made two improvements:
Now, the 'get' method is used on the dictionary which allows the program to provide a default value of an empty string if the 'completion' key is not present. This prevents a KeyError from being raised and allows the program to continue execution. The affected methods are 'claude_to_chatgpt_response_stream' and 'claude_to_chatgpt_response'.
This is an important fix that improves the robustness of the code by handling potential exceptions arising from unexpected data structures.
In both functions claude_to_chatgpt_response_stream and claude_to_chatgpt_response, claude_response.get("completion", "") is used instead of claude_response["completion"] to prevent KeyError if completion is not in claude_response. If completion is not present, it will return an empty string as default, and this empty string is then passed to num_tokens_from_string. Please adjust the default value according to your requirements.
It is related to https://github.com/jtsang4/claude-to-chatgpt/issues/6 https://github.com/jtsang4/claude-to-chatgpt/issues/7 and https://github.com/jtsang4/claude-to-chatgpt/issues/2 . I think I fixed it. At least fixed the error when long query was sent.