-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add ZhiPu AI support with CustomOpenAIClient improvements #1548
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
base: main
Are you sure you want to change the base?
Conversation
- Change CustomOpenAIClient response format from json_schema to json_object for broader compatibility with models like ZhiPu - Add prompt-based JSON schema instructions for models without native structured output support - Export CustomOpenAIClient from public types for easier developer access Co-Authored-By: Claude Haiku 4.5 <[email protected]>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 2 files
Greptile SummaryThis PR enhances ZhiPu AI support by switching
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Application
participant Client as CustomOpenAIClient
participant OpenAI as OpenAI API<br/>(ZhiPu/Ollama)
participant Validate as Validator
App->>Client: createChatCompletion(options)
activate Client
alt response_model provided
Note over Client: Format schema as JSON<br/>Add to messages
end
Client->>OpenAI: POST chat/completions<br/>response_format: json_object
activate OpenAI
OpenAI-->>Client: Response with content
deactivate OpenAI
alt response_model provided
Client->>Client: JSON.parse(content)
alt Parse OK
Client->>Validate: validateZodSchema(data)
activate Validate
alt Valid
Validate-->>Client: Success
Client-->>App: Return { data, usage }
else Invalid
Validate-->>Client: ZodSchemaValidationError
deactivate Validate
alt retries > 0
Note over Client: Retry (retries-1)
Client->>OpenAI: Retry call
else retries exhausted
Note over Client: Wrap error +<br/>detailed logging
Client-->>App: CreateChatCompletionResponseError
end
end
else Parse fails (SyntaxError)
alt retries > 0
Note over Client: Retry (retries-1)
Client->>OpenAI: Retry call
else retries exhausted
Note over Client: Error: Failed to parse JSON
Client-->>App: CreateChatCompletionResponseError
end
end
else No response_model
Client-->>App: Return { data: content, usage }
end
deactivate Client
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (2)
-
packages/core/examples/external_clients/customOpenAI.ts, line 27-34 (link)style: CustomOpenAIClient defines its own validateZodSchema function, but the codebase already exports a centralized validateZodSchema utility from
packages/core/lib/utils.tsthat throws detailed ZodSchemaValidationError. Consider using the shared utility for consistency and better error reporting, which would give clearer validation failure messages to users. -
packages/core/examples/external_clients/customOpenAI.ts, line 225-235 (link)logic: The local validateZodSchema silently returns false on validation failure, losing detailed error information. When validation fails, users get a generic "Invalid response schema" error instead of specific field-level validation details. This differs significantly from OpenAIClient's approach using the shared validateZodSchema which throws ZodSchemaValidationError with detailed error information.
2 files reviewed, 2 comments
Use shared validateZodSchema utility instead of local implementation to provide field-level validation errors consistent with OpenAIClient. Co-Authored-By: Claude Opus 4.5 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 1 comment
87e2d27 to
f58ec4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 1 comment
Move JSON.parse() inside try-catch to retry on invalid JSON responses. ZhiPu and other providers using json_object mode may return malformed JSON. Co-Authored-By: Claude Opus 4.5 <[email protected]>
f58ec4b to
e2d07a8
Compare
|
I am looking forward to this feature in china |
Summary
Testing
Verified with ZhiPu glm-4.6v model using Browserbase integration with successful extract, act, and observe operations.
Summary by cubic
Added support for ZhiPu models by switching CustomOpenAIClient to json_object responses and adding a schema-instruction prompt for structured JSON. Also exported CustomOpenAIClient from public types for easier use.
Written for commit e2d07a8. Summary will update on new commits.