mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-13 03:52:00 +00:00
fix(acp): inline file attachment resources
This commit is contained in:
parent
498bfc7bc1
commit
733e297b8a
2 changed files with 242 additions and 3 deletions
|
|
@ -1,5 +1,11 @@
|
|||
import pytest
|
||||
from acp.schema import ImageContentBlock, TextContentBlock
|
||||
from acp.schema import (
|
||||
EmbeddedResourceContentBlock,
|
||||
ImageContentBlock,
|
||||
ResourceContentBlock,
|
||||
TextContentBlock,
|
||||
TextResourceContents,
|
||||
)
|
||||
|
||||
from acp_adapter.server import HermesACPAgent, _content_blocks_to_openai_user_content
|
||||
|
||||
|
|
@ -27,6 +33,48 @@ def test_text_only_acp_blocks_stay_string_for_legacy_prompt_path():
|
|||
assert content == "/help"
|
||||
|
||||
|
||||
def test_acp_resource_link_file_is_inlined_as_text(tmp_path):
|
||||
attached = tmp_path / "notes.md"
|
||||
attached.write_text("# Notes\n\nAttached file body", encoding="utf-8")
|
||||
|
||||
content = _content_blocks_to_openai_user_content([
|
||||
TextContentBlock(type="text", text="Please read this file"),
|
||||
ResourceContentBlock(
|
||||
type="resource_link",
|
||||
name="notes.md",
|
||||
title="Project notes",
|
||||
uri=attached.as_uri(),
|
||||
mimeType="text/markdown",
|
||||
),
|
||||
])
|
||||
|
||||
assert content == (
|
||||
"Please read this file\n"
|
||||
"[Attached file: Project notes (notes.md)]\n"
|
||||
f"URI: {attached.as_uri()}\n\n"
|
||||
"# Notes\n\nAttached file body"
|
||||
)
|
||||
|
||||
|
||||
def test_acp_embedded_text_resource_is_inlined_as_text():
|
||||
content = _content_blocks_to_openai_user_content([
|
||||
EmbeddedResourceContentBlock(
|
||||
type="resource",
|
||||
resource=TextResourceContents(
|
||||
uri="file:///workspace/todo.txt",
|
||||
mimeType="text/plain",
|
||||
text="first\nsecond",
|
||||
),
|
||||
),
|
||||
])
|
||||
|
||||
assert content == (
|
||||
"[Attached file: todo.txt]\n"
|
||||
"URI: file:///workspace/todo.txt\n\n"
|
||||
"first\nsecond"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_initialize_advertises_image_prompt_capability():
|
||||
response = await HermesACPAgent().initialize()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue