Skip to content

[ai] Add GenerateTextStr convenience function, add examples, and support value types#508

Merged
loreto merged 1 commit into
mainfrom
daniel/loop
Jun 6, 2025
Merged

[ai] Add GenerateTextStr convenience function, add examples, and support value types#508
loreto merged 1 commit into
mainfrom
daniel/loop

Conversation

@loreto
Copy link
Copy Markdown
Contributor

@loreto loreto commented Jun 6, 2025

Summary

  • Add GenerateTextStr function for simple string-based prompts
  • Support both pointer and value types for all message types (SystemMessage, UserMessage, AssistantMessage, ToolMessage) and corresponding content blocks.
  • Add comprehensive test coverage for value type messages
  • Update README.md example to use new GenerateTextStr function
  • Add examples directory with basic usage

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.

@loreto loreto requested review from Copilot and mikeland73 June 6, 2025 18:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@loreto loreto merged commit 988405e into main Jun 6, 2025
13 checks passed
@loreto loreto deleted the daniel/loop branch June 6, 2025 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants