Skip to content

Conversation

@krrishdholakia
Copy link
Contributor

@krrishdholakia krrishdholakia commented Apr 3, 2025

Title

Allows developer to call multiple providers with unified file id

import base64
import requests
from openai import OpenAI

client = OpenAI(base_url="http://0.0.0.0:4000", api_key="sk-LITELLM-KEY")


# Download and save the PDF locally
url = (
    "https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/2403.05530.pdf"
)
response = requests.get(url)
response.raise_for_status()

# Save the PDF locally
with open("2403.05530.pdf", "wb") as f:
    f.write(response.content)

# Read the local PDF file
file = client.files.create(
    file=open("2403.05530.pdf", "rb"),
    purpose="assistants", # can be any openai 'purpose' value
    extra_body={"target_model_names": "gpt-4o, gemini-2.0-flash-001"},
)

## file.id = 'litellm_proxy/99aa9360-4961-4052-a437-b39ebf65f666" 👈 Unified file id 

completion = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What is in this recording?"},
                {
                    "type": "file",
                    "file": {
                        "file_id": file.id,
                    },
                },
            ],
        },
    ],
)

print(completion.choices[0].message)

Relevant issues

Relevant discussion - #9632

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on (make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

  • feat(files_endpoints.py): initial commit adding 'target_model_names' support

allow developer to specify all the models they want to call with the file

  • feat(files_endpoints.py): return unified files endpoint

  • test(test_files_endpoints.py): add validation test - if invalid purpose submitted

  • feat: more updates

  • feat: initial working commit of unified file id translation

  • fix: additional fixes

  • fix(router.py): remove model replace logic in jsonl on acreate_file

enables file upload to work for chat completion requests as well

  • fix(files_endpoints.py): remove whitespace around model name

  • fix(azure/handler.py): return acreate_file with correct response type

@vercel
Copy link

vercel bot commented Apr 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2025 2:40am

fails on ci/cd - not clear why
@krrishdholakia krrishdholakia changed the title (v0) Unified files api - allow specifying target model names when uploading a file (v0) Unified files id - allow calling multiple providers with same file id Apr 3, 2025
@krrishdholakia krrishdholakia changed the title (v0) Unified files id - allow calling multiple providers with same file id (v0) Unified file id - allow calling multiple providers with same file id Apr 3, 2025
@krrishdholakia krrishdholakia changed the base branch from main to litellm_staging_04_02_2025 April 3, 2025 05:36
@krrishdholakia krrishdholakia merged commit eb75dac into litellm_staging_04_02_2025 Apr 3, 2025
36 of 45 checks passed
@krrishdholakia krrishdholakia deleted the litellm_unified_files_api branch April 3, 2025 05:36
krrishdholakia added a commit that referenced this pull request Apr 3, 2025
* Add date picker to usage tab + Add reasoning_content token tracking across all providers on streaming (#9722)

* feat(new_usage.tsx): add date picker for new usage tab

allow user to look back on their usage data

* feat(anthropic/chat/transformation.py): report reasoning tokens in completion token details

allows usage tracking on how many reasoning tokens are actually being used

* feat(streaming_chunk_builder.py): return reasoning_tokens in anthropic/openai streaming response

allows tracking reasoning_token usage across providers

* Fix update team metadata + fix bulk adding models on Ui  (#9721)

* fix(handle_add_model_submit.tsx): fix bulk adding models

* fix(team_info.tsx): fix team metadata update

Fixes #9689

* (v0) Unified file id - allow calling multiple providers with same file id (#9718)

* feat(files_endpoints.py): initial commit adding 'target_model_names' support

allow developer to specify all the models they want to call with the file

* feat(files_endpoints.py): return unified files endpoint

* test(test_files_endpoints.py): add validation test - if invalid purpose submitted

* feat: more updates

* feat: initial working commit of unified file id translation

* fix: additional fixes

* fix(router.py): remove model replace logic in jsonl on acreate_file

enables file upload to work for chat completion requests as well

* fix(files_endpoints.py): remove whitespace around model name

* fix(azure/handler.py): return acreate_file with correct response type

* fix: fix linting errors

* test: fix mock test to run on github actions

* fix: fix ruff errors

* fix: fix file too large error

* fix(utils.py): remove redundant var

* test: modify test to work on github actions

* test: update tests

* test: more debug logs to understand ci/cd issue

* test: fix test for respx

* test: skip mock respx test

fails on ci/cd - not clear why

* fix: fix ruff check

* fix: fix test

* fix(model_connection_test.tsx): fix linting error

* test: update unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants