Respect ChatOptions.Instructions in HuggingFaceClient.GetResponseAsync
Summary by CodeRabbit
-
New Features
- Support for system-level instructions in chat: when provided, instructions are injected as a system message to guide assistant behavior.
- Improved response consistency and controllability by honoring optional instruction text in the prompt.
- Backward compatible: existing chats behave the same when no instructions are supplied.
Walkthrough
Adds conditional insertion of a System role message containing instructions into the chat prompt construction in HuggingFaceApi.ChatClient when options.Instructions is provided. The System segment is appended before the Assistant segment. No public signatures or error handling paths changed.
Changes
| Cohort / File(s) | Summary |
|---|---|
Prompt construction updatesrc/libs/HuggingFace/Extensions/HuggingFaceApi.ChatClient.cs |
Insert System role message from options.Instructions into prompt assembly before Assistant segment; request payload reflects new message order. No API surface changes. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant ChatClient
participant PromptBuilder
participant HF_API as HuggingFace API
Caller->>ChatClient: CreateChatAsync(options)
ChatClient->>PromptBuilder: Build messages
alt options.Instructions present
Note right of PromptBuilder: Append System message with instructions
PromptBuilder-->>ChatClient: [System, (User/History...), Assistant]
else No instructions
PromptBuilder-->>ChatClient: [(User/History...), Assistant]
end
ChatClient->>HF_API: POST /chat/completions with messages
HF_API-->>ChatClient: Response
ChatClient-->>Caller: Chat result
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
I thump my paws—new System note in tow,
A whisper up front, before replies flow.
Prompts line up neat, like carrots in rows,
Guidance first, then the answer grows.
Nose twitch—payload ships, off we go!
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | The title accurately and concisely summarizes the primary change: GetResponseAsync now respects ChatOptions.Instructions by including instruction text in the chat prompt. It directly matches the diff which conditionally inserts a System-role segment when options.Instructions is provided. The title is specific to the modified behavior and avoids irrelevant detail. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
[!TIP]
👮 Agentic pre-merge checks are now available in preview!
Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
- Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
- Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.
Please see the documentation for more information.
Example:
reviews: pre_merge_checks: custom_checks: - name: "Undocumented Breaking Changes" mode: "warning" instructions: | Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.