Skip to content

Commit

Permalink
Update formatting in admin.py and utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaimran committed Jan 6, 2025
1 parent aa442c2 commit 689d9d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/khoj/database/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,15 @@ def queryset(self, request, queryset):
fieldsets = (
(
"Personal info",
{"fields": ("phone_number", "email_verification_code", "verified_phone_number", "verified_email","email_verification_code_expiry")},
{
"fields": (
"phone_number",
"email_verification_code",
"verified_phone_number",
"verified_email",
"email_verification_code_expiry",
)
},
),
) + UserAdmin.fieldsets

Expand Down
9 changes: 7 additions & 2 deletions src/khoj/processor/conversation/openai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def completion_with_backoff(
# Calculate cost of chat
input_tokens = chunk.usage.prompt_tokens if hasattr(chunk, "usage") and chunk.usage else 0
output_tokens = chunk.usage.completion_tokens if hasattr(chunk, "usage") and chunk.usage else 0
cost = chunk.usage.model_extra.get("estimated_cost", 0) if hasattr(chunk, "usage") and chunk.usage else 0 # Estimated costs returned by DeepInfra API
cost = (
chunk.usage.model_extra.get("estimated_cost", 0) if hasattr(chunk, "usage") and chunk.usage else 0
) # Estimated costs returned by DeepInfra API

tracer["usage"] = get_chat_usage_metrics(model_name, input_tokens, output_tokens, tracer.get("usage"), cost)

# Save conversation trace
Expand Down Expand Up @@ -215,7 +218,9 @@ def llm_thread(
# Calculate cost of chat
input_tokens = chunk.usage.prompt_tokens if hasattr(chunk, "usage") and chunk.usage else 0
output_tokens = chunk.usage.completion_tokens if hasattr(chunk, "usage") and chunk.usage else 0
cost = chunk.usage.model_extra.get("estimated_cost", 0) if hasattr(chunk, "usage") and chunk.usage else 0 # Estimated costs returned by DeepInfra API
cost = (
chunk.usage.model_extra.get("estimated_cost", 0) if hasattr(chunk, "usage") and chunk.usage else 0
) # Estimated costs returned by DeepInfra API
tracer["usage"] = get_chat_usage_metrics(model_name, input_tokens, output_tokens, tracer.get("usage"), cost)

# Save conversation trace
Expand Down

0 comments on commit 689d9d8

Please sign in to comment.