mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
Add xAI and fix some old model config (#8218)
Signed-off-by: Zhaohan Dong <65422392+zhaohan-dong@users.noreply.github.com>
This commit is contained in:
parent
ec614be6c4
commit
d60d3ee970
4 changed files with 66 additions and 5 deletions
|
|
@ -89,6 +89,7 @@ response_format: { "type": "json_schema", "json_schema": … , "strict": true }
|
|||
Works for:
|
||||
- OpenAI models
|
||||
- Azure OpenAI models
|
||||
- xAI models (Grok-2 or later)
|
||||
- Google AI Studio - Gemini models
|
||||
- Vertex AI models (Gemini + Anthropic)
|
||||
- Bedrock Models
|
||||
|
|
|
|||
|
|
@ -118,9 +118,11 @@ response = client.chat.completions.create(
|
|||
Use `litellm.supports_vision(model="")` -> returns `True` if model supports `vision` and `False` if not
|
||||
|
||||
```python
|
||||
assert litellm.supports_vision(model="gpt-4-vision-preview") == True
|
||||
assert litellm.supports_vision(model="gemini-1.0-pro-vision") == True
|
||||
assert litellm.supports_vision(model="gpt-3.5-turbo") == False
|
||||
assert litellm.supports_vision(model="openai/gpt-4-vision-preview") == True
|
||||
assert litellm.supports_vision(model="vertex_ai/gemini-1.0-pro-vision") == True
|
||||
assert litellm.supports_vision(model="openai/gpt-3.5-turbo") == False
|
||||
assert litellm.supports_vision(model="xai/grok-2-vision-latest") == True
|
||||
assert litellm.supports_vision(model="xai/grok-2-latest") == False
|
||||
```
|
||||
</TabItem>
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,21 @@ response = completion(
|
|||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="xai" label="xAI">
|
||||
|
||||
```python
|
||||
from litellm import completion
|
||||
import os
|
||||
|
||||
## set ENV variables
|
||||
os.environ["XAI_API_KEY"] = "your-api-key"
|
||||
|
||||
response = completion(
|
||||
model="xai/grok-2-latest",
|
||||
messages=[{ "content": "Hello, how are you?","role": "user"}]
|
||||
)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="vertex" label="VertexAI">
|
||||
|
||||
```python
|
||||
|
|
@ -272,7 +286,22 @@ response = completion(
|
|||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="xai" label="xAI">
|
||||
|
||||
```python
|
||||
from litellm import completion
|
||||
import os
|
||||
|
||||
## set ENV variables
|
||||
os.environ["XAI_API_KEY"] = "your-api-key"
|
||||
|
||||
response = completion(
|
||||
model="xai/grok-2-latest",
|
||||
messages=[{ "content": "Hello, how are you?","role": "user"}],
|
||||
stream=True,
|
||||
)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="vertex" label="VertexAI">
|
||||
|
||||
```python
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import os
|
|||
|
||||
os.environ['XAI_API_KEY'] = ""
|
||||
response = completion(
|
||||
model="xai/grok-beta",
|
||||
model="xai/grok-2-latest",
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
|
|
@ -51,7 +51,7 @@ import os
|
|||
|
||||
os.environ['XAI_API_KEY'] = ""
|
||||
response = completion(
|
||||
model="xai/grok-beta",
|
||||
model="xai/grok-2-latest",
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
|
|
@ -74,6 +74,35 @@ for chunk in response:
|
|||
print(chunk)
|
||||
```
|
||||
|
||||
## Sample Usage - Vision
|
||||
```python
|
||||
import os
|
||||
from litellm import completion
|
||||
|
||||
os.environ["XAI_API_KEY"] = "your-api-key"
|
||||
|
||||
response = completion(
|
||||
model="xai/grok-2-latest",
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": "https://science.nasa.gov/wp-content/uploads/2023/09/web-first-images-release.png",
|
||||
"detail": "high",
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": "What's in this image?",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
```
|
||||
|
||||
## Usage with LiteLLM Proxy Server
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue