Skip to content

Fix/llxprt tool calls and sse streaming#66

Open
marmarjohnson wants to merge 4 commits intoAmm1rr:masterfrom
marmarjohnson:fix/llxprt-tool-calls-and-sse-streaming
Open

Fix/llxprt tool calls and sse streaming#66
marmarjohnson wants to merge 4 commits intoAmm1rr:masterfrom
marmarjohnson:fix/llxprt-tool-calls-and-sse-streaming

Conversation

@marmarjohnson
Copy link
Copy Markdown

Tool calls weren't working for me for either endpoint. Note, I also have a commit to the script update.sh that updates and starts the job in the background if its not already running (running on Ubuntu 24.04)

marmarjohnson and others added 4 commits March 14, 2026 15:13
Fixes two issues preventing llxprt from working correctly with
WebAI-to-API via its gemini and openai provider profiles.

## Fix 1: Gemini provider — "Incomplete JSON segment" error (test.json)

The @google/genai SDK always calls streamGenerateContent and expects
SSE format (text/event-stream with `data: {...}` lines). The endpoint
was returning plain JSON, causing the SDK to fail parsing.

Changes in google_generative.py:
- Route changed from `/v1beta/models/{model}` to
  `/v1beta/models/{model_path:path}` to correctly capture the
  `:streamGenerateContent` action suffix in the URL
- Detects the action (generateContent vs streamGenerateContent) and
  returns a StreamingResponse with text/event-stream content type
- Accepts tools (functionDeclarations), systemInstruction, and
  generationConfig fields that were previously causing 422 errors
- Injects tool definitions as a system prompt and parses functionCall
  JSON from the response, returning it in Gemini native part format

## Fix 2: OpenAI provider — tool calls not recognized (webai.json)

The tools field in OpenAI chat completion requests was silently
ignored and responses never contained tool_calls.

Changes in chat.py:
- OpenAIChatRequest now accepts tools and tool_choice fields
- Tool definitions are injected as a system prompt instructing Gemini
  to respond as {"tool_call": {"name": ..., "arguments": {...}}}
- Handles role:tool messages (tool results) and assistant messages
  with tool_calls in conversation history
- Parses Gemini response text for tool call JSON and returns proper
  OpenAI tool_calls format with finish_reason: "tool_calls"

## Fix 3: Schema — Part model made flexible (request.py)

Part.text was required (str), causing 422 errors for Gemini SDK
requests that include functionCall or functionResponse parts.
Made text optional and added functionCall and functionResponse fields.
Also added Tool and FunctionDeclaration models to support the
tools field in GoogleGenerativeRequest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Regex patterns with [^{}]* failed when tool arguments contained nested
objects (e.g. {"dir_path": "..."}). Replace with json.JSONDecoder.raw_decode
which scans for { and handles arbitrary nesting depth. Also relax model
fields from GeminiModels enum to str to allow any model name.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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