Add OpenAI-compliant server-side tool calling support (#293) #888
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.
Summary
This PR implements complete OpenAI-compliant server-side tool calling for EXO, addressing Issue #293 ($300 bounty).
Key Features:
tool_callsarrayfinish_reason="tool_calls"when tools are invokedcall_<random>)Changes
Core Implementation (
exo/api/chatgpt_api.py)Added
parse_tool_calls()function<tool_call>...</tool_call>XML tags from model outputModified
generate_completion()functiontoolsprovided in requesttool_callsarrayfinish_reasonto"tool_calls"appropriatelyExample Code (
examples/function_calling_openai_compliant.py)Tests (
test_parse_simple.py)parse_tool_calls()functionOpenAI Format Compliance
Response format matches OpenAI spec exactly:
{ "id": "chatcmpl-xxx", "object": "chat.completion", "model": "model-name", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "text before tool calls", "tool_calls": [{ "id": "call_abc123xyz", "type": "function", "function": { "name": "function_name", "arguments": "{\"param\": \"value\"}" } }] }, "finish_reason": "tool_calls" }] }Testing
Unit Tests:
Integration Testing:
The implementation can be tested with any EXO deployment:
Implementation Approach
This PR takes a focused, minimal approach compared to the stalled PR #771 (59 commits, 35 files changed):
examples/function_calling.pyWhy This Solution
Closes
Fixes #293
Checklist
Ready for review and merge! This implementation is production-ready and fully OpenAI-compatible.