mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
docs - using batch completions with python
This commit is contained in:
parent
bf2194d7fc
commit
25febe41c4
1 changed files with 96 additions and 0 deletions
|
|
@ -377,6 +377,95 @@ This same request will be sent to the following model groups on the [litellm pro
|
|||
- `model_name="llama3"`
|
||||
- `model_name="gpt-3.5-turbo"`
|
||||
|
||||
<Tabs>
|
||||
|
||||
<TabItem value="openai-py" label="OpenAI Python SDK">
|
||||
|
||||
|
||||
```python
|
||||
import openai
|
||||
|
||||
client = openai.OpenAI(api_key="sk-1234", base_url="http://0.0.0.0:4000")
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo,llama3",
|
||||
messages=[
|
||||
{"role": "user", "content": "this is a test request, write a short poem"}
|
||||
],
|
||||
)
|
||||
|
||||
print(response)
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Expected Response Format
|
||||
|
||||
Get a list of responses when `model` is passed as a list
|
||||
|
||||
```python
|
||||
[
|
||||
ChatCompletion(
|
||||
id='chatcmpl-9NoYhS2G0fswot0b6QpoQgmRQMaIf',
|
||||
choices=[
|
||||
Choice(
|
||||
finish_reason='stop',
|
||||
index=0,
|
||||
logprobs=None,
|
||||
message=ChatCompletionMessage(
|
||||
content='In the depths of my soul, a spark ignites\nA light that shines so pure and bright\nIt dances and leaps, refusing to die\nA flame of hope that reaches the sky\n\nIt warms my heart and fills me with bliss\nA reminder that in darkness, there is light to kiss\nSo I hold onto this fire, this guiding light\nAnd let it lead me through the darkest night.',
|
||||
role='assistant',
|
||||
function_call=None,
|
||||
tool_calls=None
|
||||
)
|
||||
)
|
||||
],
|
||||
created=1715462919,
|
||||
model='gpt-3.5-turbo-0125',
|
||||
object='chat.completion',
|
||||
system_fingerprint=None,
|
||||
usage=CompletionUsage(
|
||||
completion_tokens=83,
|
||||
prompt_tokens=17,
|
||||
total_tokens=100
|
||||
)
|
||||
),
|
||||
ChatCompletion(
|
||||
id='chatcmpl-4ac3e982-da4e-486d-bddb-ed1d5cb9c03c',
|
||||
choices=[
|
||||
Choice(
|
||||
finish_reason='stop',
|
||||
index=0,
|
||||
logprobs=None,
|
||||
message=ChatCompletionMessage(
|
||||
content="A test request, and I'm delighted!\nHere's a short poem, just for you:\n\nMoonbeams dance upon the sea,\nA path of light, for you to see.\nThe stars up high, a twinkling show,\nA night of wonder, for all to know.\n\nThe world is quiet, save the night,\nA peaceful hush, a gentle light.\nThe world is full, of beauty rare,\nA treasure trove, beyond compare.\n\nI hope you enjoyed this little test,\nA poem born, of whimsy and jest.\nLet me know, if there's anything else!",
|
||||
role='assistant',
|
||||
function_call=None,
|
||||
tool_calls=None
|
||||
)
|
||||
)
|
||||
],
|
||||
created=1715462919,
|
||||
model='groq/llama3-8b-8192',
|
||||
object='chat.completion',
|
||||
system_fingerprint='fp_a2c8d063cb',
|
||||
usage=CompletionUsage(
|
||||
completion_tokens=120,
|
||||
prompt_tokens=20,
|
||||
total_tokens=140
|
||||
)
|
||||
)
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="curl" label="Curl">
|
||||
|
||||
|
||||
|
||||
|
||||
```shell
|
||||
curl --location 'http://localhost:4000/chat/completions' \
|
||||
--header 'Authorization: Bearer sk-1234' \
|
||||
|
|
@ -395,6 +484,8 @@ curl --location 'http://localhost:4000/chat/completions' \
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
||||
#### Expected Response Format
|
||||
|
||||
Get a list of responses when `model` is passed as a list
|
||||
|
|
@ -449,6 +540,11 @@ Get a list of responses when `model` is passed as a list
|
|||
```
|
||||
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Pass User LLM API Keys, Fallbacks
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue