Skip to content

Commit

Permalink
Added kwargs to call_single (#46)
Browse files Browse the repository at this point in the history
* added kwargs to call_single to allow customization when calling it directly

* Added a test to check if kwargs is passed correctly

* Updated tests

* grouped kwargs tests in a subtest
  • Loading branch information
maykcaldas authored Jan 28, 2025
1 parent b6ca776 commit 7d5c739
Show file tree
Hide file tree
Showing 9 changed files with 1,336 additions and 1,136 deletions.
3 changes: 2 additions & 1 deletion llmclient/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ async def call_single(
output_type: type[BaseModel] | TypeAdapter | JSONSchema | None = None,
tools: list[Tool] | None = None,
tool_choice: Tool | str | None = TOOL_CHOICE_REQUIRED,
**kwargs,
) -> LLMResult:
results = await self.call(
messages, callbacks, name, output_type, tools, tool_choice, n=1
messages, callbacks, name, output_type, tools, tool_choice, n=1, **kwargs
)
if not results:
raise ValueError("No results returned from call")
Expand Down
1,261 changes: 495 additions & 766 deletions tests/cassettes/TestLiteLLMModel.test_call_single[with-router].yaml

Large diffs are not rendered by default.

532 changes: 169 additions & 363 deletions tests/cassettes/TestLiteLLMModel.test_call_single[without-router].yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
interactions:
- request:
body:
'{"model": "claude-3-5-haiku-20241022", "messages": [{"role": "user", "content":
[{"type": "text", "text": "What is the meaning of the universe?"}]}], "temperature":
0, "max_tokens": 56, "system": [{"type": "text", "text": "Respond with single
words."}]}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
anthropic-version:
- "2023-06-01"
connection:
- keep-alive
content-length:
- "253"
content-type:
- application/json
host:
- api.anthropic.com
user-agent:
- litellm/1.59.5
method: POST
uri: https://api.anthropic.com/v1/messages
response:
body:
string: !!binary |
H4sIAAAAAAAAA2SOMWvDMBSE/8vNcrDVplCNXbpkrOkQilDkRyLbeXKkJ9Ji/N+LQwMtnQ7uuztu
RuhgcM5HWzdtv7vu0uHSvz21L8+U3g/9KzdQkK+J1hTl7I4EhRTH1XA5hyyOBQrn2NEIAz+60lH1
UG2rkwtDqXStH5taayj4yEIsMPv5vin0ubZvYtDywPHKGywfClniZBO5HBkGxJ2Vkhg/INOlEHuC
4TKOCuV2zcwIPBWxEgfiDKMbBe/8iaxP5CREtn8D9Z0nct1/Fov8drbL8g0AAP//AwD1M9oFMwEA
AA==
headers:
CF-RAY:
- 909370809f0f15e3-SJC
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Tue, 28 Jan 2025 19:37:51 GMT
Server:
- cloudflare
Transfer-Encoding:
- chunked
X-Robots-Tag:
- none
anthropic-ratelimit-input-tokens-limit:
- "5000000"
anthropic-ratelimit-input-tokens-remaining:
- "5000000"
anthropic-ratelimit-input-tokens-reset:
- "2025-01-28T19:37:51Z"
anthropic-ratelimit-output-tokens-limit:
- "1000000"
anthropic-ratelimit-output-tokens-remaining:
- "1000000"
anthropic-ratelimit-output-tokens-reset:
- "2025-01-28T19:37:51Z"
anthropic-ratelimit-requests-limit:
- "5000"
anthropic-ratelimit-requests-remaining:
- "4999"
anthropic-ratelimit-requests-reset:
- "2025-01-28T19:37:51Z"
anthropic-ratelimit-tokens-limit:
- "6000000"
anthropic-ratelimit-tokens-remaining:
- "6000000"
anthropic-ratelimit-tokens-reset:
- "2025-01-28T19:37:51Z"
cf-cache-status:
- DYNAMIC
request-id:
- req_01Eppf1xbA8q5A3TkRYsr68g
via:
- 1.1 google
status:
code: 200
message: OK
version: 1
107 changes: 107 additions & 0 deletions tests/cassettes/TestLiteLLMModel.test_cost_call[OpenAI-model].yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
interactions:
- request:
body:
'{"messages": [{"role": "system", "content": "Respond with single words."},
{"role": "user", "content": "What is the meaning of the universe?"}], "model":
"gpt-4o-mini-2024-07-18", "max_tokens": 56, "temperature": 0}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- "215"
content-type:
- application/json
host:
- api.openai.com
user-agent:
- AsyncOpenAI/Python 1.60.0
x-stainless-arch:
- arm64
x-stainless-async:
- async:asyncio
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.60.0
x-stainless-raw-response:
- "true"
x-stainless-retry-count:
- "0"
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.11.10
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//jJJBT+MwEIXv+RXWnBuUlqKU3jhwQHBgkRAHhCLXniSmjseyJ7usUP87
clKaIFhpLznMN+/lzXjeMyHAaNgKUK1k1XmbX/W23fx6etjvLx4e63b55zEEurm7vLnt6B4WSUG7
V1T8qTpT1HmLbMiNWAWUjMl1WZ5visvzoiwG0JFGm2SN53xNeWecyVfFap0XZb7cHNUtGYURtuI5
E0KI9+GbcjqNb7AVg9dQ6TBG2SBsT01CQCCbKiBjNJGlY1hMUJFjdEP06zcTGZ3Cs3lDwLqPMoV0
vbXH+uH0R0uND7SLR36q18aZ2FYBZSSX3COTh4EeMiFehsn6L2HBB+o8V0x7dMlwtR7tYNrnBD8Z
E0s702wWP5hVGlkaG2eLASVVi3pSTluUvTY0A9ls5O9ZfvIexzau+R/7CSiFnlFXPqA26uu8U1vA
dGz/ajuteAgMEcNvo7BigyE9g8Za9nY8AYh/I2NX1cY1GHww4x3UvipXqEu5u1gryA7ZBwAAAP//
AwC1HS6hFQMAAA==
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 9093707c3c60174a-SJC
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Tue, 28 Jan 2025 19:37:51 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=dqIilPhCKBMWrfzBIKv4Z773uZfIHyMVkz9CwPgIUtA-1738093071-1.0.1.1-eLZ4cnMA8fb5u55VPgPzLBwaJH8MbcL3FaS_WIZ7m1Y2PPk00cpUZHpTcwEErfVXeYRqTRcDOGjb4niE.byJ3A;
path=/; expires=Tue, 28-Jan-25 20:07:51 GMT; domain=.api.openai.com; HttpOnly;
Secure; SameSite=None
- _cfuvid=VubHV4jc3NAG1.KYK.9ezrasy_FR9RQDSt8gSdEubnM-1738093071389-0.0.1.1-604800000;
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
alt-svc:
- h3=":443"; ma=86400
openai-organization:
- future-house-xr4tdh
openai-processing-ms:
- "490"
openai-version:
- "2020-10-01"
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-ratelimit-limit-requests:
- "30000"
x-ratelimit-limit-tokens:
- "150000000"
x-ratelimit-remaining-requests:
- "29999"
x-ratelimit-remaining-tokens:
- "149999926"
x-ratelimit-reset-requests:
- 2ms
x-ratelimit-reset-tokens:
- 0s
x-request-id:
- req_e0ce487241223e824cc737d821b5495c
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit 7d5c739

Please sign in to comment.