|
5 | 5 | from typing import List |
6 | 6 |
|
7 | 7 | from litellm import acompletion |
| 8 | +from typing import Dict |
8 | 9 |
|
9 | 10 | from eval_protocol.dataset_logger import default_logger |
10 | 11 | from eval_protocol.models import EvaluationRow, Message |
@@ -61,10 +62,15 @@ async def process_row(row: EvaluationRow) -> EvaluationRow: |
61 | 62 | if row.tools is not None: |
62 | 63 | request_params["tools"] = row.tools |
63 | 64 |
|
| 65 | + # Dynamic import to avoid static dependency/lint errors if LiteLLM isn't installed yet |
| 66 | + import importlib |
| 67 | + |
| 68 | + _litellm = importlib.import_module("litellm") |
| 69 | + acompletion = getattr(_litellm, "acompletion") |
64 | 70 | response = await acompletion(**request_params) |
65 | 71 |
|
66 | | - assistant_content = response.choices[0].message.content or "" # pyright: ignore[reportAttributeAccessIssue] |
67 | | - tool_calls = response.choices[0].message.tool_calls if response.choices[0].message.tool_calls else None # pyright: ignore[reportAttributeAccessIssue] |
| 72 | + assistant_content = response.choices[0].message.content or "" |
| 73 | + tool_calls = response.choices[0].message.tool_calls if response.choices[0].message.tool_calls else None |
68 | 74 |
|
69 | 75 | converted_tool_calls = None |
70 | 76 | if tool_calls: |
@@ -106,9 +112,9 @@ async def process_row(row: EvaluationRow) -> EvaluationRow: |
106 | 112 | ] |
107 | 113 |
|
108 | 114 | row.execution_metadata.usage = CompletionUsage( |
109 | | - prompt_tokens=response.usage.prompt_tokens, # pyright: ignore[reportAttributeAccessIssue] |
110 | | - completion_tokens=response.usage.completion_tokens, # pyright: ignore[reportAttributeAccessIssue] |
111 | | - total_tokens=response.usage.total_tokens, # pyright: ignore[reportAttributeAccessIssue] |
| 115 | + prompt_tokens=response.usage.prompt_tokens, |
| 116 | + completion_tokens=response.usage.completion_tokens, |
| 117 | + total_tokens=response.usage.total_tokens, |
112 | 118 | ) |
113 | 119 |
|
114 | 120 | row.messages = messages |
|
0 commit comments