Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/openai modify assistant #7574

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jeansouzak
Copy link
Contributor

Title

Implement OpenAI Modify Assistant Endpoint
https://platform.openai.com/docs/api-reference/assistants/modifyAssistant

Relevant issues

Solve part of I wish litellm HAD comment

Type

🆕 New Feature
📖 Documentation
✅ Test

Changes

  • Added support for the Modify Assistant endpoint (OpenAI).
  • Updated Assistants API documentation to include modify examples (SDK + cURL).
  • Implemented local Python tests to validate the assistant modification process.

[REQUIRED] Testing - Attach a screenshot of any new tests passing locally

Local test script:

pytest tests/local_testing/test_assistants.py::test_modify_assistant -v

PASSED tests/local_testing/test_assistants.py::test_modify_assistant[False-openai]
PASSED tests/local_testing/test_assistants.py::test_modify_assistant[True-openai]

External api test:

Code:

import requests

def modify_assistant(assistant_id, name=None, instructions=None, tools=None):
    url = f"http://0.0.0.0:4000/v1/assistants/{assistant_id}"
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer jean@123" 
    }
    
    # Add only non-None parameters to the request body
    payload = {
        "name": name,
        "instructions": instructions,
        "tools": tools,
    }
    payload = {k: v for k, v in payload.items() if v is not None}  # Remove None values
    
    print(f"Sending PATCH request with payload: {payload}")
    
    try:
        response = requests.patch(url, headers=headers, json=payload)
        response.raise_for_status()  # Raise an exception for HTTP errors
        data = response.json()
        
        print("Response:", data)
        if "name" in data:
            print(f"Updated assistant name: {data.get('name')}")
        if "instructions" in data:
            print(f"Updated instructions: {data.get('instructions')}")
    
    except requests.exceptions.RequestException as e:
        print("Error while making the request:", e)


if __name__ == "__main__":
    assistant_payloads = [
        {
            "assistant_id": "asst_S4IW1JplxrRtsb5sQOXmztf4",
            "name": "Updated Assistant Name",
            "instructions": "You are an updated Python expert.",
            "tools": [{"type": "code_interpreter"}],
        },
        {
            "assistant_id": "asst_p3cGPCy5zU2AkJdzvkgboirU",
            "name": "Modified SQL Tutor",
            "instructions": "Provide expert advice on SQL queries.",
        },
        {
            "assistant_id": "asst_i3deNsX4WgK0UNRcwpvtwPAO",
            "name": "Game Code Assistant",
            "tools": [{"type": "code_interpreter"}],
        },
    ]

    for case in assistant_payloads:
        modify_assistant(**case)
        print("-" * 50)

Result:

myenv) jeansouza@Jeans-Laptop test-litellm % python3 curl-modify-assistant-api.py
Sending PATCH request with payload: {'name': 'Updated Assistant Name', 'instructions': 'You are an updated Python expert.', 'tools': [{'type': 'code_interpreter'}]}
Response: {'id': 'asst_S4IW1JplxrRtsb5sQOXmztf4', 'created_at': 1736063507, 'description': None, 'instructions': 'You are an updated Python expert.', 'metadata': {}, 'model': 'gpt-4-turbo', 'name': 'Updated Assistant Name', 'object': 'assistant', 'tools': [{'type': 'code_interpreter'}], 'response_format': 'auto', 'temperature': 1.0, 'tool_resources': {'code_interpreter': {'file_ids': []}, 'file_search': None}, 'top_p': 1.0}
Updated assistant name: Updated Assistant Name
Updated instructions: You are an updated Python expert.
--------------------------------------------------
Sending PATCH request with payload: {'name': 'Modified SQL Tutor', 'instructions': 'Provide expert advice on SQL queries.'}
Response: {'id': 'asst_p3cGPCy5zU2AkJdzvkgboirU', 'created_at': 1736063412, 'description': None, 'instructions': 'Provide expert advice on SQL queries.', 'metadata': {}, 'model': 'gpt-4-turbo', 'name': 'Modified SQL Tutor', 'object': 'assistant', 'tools': [{'type': 'code_interpreter'}], 'response_format': 'auto', 'temperature': 1.0, 'tool_resources': {'code_interpreter': {'file_ids': []}, 'file_search': None}, 'top_p': 1.0}
Updated assistant name: Modified SQL Tutor
Updated instructions: Provide expert advice on SQL queries.
--------------------------------------------------
Sending PATCH request with payload: {'name': 'Game Code Assistant', 'tools': [{'type': 'code_interpreter'}]}
Response: {'id': 'asst_i3deNsX4WgK0UNRcwpvtwPAO', 'created_at': 1736063412, 'description': None, 'instructions': 'You are a coding assistant.', 'metadata': {}, 'model': 'gpt-4-turbo', 'name': 'Game Code Assistant', 'object': 'assistant', 'tools': [{'type': 'code_interpreter'}], 'response_format': 'auto', 'temperature': 1.0, 'tool_resources': {'code_interpreter': {'file_ids': []}, 'file_search': None}, 'top_p': 1.0}
Updated assistant name: Game Code Assistant
Updated instructions: You are a coding assistant.
--------------------------------------------------

…tants via PATCH request

- Implemented `modify_assistant` function to update assistant details such as name, instructions, and tools.
- Added `local_tests` to verify the modification functionality.
Copy link

vercel bot commented Jan 5, 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 Jan 5, 2025 6:49pm

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.

1 participant