Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

core: introduce API to encode return values as response objects #88

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Jan 27, 2025

We introduce several encoders that can be used to encode any return value to a relevant response type.

Specifically, there is ToolResponseEncoder that could be used to encode any return value to a ToolResponse; ContentEncoder to encode any return value to Content; ResourceContentsEncoder to ResourceContents and PromptResponseEncoder to PromptResponse.

We also register JsonTextContentEncoder and JsonTextResourceContentsEncoder by default. As a result, any "custom" return value returned from a @Tool method is encoded as TextContent containing the value encoded as JSON (using Jackson), and any "custom" return value returned from a @Resource method is encoded as TextResourceContents containing the value encoded as JSON (using Jackson).

@mkouba mkouba force-pushed the issue-85-encoders branch 3 times, most recently from 3bb8977 to 011b80f Compare January 28, 2025 07:09
@mkouba mkouba marked this pull request as ready for review January 28, 2025 07:11
@mkouba mkouba requested a review from a team as a code owner January 28, 2025 07:11
@mkouba mkouba requested a review from geoand January 28, 2025 07:19
Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Nice!

@mkouba mkouba force-pushed the issue-85-encoders branch from 011b80f to b41885e Compare January 28, 2025 09:08
@mkouba mkouba merged commit 0095a17 into quarkiverse:main Jan 28, 2025
1 check passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add API to encode aritrary objects as Content and ResourceContents
2 participants