Skip to content

Commit

Permalink
Merge pull request #10 from JamesFlare1212/main
Browse files Browse the repository at this point in the history
Handle KeyError for 'completion' and add timeout for HTTPX client
  • Loading branch information
jtsang4 committed Jun 13, 2023
2 parents eab0b92 + de2cd5c commit 6a17657
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions claude_to_chatgpt/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def openai_to_claude_params(self, openai_params):
return claude_params

def claude_to_chatgpt_response_stream(self, claude_response, prev_decoded_response):
completion_tokens = num_tokens_from_string(claude_response["completion"])
completion_tokens = num_tokens_from_string(claude_response.get("completion", ""))
openai_response = {
"id": f"chatcmpl-{str(time.time())}",
"object": "chat.completion.chunk",
Expand Down Expand Up @@ -98,7 +98,7 @@ def claude_to_chatgpt_response_stream(self, claude_response, prev_decoded_respon
return openai_response

def claude_to_chatgpt_response(self, claude_response):
completion_tokens = num_tokens_from_string(claude_response["completion"])
completion_tokens = num_tokens_from_string(claude_response.get("completion", ""))
openai_response = {
"id": f"chatcmpl-{str(time.time())}",
"object": "chat.completion",
Expand Down Expand Up @@ -131,7 +131,7 @@ async def chat(self, request: Request):
claude_params = self.openai_to_claude_params(openai_params)
api_key = self.get_api_key(headers)

async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(timeout=120.0) as client:
if not claude_params.get("stream", False):
response = await client.post(
f"{self.claude_base_url}/v1/complete",
Expand Down

0 comments on commit 6a17657

Please sign in to comment.