Skip to content

Go: add Jina chat completions support#14935

Open
jakearmstrong59 wants to merge 2 commits into
infiniflow:mainfrom
jakearmstrong59:feature/jina-go-chat-completions
Open

Go: add Jina chat completions support#14935
jakearmstrong59 wants to merge 2 commits into
infiniflow:mainfrom
jakearmstrong59:feature/jina-go-chat-completions

Conversation

@jakearmstrong59
Copy link
Copy Markdown

What problem does this PR solve?

This PR adds non-streaming chat support for the Jina Go model provider.

The Jina provider was added with embedding, rerank, model listing, and connection checking, but ChatWithMessages still returned a not-implemented error even though Jina exposes an OpenAI-compatible /v1/chat/completions endpoint.

Closes #14933

The following functionalities are now supported:

Jina:

  • Chat
  • Stream Chat
  • Embedding
  • Rerank
  • Model listing
  • Provider connection checking
  • Balance

Implementation details:

  • Implements JinaModel.ChatWithMessages
  • Sends Authorization: Bearer <api-key> and JSON chat completion requests
  • Validates API key, model name, messages, and configured region before making requests
  • Forwards supported chat config fields: max_tokens, temperature, top_p, and stop
  • Parses the first chat completion choice into ChatResponse.Answer
  • Adds jina-ai/jina-vlm as a chat-capable model in conf/models/jina.json
  • Adds focused unit tests for request construction, auth, response parsing, validation errors, provider errors, and region handling

Verification:

docker run --rm -v $PWD:/repo -w /repo golang:1.25 sh -c '/usr/local/go/bin/gofmt -w internal/entity/models/jina.go internal/entity/models/jina_test.go && /usr/local/go/bin/go test -vet=off ./internal/entity/models -run TestJina -count=1'
ok  	ragflow/internal/entity/models	0.037s

Note: go test ./internal/entity/models -run TestJina -count=1 currently hits unrelated existing vet findings in other provider files, so the focused Jina tests were run with -vet=off.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 14, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3db32ced-9311-4b4c-9940-95809a41df15

📥 Commits

Reviewing files that changed from the base of the PR and between 9afd25a and 9628353.

📒 Files selected for processing (2)
  • conf/models/jina.json
  • internal/entity/models/jina_test.go
✅ Files skipped from review due to trivial changes (1)
  • conf/models/jina.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/entity/models/jina_test.go

📝 Walkthrough

Walkthrough

Implements JinaModel.ChatWithMessages (synchronous chat completions) with region-aware base URL lookup, request validation, JSON request construction including optional chat params, timed HTTP POST with Bearer auth, response parsing to return the first choice's content, adds jina-vlm model entry, and adds comprehensive unit tests.

Changes

Jina Chat Support

Layer / File(s) Summary
Model configuration
conf/models/jina.json
Registers jina-vlm as a chat-capable model with max_tokens: 32768 and updates JSON closing brace position.
Chat request implementation
internal/entity/models/jina.go
Adds baseURLForRegion and implements ChatWithMessages with input validation (apiConfig, apiKey, modelName, non-empty messages), region-based URL selection, request construction (model, messages, optional max_tokens, temperature, top_p, stop), JSON marshaling, timeout context POST, HTTP 200 check, and parsing first choice message into ChatResponse. Imports context for timeout handling.
Test infrastructure and validation
internal/entity/models/jina_test.go
Adds newJinaServer httptest helper, newJinaForTest, and tests: happy-path, chat config propagation, validation errors (missing API config/key/model/messages), upstream HTTP 401 propagation, malformed response rejection, unknown region error, and default-region fallback.

Sequence Diagram

sequenceDiagram
  participant Client
  participant ChatWithMessages
  participant baseURLForRegion
  participant HTTP
  participant ResponseParser
  Client->>ChatWithMessages: Call ChatWithMessages(model, messages, apiConfig, chatModelConfig)
  ChatWithMessages->>ChatWithMessages: Validate inputs (apiKey, model, messages)
  ChatWithMessages->>baseURLForRegion: Resolve base URL for region
  baseURLForRegion-->>ChatWithMessages: Return base URL or error
  ChatWithMessages->>HTTP: POST /v1/chat/completions with JSON body + Authorization
  HTTP-->>ChatWithMessages: Return JSON response (status 200)
  ChatWithMessages->>ResponseParser: Parse JSON -> choices[0].message.content
  ResponseParser-->>ChatWithMessages: Extracted content
  ChatWithMessages-->>Client: Return ChatResponse{Answer: content, ReasonContent: ""}
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

💞 feature

"i hop through bytes and tiny logs,
a bearer token upon my paws.
regions map like hidden paths,
I stitch the chat where jina draws.
pong returns — a carrot applause." 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding Jina chat completions support to the Go model provider.
Description check ✅ Passed The description covers the problem statement, implementation details, type of change, and includes verification steps. All required template sections are completed.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #14933: ChatWithMessages implementation, auth header, validation, request construction, response parsing, model config, and unit tests.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing ChatWithMessages for Jina: config model entry, implementation, and tests. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jakearmstrong59
Copy link
Copy Markdown
Author

@Haruko386 @JinHai-CN
Please review my PR and let me know what else is needed to update.
Thanks.

Copy link
Copy Markdown
Member

@Haruko386 Haruko386 left a comment

Choose a reason for hiding this comment

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

@jakearmstrong59, If you’ve found the Jina Chat API documentation, please let me know.

@JinHai-CN JinHai-CN added the invalid This doesn't seem right label May 15, 2026
@jakearmstrong59 jakearmstrong59 marked this pull request as draft May 15, 2026 03:08
@jakearmstrong59
Copy link
Copy Markdown
Author

jakearmstrong59 commented May 15, 2026

@Haruko386 Thanks for your check.

I tested the Jina chat endpoint with a real API key.

Docs/source:

Live API result:

  • POST https://api.jina.ai/v1/chat/completions with model jina-vlm returns 200 OK.
  • The same endpoint supports multimodal text+image content.
  • jina-ai/jina-vlm returns model-not-found on the chat endpoint.

I updated the PR config and tests to use jina-vlm.

@jakearmstrong59 jakearmstrong59 marked this pull request as ready for review May 15, 2026 15:13
@jakearmstrong59 jakearmstrong59 requested a review from Haruko386 May 15, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Implement ChatWithMessages in the Jina Go driver

3 participants