Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
fix completions in openai
Browse files Browse the repository at this point in the history
  • Loading branch information
patcher9 committed Mar 16, 2024
1 parent 5d3bfbe commit 6e8a6e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
20 changes: 11 additions & 9 deletions src/dokumetry/async_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ async def llm_chat_completions(*args, **kwargs):
async def stream_generator():
accumulated_content = ""
async for chunk in await original_chat_create(*args, **kwargs):
#pylint: disable=line-too-long
if hasattr(chunk.choices[0], 'delta') and hasattr(chunk.choices[0].delta, 'content'):
content = chunk.choices[0].delta.content
if content:
accumulated_content += content
if len(chunk.choices) > 0:
#pylint: disable=line-too-long
if hasattr(chunk.choices[0], 'delta') and hasattr(chunk.choices[0].delta, 'content'):
content = chunk.choices[0].delta.content
if content:
accumulated_content += content
yield chunk
response_id = chunk.id
end_time = time.time()
Expand Down Expand Up @@ -171,10 +172,11 @@ async def llm_completions(*args, **kwargs):
async def stream_generator():
accumulated_content = ""
async for chunk in await original_completions_create(*args, **kwargs):
if hasattr(chunk.choices[0].text, 'content'):
content = chunk.choices[0].text
if content:
accumulated_content += content
if len(chunk.choices) > 0:
if hasattr(chunk.choices[0], 'text'):
content = chunk.choices[0].text
if content:
accumulated_content += content
yield chunk
response_id = chunk.id
end_time = time.time()
Expand Down
24 changes: 13 additions & 11 deletions src/dokumetry/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ def llm_chat_completions(*args, **kwargs):
def stream_generator():
accumulated_content = ""
for chunk in original_chat_create(*args, **kwargs):
#pylint: disable=line-too-long
if hasattr(chunk.choices[0], 'delta') and hasattr(chunk.choices[0].delta, 'content'):
content = chunk.choices[0].delta.content
if content:
accumulated_content += content
if len(chunk.choices) > 0:
#pylint: disable=line-too-long
if hasattr(chunk.choices[0], 'delta') and hasattr(chunk.choices[0].delta, 'content'):
content = chunk.choices[0].delta.content
if content:
accumulated_content += content
yield chunk
response_id = chunk.id
end_time = time.time()
Expand Down Expand Up @@ -170,11 +171,12 @@ def llm_completions(*args, **kwargs):
if streaming:
def stream_generator():
accumulated_content = ""
for chunk in original_chat_create(*args, **kwargs):
if hasattr(chunk.choices[0].text, 'content'):
content = chunk.choices[0].text
if content:
accumulated_content += content
for chunk in original_completions_create(*args, **kwargs):
if len(chunk.choices) > 0:
if hasattr(chunk.choices[0], 'text'):
content = chunk.choices[0].text
if content:
accumulated_content += content
yield chunk
response_id = chunk.id
end_time = time.time()
Expand Down Expand Up @@ -258,7 +260,7 @@ def patched_embeddings_create(*args, **kwargs):
end_time = time.time()
duration = end_time - start_time
model = kwargs.get('model', "No Model provided")
prompt = kwargs.get('input', "No prompt provided")
prompt = ', '.join(kwargs.get('input', []))

data = {
"environment": environment,
Expand Down

0 comments on commit 6e8a6e4

Please sign in to comment.