Skip to content

Commit

Permalink
fix: DIA-1534: prompts containing {} throw an error in cost estimate (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-bernstein authored Oct 25, 2024
1 parent 43bfb50 commit 0c667eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion adala/runtimes/_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ def get_cost_estimate(
) -> CostEstimate:
try:
user_prompts = [
prompt.format(**substitution) for substitution in substitutions
partial_str_format(prompt, **substitution)
for substitution in substitutions
]
cumulative_prompt_cost = 0
cumulative_completion_cost = 0
Expand Down
18 changes: 13 additions & 5 deletions tests/test_cost_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
import pytest
from adala.runtimes._litellm import AsyncLiteLLMChatRuntime
from adala.runtimes.base import CostEstimate
from adala.agents import Agent
from adala.skills import ClassificationSkill
import numpy as np
import os
from fastapi.testclient import TestClient
from server.app import app, CostEstimateRequest

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

Expand Down Expand Up @@ -60,7 +56,19 @@ def test_estimate_cost_endpoint(client):
}
},
},
"prompt": "test {text}",
"prompt": """
test {text}
Use the following JSON format:
{
"data": [
{
"output": "<output>",
"reasoning": "<reasoning>",
}
]
}
""",
"substitutions": [{"text": "test"}],
}
resp = client.post(
Expand Down

0 comments on commit 0c667eb

Please sign in to comment.