-
Notifications
You must be signed in to change notification settings - Fork 32
MicrosoftExtensions: Idiomatic CacheControl Support #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PederHP
wants to merge
45
commits into
anthropics:next
Choose a base branch
from
PederHP:feature/meai-cache-control-extension
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
MicrosoftExtensions: Idiomatic CacheControl Support #73
PederHP
wants to merge
45
commits into
anthropics:next
from
PederHP:feature/meai-cache-control-extension
Conversation
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
b38ea33 to
6a6e29c
Compare
Contributor
Author
|
Let me know if you want a separate extension for beta and non-beta cache control (currently the outer one is shared). I also added a new file. I can fold it into the extensions file, but it's getting massive, so I think if it's not ok to have more than one top-level MEAI related file - then maybe there should be a folder? Otherwise the file is just going to keep growing and get more and more unwieldy. |
a6ccfa7 to
007b0c0
Compare
6a6e29c to
f88b66b
Compare
ae28dee to
edc3cfb
Compare
* Changes from PR 55 * Lint fix * fix: replace deprecated Assert.IsAssignableFrom with Assert.IsType
* fix: use Properties initializer for InputSchema in IChatClient extensions (anthropics#83) * chore(ci): Add Claude Code GitHub Workflow (#273) * "Claude PR Assistant workflow" * "Claude Code Review workflow" * fix: use Properties initializer for InputSchema in IChatClient extensions The InputSchema constructor was being passed properties as rawData, which caused them to be serialized at the top level of the JSON object instead of under a "properties" key. This resulted in invalid JSON Schema that failed Anthropic API validation with error: "tools.0.custom.input_schema: JSON schema is invalid" The fix uses property initializer syntax to correctly populate the Properties property, ensuring the schema is valid JSON Schema draft 2020-12. Also updates tests to expect the corrected schema format. Fixes anthropics#82 * Remove added workflows --------- Co-authored-by: dtmeadows <dmeadows@stainless.com> * Add MEAI User-Agent for IChatClient implementation * Fix failing UT for new schema properties pattern * Add MEAI user agent + UT for betaservice * Address PR comments * Use FrozenDictionary for MEAI headers and fix User-Agent test assertions * Add missing System.Linq using for ToArray extension method * Fix User-Agent tests to verify single header with multiple values * Fix lint issues: use collection expressions and simplify regex --------- Co-authored-by: Matt Brailsford <me@mattbrailsford.com> Co-authored-by: dtmeadows <dmeadows@stainless.com>
Co-authored-by: Claude Code (/Users/davidmeadows/stainless/stainless) <noreply@anthropic.com>
* SSE implementation * Add aws cred store * Adapt AWS authentication * Fix Streaming for bedrock * Add nuget stubs * Lint files * Update code comments * Add support for netstandard to bedrock Removed Async streaming implementation * Format code * Cleanup code * make mr linter happy * Fix net9 specific optimizations * Apply review comments * Fix linting issues * applied review comments * Remove argument check * Remove unused code * Adapt method header NetStandard switch * lint code * Fix merge conflicts from source * Apply review comments * Removed unused method * Apply code review changes * Add bedrock example * rename event stream helper * linting * remove incorrectly added example project * fix build * Fix tests * fix build and lint * apply review comments * revert merge conflict issue * lint * Split examples into multiple projects for bedrock, anthropic and foundry * apply review comments * Remove bedrock from general testing loop as currently unsupported by test tool * Update Examples * lint * Cleanup examples * update comment * update exception * Update src/Anthropic.Bedrock/LocalShims.cs * combine if statements * fix lint? --------- Co-authored-by: Stephen <stephen@stainless.com>
output_format is depracated in favour of output_config.format. Update api call configuration to reflect this change update test to reflect this change
* chore: add release notes * Implement message Aggregator * Add prism log to gitignore * Fix test script * Add streaming aggregators * Refactored aggregator for v0.1.0 * Fixed copypaste SignatureDelta issue * WIP Aggregator refactor * applied review comments * Fix merge conflict Format code * apply review comments * Lint code * Apply code review * fix test results * apply review comments * properly await Aggregate function * lint files * Refactor code to provide in-place aggregation * Add example * Fix examples and lint code * Update readme and example * Fix tests * apply review sugestions * fix tests * fix tests * Apply suggestions from code review Co-authored-by: Stephen <stephen@stainless.com> * typo * remove obsolete gitignore entry * typo * lint * fix linter? * fix lint * fixes * example working * done? * fix formatting * fixes * add exception when computed timeout is too high * update readme * address feedback * formatting --------- Co-authored-by: meorphis <eric@stainless.com> Co-authored-by: JPVenson <github@jpb.email> Co-authored-by: JPVenson <ger-delta-07@hotmail.de>
* Add vertex provider Add vertex example Add explicit body check for vertex Readd explicit check for model value in bedrock client lint reintroduce null forgiving operator as required by build * apply review suggestions * Update examples/MessagesExample.Vertex/Program.cs * Apply suggestion from @sd-st --------- Co-authored-by: Stephen <stephen@stainless.com>
Add handling for nullable union types (e.g., "type": ["integer", "null"]) generated by the C# MCP SDK for optional nullable parameters. Transforms them to simple types for non-required properties since structured outputs doesn't support union types. Changes: - Add nullable union type normalization in schema transform - Add TransformNullableUnionType helper for tool property processing - Reorder required/properties parsing to support transformation - Add tests for nullable union type transformation
Add AIContentCacheExtensions with WithCacheControl() methods that allow setting Anthropic prompt caching on AIContent instances via AdditionalProperties. Changes: - New AIContentCacheExtensions.cs with WithCacheControl(CacheControlEphemeral) and WithCacheControl(TTL) extension methods - Update CreateMessageParams in both AnthropicClientExtensions and AnthropicBetaClientExtensions to apply cache control when mapping AIContent to Anthropic content block params (TextBlockParam, ImageBlockParam, DocumentBlockParam, ToolUseBlockParam, ToolResultBlockParam) - Fix system message handling in both clients to support cache control - Add unit tests for extension methods and request serialization The Beta client converts from CacheControlEphemeral to BetaCacheControlEphemeral internally, so users can use the same extension methods with both clients.
6892ce7 to
413a2b2
Compare
2402c71 to
9ae6014
Compare
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.
For agentic loops the cost difference between caching and not caching is massive, and it's really awkward to use caching with the extensions. And not really possible at all at the system-level (because of how it converts without using the raw representation factory). Using raw representation factory also means one has to re-implement the mapping from MEAI to Anthropic content types. Instead this PR adds a new extension method that uses AdditionalProperties to store the CacheControl and then uses it while mapping in the existing extension code.