[ai] Add GenerateTextStr convenience function, add examples, and support value types#508
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new convenience function GenerateTextStr, extends support for value type messages across different message types, and updates tests and documentation accordingly. Key changes include:
- Adding value-type handling for system, user, assistant, and tool messages.
- Expanding test coverage to include value type messages and content blocks.
- Updating examples and documentation to utilize the new GenerateTextStr function.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| go.work.sum | Update dependency for golang.org/x/tools to the new version. |
| aisdk/ai/provider/openai/internal/codec/encode_prompt_test.go | Added test cases to cover value type messages for all message categories. |
| aisdk/ai/provider/openai/internal/codec/encode_prompt.go | Extended encoding functions to support both pointer and value type messages and content blocks. |
| aisdk/ai/provider/internal/openrouter/codec/encode_prompt.go | Added branches for handling value types in message encoding. |
| aisdk/ai/provider/anthropic/codec/encode_prompt_test.go | Added new test cases for value type messages and content blocks. |
| aisdk/ai/provider/anthropic/codec/encode_prompt.go | Extended encoding logic for value type messages/content blocks. |
| aisdk/ai/go.mod | Added some new dependencies and updated indirect modules. |
| aisdk/ai/examples/basic/simple-text/main.go, aisdk/ai/examples/README.md, aisdk/ai/ai.go, aisdk/ai/README.md | Updated examples and documentation to use the new GenerateTextStr function. |
mikeland73
approved these changes
Jun 6, 2025
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
How was it tested?
Ran tests, ran example.
Community Contribution License
All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.
By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.