Skip to content

Commit

Permalink
fix None openaiMetadta
Browse files Browse the repository at this point in the history
  • Loading branch information
bdqfork committed Feb 4, 2024
1 parent 96406aa commit 0428d89
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libs/superagent/app/api/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ async def delete(agent_id: str, api_user=Depends(get_current_api_user)):
if SEGMENT_WRITE_KEY:
analytics.track(api_user.id, "Deleted Agent")
deleted = await prisma.agent.delete(where={"id": agent_id})
if deleted is None or deleted.openaiMetadata is None:
return {"success": True, "data": None}
openaiMetadata = json.loads(deleted.openaiMetadata)
if openaiMetadata.get("id", None):
llm = await prisma.llm.find_first_or_raise(
Expand Down Expand Up @@ -254,6 +256,8 @@ async def update(
"apiUserId": api_user.id,
},
)
if data.openaiMetadata is None:
return {"success": True, "data": data}
openaiMetadata = json.loads(data.openaiMetadata)
if openaiMetadata:
llm = await prisma.llm.find_first_or_raise(
Expand Down Expand Up @@ -427,7 +431,8 @@ def track_agent_invocation(result):
},
)

costCallback = CostCalcAsyncHandler(model=LLM_MAPPING[agent_config.llmModel])
costCallback = CostCalcAsyncHandler(
model=LLM_MAPPING[agent_config.llmModel])

agentCallbacks = [costCallback]

Expand Down Expand Up @@ -481,7 +486,8 @@ async def send_message(
logging.error(f"Error in send_message: {error}")
if SEGMENT_WRITE_KEY:
try:
track_agent_invocation({"error": str(error), "status_code": 500})
track_agent_invocation(
{"error": str(error), "status_code": 500})
except Exception as e:
logging.error(f"Error tracking agent invocation: {e}")
yield ("event: error\n" f"data: {error}\n\n")
Expand Down

0 comments on commit 0428d89

Please sign in to comment.