Update OpenAI to >=1.76.2,<1.99 to fix ImportError in chat completion #2758
+6
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please describe the purpose of this pull request.
This PR fixes a bug: an
ImportError: cannot import name 'Function' from 'openai.types.chat.chat_completion_message_tool_call'
encountered when usingopenai = "^1.60.0"
. The issue was resolved by updating the OpenAI dependency to >=1.76.2,<1.99 in pyproject.toml and regenerating poetry.lock.How to test
To test this PR during review: Clone the repository and checkout this branch.
Ensure Poetry is installed and set up the virtual environment:
poetry install
Set the OPENAI_API_KEY environment variable:
export OPENAI_API_KEY="your_openai_api_key" # On Windows: $env:OPENAI_API_KEY="your_openai_api_key"
Start the Letta server:
poetry run letta server
Expected Outcome: The server starts at http://localhost:8283 without the ImportError. Logs should show sqlite-vec extension successfully loaded and no OpenAI-related errors.
Connect to the ADE and interact with an agent (e.g., create or send a chat message).
Expected Outcome: Agent interactions work without OpenAI errors.
Have you tested this PR?
Yes, I tested the latest commit on this PR on Windows 10 with the SQLite backend. Below are the test outputs: Ran poetry run letta server:
Outcome: Server started successfully, sqlite-vec loaded, and no OpenAI ImportError occurred.
Tested with ADE: Connected to the local server and performed basic agent interactions (e.g., chat). No OpenAI-related errors were observed.
Related issues or PRs
Searched open issues in letta-ai/letta for ImportError: cannot import name 'Function' from 'openai.types.chat.chat_completion_message_tool_call'. No matching issues found among the 21 open issues. Closest issues include:#2605: Mentions agent crashes with tool calls, potentially related to OpenAI SDK changes but not specific to this ImportError.
#2714: References OpenAI Chat Completion compatibility but doesn’t mention this error.
Is your PR over 500 lines of code?
No, this PR is minimal, modifying only pyproject.toml (1 line, changing openai version) and poetry.lock (dependency updates). The changes are focused and don’t require splitting.
Additional context
Not required for now.