forked from phoenix/litellm-mirror
(docs) using gemini vision with base64
This commit is contained in:
parent
8d76df6a5e
commit
02c3955c51
2 changed files with 46 additions and 3 deletions
|
@ -152,8 +152,14 @@ LiteLLM Supports the following image types passed in `url`
|
||||||
- Images with Cloud Storage URIs - gs://cloud-samples-data/generative-ai/image/boats.jpeg
|
- Images with Cloud Storage URIs - gs://cloud-samples-data/generative-ai/image/boats.jpeg
|
||||||
- Images with direct links - https://storage.googleapis.com/github-repo/img/gemini/intro/landmark3.jpg
|
- Images with direct links - https://storage.googleapis.com/github-repo/img/gemini/intro/landmark3.jpg
|
||||||
- Videos with Cloud Storage URIs - https://storage.googleapis.com/github-repo/img/gemini/multimodality_usecases_overview/pixel8.mp4
|
- Videos with Cloud Storage URIs - https://storage.googleapis.com/github-repo/img/gemini/multimodality_usecases_overview/pixel8.mp4
|
||||||
|
- Base64 Encoded Local Images
|
||||||
|
|
||||||
|
**Example Request - image url**
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
|
||||||
|
<TabItem value="direct" label="Images with direct links">
|
||||||
|
|
||||||
**Example Request**
|
|
||||||
```python
|
```python
|
||||||
import litellm
|
import litellm
|
||||||
|
|
||||||
|
@ -179,6 +185,43 @@ response = litellm.completion(
|
||||||
)
|
)
|
||||||
print(response)
|
print(response)
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem value="base" label="Local Base64 Images">
|
||||||
|
|
||||||
|
```python
|
||||||
|
import litellm
|
||||||
|
|
||||||
|
def encode_image(image_path):
|
||||||
|
import base64
|
||||||
|
|
||||||
|
with open(image_path, "rb") as image_file:
|
||||||
|
return base64.b64encode(image_file.read()).decode("utf-8")
|
||||||
|
|
||||||
|
image_path = "cached_logo.jpg"
|
||||||
|
# Getting the base64 string
|
||||||
|
base64_image = encode_image(image_path)
|
||||||
|
response = litellm.completion(
|
||||||
|
model="vertex_ai/gemini-pro-vision",
|
||||||
|
messages=[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": [
|
||||||
|
{"type": "text", "text": "Whats in this image?"},
|
||||||
|
{
|
||||||
|
"type": "image_url",
|
||||||
|
"image_url": {
|
||||||
|
"url": "data:image/jpeg;base64," + base64_image
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
|
print(response)
|
||||||
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
|
||||||
## Chat Models
|
## Chat Models
|
||||||
|
|
|
@ -122,8 +122,6 @@ const sidebars = {
|
||||||
"providers/openai_compatible",
|
"providers/openai_compatible",
|
||||||
"providers/azure",
|
"providers/azure",
|
||||||
"providers/azure_ai",
|
"providers/azure_ai",
|
||||||
"providers/huggingface",
|
|
||||||
"providers/ollama",
|
|
||||||
"providers/vertex",
|
"providers/vertex",
|
||||||
"providers/palm",
|
"providers/palm",
|
||||||
"providers/gemini",
|
"providers/gemini",
|
||||||
|
@ -132,6 +130,8 @@ const sidebars = {
|
||||||
"providers/aws_sagemaker",
|
"providers/aws_sagemaker",
|
||||||
"providers/bedrock",
|
"providers/bedrock",
|
||||||
"providers/anyscale",
|
"providers/anyscale",
|
||||||
|
"providers/huggingface",
|
||||||
|
"providers/ollama",
|
||||||
"providers/perplexity",
|
"providers/perplexity",
|
||||||
"providers/groq",
|
"providers/groq",
|
||||||
"providers/vllm",
|
"providers/vllm",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue