Implement SEP-1577 - Sampling With Tools (#1594)

Co-authored-by: Felix Weinberger <fweinberger@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Olivier Chafik 2025-11-23 04:58:14 +00:00 • committed by GitHub
commit 71c475588f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 674 additions and 19 deletions

View file

@ -134,8 +134,8 @@ async def test_sampling(prompt: str, ctx: Context[ServerSession, None]) -> str:
max_tokens=100,
)
if result.content.type == "text":
model_response = result.content.text
if any(c.type == "text" for c in result.content_as_list):
model_response = "\n".join(c.text for c in result.content_as_list if c.type == "text")
else:
model_response = "No response"

View file

@ -20,6 +20,6 @@ async def generate_poem(topic: str, ctx: Context[ServerSession, None]) -> str:
max_tokens=100,
)
if result.content.type == "text":
return result.content.text
if all(c.type == "text" for c in result.content_as_list):
return "\n".join(c.text for c in result.content_as_list if c.type == "text")
return str(result.content)