Skip to content

Commit

Permalink
fix: (models, sync) add error handling and logging for OpenAI respons…
Browse files Browse the repository at this point in the history
…es and data filtering
  • Loading branch information
yufeikang committed Jul 5, 2024
1 parent 2a163e7 commit 257c229
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ async def __chat(self, messages, model, temperature, **kwargs):
yield choice, None
return
async for chunk in res:
if not chunk.choices:
logger.error(f"OpenAI error: {chunk}")
yield None, None
return
yield chunk.choices[0], None

def get_models(self):
Expand Down
5 changes: 4 additions & 1 deletion app/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ async def get_sync_data(request: Request, after: str = Query(None)):
data = json.loads(f.read())
if after:
after_time = datetime.fromisoformat(after.replace("Z", "+00:00"))
logger.info(f"Filtering data after {after_time}")
data["updated"] = [
item
for item in data["updated"]
if datetime.fromisoformat(item["updated_at"].replace("Z", "+00:00"))
if datetime.fromisoformat(
item["client_updated_at"].replace("Z", "+00:00")
)
> after_time
]
return data
Expand Down

0 comments on commit 257c229

Please sign in to comment.