Skip to content

Add initial chat completions client - #1

Open
faheemKamboh wants to merge 28 commits into
mainfrom
feature/chat-completions-client
Open

faheemKamboh wants to merge 28 commits into
mainfrom
feature/chat-completions-client

Conversation

@faheemKamboh

@faheemKamboh faheemKamboh commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds the initial ZAI::Client with chat completions support.
  • Adds response and error wrapper classes.
  • Renames the public module from generated ZAi to ZAI before the gem has public usage.
  • Replaces generated README/gemspec placeholders with usable open-source metadata and examples.
  • Expands CI to cover Ruby 3.2, 3.3, 3.4, and 4.0.5.

Scope intentionally deferred

  • Streaming responses
  • Tool/function calling helpers
  • Rails configuration helpers
  • Release automation

Notes

This is intentionally small and dependency-free. Specs use RSpec doubles for the Net::HTTP boundary instead of adding a test-only HTTP mocking dependency in the first PR.

The client targets Z.ai's documented general API endpoint and /chat/completions path.

Validation

  • GitHub Actions passes
  • Manual review of public API naming
  • Manual review of README examples

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2014bff7e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/z_ai/client.rb Outdated
request.body = JSON.generate(body)

response = perform_request(uri, request)
parsed_body = parse_response(response)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle non-JSON error responses by status

If Z.ai or an intermediary returns a non-empty HTML/text body for a 401, 429, or 5xx response, this parses the body before checking the HTTP status, and the JSON::ParserError rescue raises ZAI::ParseError instead of the intended AuthenticationError, RateLimitError, or ServerError with status/headers. That prevents callers from reliably handling retry/authentication cases unless every error response is valid JSON.

Useful? React with 👍 / 👎.

Comment thread lib/z_ai/version.rb
# frozen_string_literal: true

module ZAi
module ZAI

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the packaged RBS namespace

Renaming the runtime namespace to ZAI here leaves the packaged type signature stale: sig/z_ai.rbs still declares module ZAi and does not describe ZAI::Client or the new response/error classes. Because the gemspec still includes sig/, typed consumers of the released gem will be told the new public API does not exist while the old constant does, so the RBS should be updated or removed with this rename.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e42e2de12d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/z_ai/client.rb
def api_error_message(body)
return unless body.is_a?(Hash)

body.dig("error", "message") || body["message"] || body["msg"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle string error bodies without TypeError

If a non-2xx JSON response has a top-level error value that is not an object, such as a gateway/path 404 body like { "error": "Not Found" }, this dig call raises TypeError before api_error_class can raise APIError with the status, body, and headers. Callers then cannot handle the failure through the SDK error hierarchy even though the response was valid JSON, so guard the error value's type or handle string errors before digging.

Useful? React with 👍 / 👎.

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