Skip to content

feat: Allow FIM chat requests without messages - #1959

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
RedwindA:feat/silicon-fim
Oct 3, 2025
Merged

feat: Allow FIM chat requests without messages#1959
seefs001 merged 1 commit into
QuantumNous:mainfrom
RedwindA:feat/silicon-fim

Conversation

@RedwindA

@RedwindA RedwindA commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

PR 类型

  • Bug 修复
  • 新功能
  • 文档更新
  • 其他

PR 是否包含破坏性更新?

PR 描述

close #1649

为兼容prefix/subfix形式的 FIM 调用,当客户端未提供 messages 时,不再在入参校验阶段直接拒绝请求,同时在 SiliconFlow 适配器内补充一个空的 user 消息以满足上游服务的必填要求,从而避免这类请求被误判为无效。

Summary by CodeRabbit

  • New Features

    • Added support for fill‑in‑the‑middle (FIM) prompts using Prefix/Suffix without requiring chat messages in chat completions.
  • Bug Fixes

    • Reduced validation errors when submitting FIM requests without messages.
    • Improved compatibility with SiliconFlow by automatically adjusting requests to meet provider requirements, leading to fewer failed requests.

@coderabbitai

coderabbitai Bot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Updates enable Fill-in-the-Middle requests without explicit messages: validation now permits missing messages when Prefix/Suffix exist, and the SiliconFlow adaptor injects an empty user message if needed to meet provider requirements.

Changes

Cohort / File(s) Summary
Validation logic for chat completions
relay/helper/valid_request.go
Relaxed message presence check: messages are only required when both Prefix and Suffix are absent. Added comments explaining FIM allowance.
SiliconFlow adaptor FIM handling
relay/channel/siliconflow/adaptor.go
ConvertOpenAIRequest mutates requests: when Prefix/Suffix exist and Messages are empty, injects a single empty user message to satisfy SiliconFlow requirements.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Relay
  participant Validator as GetAndValidateTextRequest
  participant Adaptor as SiliconFlow Adaptor
  participant Provider as SiliconFlow API

  Client->>Relay: ChatCompletions request (Prefix/Suffix, no Messages)
  Relay->>Validator: Validate request
  alt Prefix/Suffix present
    Validator-->>Relay: OK (messages optional)
  else No Prefix/Suffix
    Validator-->>Relay: Error (messages required)
  end

  Relay->>Adaptor: ConvertOpenAIRequest
  alt Messages empty AND Prefix/Suffix present
    Adaptor->>Adaptor: Inject empty user message
  end
  Adaptor-->>Relay: Modified request
  Relay->>Provider: Send request
  Provider-->>Relay: Response
  Relay-->>Client: Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A whisk of code, a hop, a cheer—
FIM can flow, the path is clear.
No messages? I’ll drop one in,
An empty nib for text to spin.
Thump-thump—relay hums along,
Silicon streams a tidy song. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary change of allowing fill-in-the-middle chat requests to proceed without a messages array, which aligns directly with the modifications to validation logic and adapter behavior in the PR.
Linked Issues Check ✅ Passed The PR relaxes the validation in GetAndValidateTextRequest to permit requests missing messages when a prefix or suffix is present and updates the SiliconFlow adapter to inject an empty user message, directly resolving the “field messages is required” error described in issue #1649.
Out of Scope Changes Check ✅ Passed All code modifications are confined to input validation and the SiliconFlow adapter to support FIM-style requests without messages, and there are no unrelated or extraneous changes in this PR.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66d0764 and 69e1542.

📒 Files selected for processing (2)
  • relay/channel/siliconflow/adaptor.go (1 hunks)
  • relay/helper/valid_request.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
relay/channel/siliconflow/adaptor.go (1)
dto/openai_request.go (1)
  • Message (271-282)
🔇 Additional comments (3)
relay/helper/valid_request.go (2)

280-282: Validation logic correctly implements FIM support.

The conditional logic properly allows messages to be optional when either Prefix or Suffix is present, aligning with the SiliconFlow adapter's behavior and the PR objectives.


278-279: Verify FIM behavior for non-SiliconFlow providers. Only SiliconFlow’s adaptor (relay/channel/siliconflow/adaptor.go) injects a dummy message when Prefix/Suffix is set; DeepSeek and all other adaptors simply return the request unchanged. Confirm that each vendor’s model accepts empty messages with Prefix/Suffix or add fallback injection logic as needed.

relay/channel/siliconflow/adaptor.go (1)

64-73: Confirm SiliconFlow accepts empty user messages. Check the official SiliconFlow API docs or integration tests to ensure injecting an empty Content string is permitted and won’t cause downstream errors.


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.

@seefs001
seefs001 merged commit 5c6e603 into QuantumNous:main Oct 3, 2025
1 check passed
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
feat: Allow FIM chat requests without messages
@RedwindA
RedwindA deleted the feat/silicon-fim branch July 23, 2026 07:04
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.

使用FIM模型时报错field messages is required

2 participants