Repository navigation
Conversation
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: 1
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
src/typechat/LanguageModel.cs — When OpenAIConfig.UseResponsesApi is explicitly set to false, non-Azure configuration should ensure… |
|
src/typechat/HttpEx.cs — GetJsonResponseWithRawAsync reuses a single StringContent across retries, but… |
What changed in this PR
This PR upgrades TypeChat’s language-model abstraction to return a richer LanguageModelResponse (text + normalized completion metadata), adds normalized token/finish-reason types, updates prompts to JSON-encode user/error sections to reduce prompt-injection risk, and expands unit tests to cover the new behaviors (including OpenAI “Responses API” routing).
Changes:
- Changed
ILanguageModel.CompleteAsync(and implementations) to returnLanguageModelResponse, carryingCompletionInfo(model, finish reason, token usage, raw JSON). - Added non-throwing
JsonTranslator.TranslateToResultAsyncAPIs returningResult<T>with attached completion metadata on success. - Added HTTP helper to capture raw JSON responses and updated prompt templates to JSON-string encode untrusted request/error text.
| File | Description |
|---|---|
| tests/TypeChat.UnitTests/TestLanguageModel.cs | Adds coverage for CompletionInfo parsing and /responses endpoint routing. |
| tests/TypeChat.UnitTests/TestJsonTranslatorPrompts.cs | Verifies prompt sections JSON-encode untrusted request/error text. |
| tests/TypeChat.TestLib/Models.cs | Updates mock language model to new LanguageModelResponse return type. |
| tests/TypeChat.IntegrationTests/TestEndToEnd.cs | Adjusts assertion to handle LanguageModelResponse (string conversion). |
| src/typechat/TokenUsage.cs | Introduces normalized token usage model. |
| src/typechat/Result.cs | Adds optional CompletionInfo to successful results. |
| src/typechat/OpenAIConfig.cs | Adds UseResponsesApi selector for endpoint variant selection. |
| src/typechat/LanguageModelResponse.cs | New response wrapper with implicit conversion to/from string. |
| src/typechat/LanguageModel.cs | Adds Responses API support, endpoint inference/rewrites, and completion metadata extraction. |
| src/typechat/JsonTranslatorPrompts.cs | Switches prompt embedding to JSON-string encoding for safety/consistency. |
| src/typechat/JsonTranslator.cs | Adds non-throwing translation APIs and propagates completion info + repair attempts. |
| src/typechat/ILanguageModel.cs | Interface updated to return LanguageModelResponse. |
| src/typechat/HttpEx.cs | Adds GetJsonResponseWithRawAsync to return parsed + raw response JSON. |
| src/typechat/CompletionInfo.cs | New normalized completion metadata container (model/usage/finish/raw/repairs). |
| src/typechat/CompletionFinishReason.cs | New normalized finish reason enum. |
| src/typechat.sk/TextCompletionModel.cs | Updates SK adapter to return LanguageModelResponse. |
| src/typechat.sk/ChatLanguageModel.cs | Updates SK adapter to return LanguageModelResponse. |
| src/typechat.meai/ChatLanguageModel.cs | Updates MEAI adapter to return LanguageModelResponse with normalized metadata. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Preserve the original completion API and translator hooks while adding optional metadata and validation-result APIs. Retain failure context from main, fix endpoint and output handling, and test consumers compiled against the original contracts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
main(d0b9597), including Retain rejected output and repair failure context #338's rejected-output and repair-failure context.ILanguageModel.CompleteAsyncand all existing provider methods asTask<string>. Add opt-inILanguageModelWithMetadata.CompleteWithMetadataAsyncplus an extension method that supports existing text-only models.TranslateAsynccalls routed through the original protectedGetResponseAsynchook. The additiveTranslateToResultAsyncAPI uses a separate metadata-aware hook and retains both completion metadata and failure context.Compatibility
Existing model implementations,
Task<string>callers, and translator subclasses continue to work without recompilation. REST and Microsoft.Extensions.AI expose the optional metadata capability. Semantic Kernel and other text-only models work through the extension-method fallback with unavailable metadata left null. No shared "last completion" state is introduced.The original throwing translation API remains supported. Subclasses opting into the result-returning API can override
GetResponseWithMetadataAsync.Validation
NU1900warning for an unreachable NuGet audit feed.