mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-19 14:23:21 +08:00
初始化:独立 oclaw 仓库首提交
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
This commit is contained in:
commit
ba3836f00f
579 changed files with 83112 additions and 0 deletions
27
tests/test_anthropic_transport.py
Normal file
27
tests/test_anthropic_transport.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from oclaw.platform.llm.transports.anthropic_messages import parse_anthropic_stream_events
|
||||
|
||||
|
||||
def test_anthropic_stream_parses_text_and_tool_use() -> None:
|
||||
events = [
|
||||
{"type": "message_start"},
|
||||
{"type": "content_block_start", "content_block": {"type": "text", "text": ""}},
|
||||
{"type": "content_block_delta", "delta": {"type": "text_delta", "text": "Hi "}},
|
||||
{"type": "content_block_delta", "delta": {"type": "text_delta", "text": "there"}},
|
||||
{"type": "content_block_stop"},
|
||||
{"type": "content_block_start", "content_block": {"type": "tool_use", "id": "toolu_1", "name": "query_route", "input": {}}},
|
||||
{"type": "content_block_delta", "delta": {"type": "input_json_delta", "partial_json": "{\"destination\":\"1.1.1.1\"}"}},
|
||||
{"type": "content_block_stop"},
|
||||
{"type": "message_stop"},
|
||||
]
|
||||
buf: list[str] = []
|
||||
text, tool_calls = parse_anthropic_stream_events(events, on_token=buf.append)
|
||||
assert text == "Hi there"
|
||||
assert "".join(buf) == "Hi there"
|
||||
assert len(tool_calls) == 1
|
||||
tc = tool_calls[0]
|
||||
assert tc.id == "toolu_1"
|
||||
assert tc.name == "query_route"
|
||||
assert tc.arguments.get("destination") == "1.1.1.1"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue