mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-15 23:20:49 +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
33
tests/test_tool_llm_truncation.py
Normal file
33
tests/test_tool_llm_truncation.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from oclaw.chat.tool_runtime import truncate_tool_result_for_llm_messages, tool_llm_message_max_chars
|
||||
|
||||
|
||||
class ToolLlmTruncationTests(unittest.TestCase):
|
||||
def test_small_payload_unchanged(self) -> None:
|
||||
d = {"ok": True, "files": ["a.txt", "b.txt"], "count": 2}
|
||||
self.assertEqual(truncate_tool_result_for_llm_messages(d), d)
|
||||
|
||||
def test_huge_files_truncated(self) -> None:
|
||||
cap = 8000
|
||||
files = [f"f{i:05d}.txt" for i in range(5000)]
|
||||
d = {"ok": True, "files": files, "root": "C:\\\\test"}
|
||||
out = truncate_tool_result_for_llm_messages(d, max_chars=cap)
|
||||
self.assertTrue(out.get("_truncated_for_llm"))
|
||||
self.assertLessEqual(len(json.dumps(out, ensure_ascii=False)), cap)
|
||||
self.assertIn("files_total", out)
|
||||
self.assertGreater(out["files_total"], len(out.get("files") or []))
|
||||
|
||||
def test_tool_llm_max_chars_env(self) -> None:
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
with mock.patch.dict(os.environ, {"AIA_TOOL_LLM_MESSAGE_MAX_CHARS": "9000"}, clear=False):
|
||||
self.assertEqual(tool_llm_message_max_chars(), 9000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue