ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(PROJECT_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
|
||||
from demo import load_cases, matches_expected
|
||||
|
||||
|
||||
def test_expected_match_uses_word_boundaries():
|
||||
assert matches_expected("The answer is 79.", ["79"])
|
||||
assert matches_expected("FAST", ["fast"])
|
||||
assert not matches_expected("The answer is 179.", ["79"])
|
||||
|
||||
|
||||
def test_case_manifest_validation(tmp_path):
|
||||
empty = tmp_path / "cases.json"
|
||||
empty.write_text("[]", encoding="utf-8")
|
||||
with pytest.raises(ValueError, match="Malformed"):
|
||||
load_cases(empty)
|
||||
@@ -0,0 +1,25 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from speech_model import MiniCPMOClient, sha256_file
|
||||
|
||||
|
||||
def test_sha256_file(tmp_path):
|
||||
path = tmp_path / "sample"
|
||||
path.write_bytes(b"abc")
|
||||
assert sha256_file(path) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
|
||||
|
||||
def test_inference_requires_loaded_model():
|
||||
client = MiniCPMOClient(enable_tts=False)
|
||||
with pytest.raises(RuntimeError, match=r"Call load\(\)"):
|
||||
client.infer_text("hello")
|
||||
|
||||
|
||||
def test_speech_output_requires_tts(monkeypatch, tmp_path):
|
||||
client = MiniCPMOClient(enable_tts=False)
|
||||
client.model = object()
|
||||
monkeypatch.setattr(client, "load_audio", lambda _: [0.0])
|
||||
with pytest.raises(RuntimeError, match="enable_tts=False"):
|
||||
client.infer_audio(tmp_path / "input.wav", "answer", output_audio_path=tmp_path / "out.wav")
|
||||
@@ -0,0 +1,53 @@
|
||||
import json
|
||||
import wave
|
||||
from pathlib import Path
|
||||
|
||||
from speech_model import MODEL_ID, MODEL_REVISION, sha256_file
|
||||
from validate_evidence import validate
|
||||
|
||||
|
||||
def test_complete_evidence_passes(tmp_path):
|
||||
wav = tmp_path / "answer.wav"
|
||||
with wave.open(str(wav), "wb") as handle:
|
||||
handle.setnchannels(1)
|
||||
handle.setsampwidth(2)
|
||||
handle.setframerate(24000)
|
||||
handle.writeframes(b"\x00\x00" * 2400)
|
||||
arm = {"response": "ok", "transcript": "spoken words"}
|
||||
evidence = {
|
||||
"experiment": "6-5",
|
||||
"model": {
|
||||
"model_id": MODEL_ID,
|
||||
"model_revision": MODEL_REVISION,
|
||||
"cuda_available": True,
|
||||
"init_audio": True,
|
||||
},
|
||||
"protocol": {"enable_thinking": False},
|
||||
"cases": [
|
||||
{"direct": {"response": "ok"}, "self_cascade": arm}
|
||||
for _ in range(4)
|
||||
],
|
||||
"speech_output": {
|
||||
"output_audio": {
|
||||
"path": str(wav),
|
||||
"sha256": sha256_file(wav),
|
||||
"sample_rate_hz": 24000,
|
||||
"duration_seconds": 0.1,
|
||||
}
|
||||
},
|
||||
"implementation_sha256": {
|
||||
"requirements.txt": sha256_file(
|
||||
Path(__file__).resolve().parents[1] / "requirements.txt"
|
||||
)
|
||||
},
|
||||
"external_api_calls": 0,
|
||||
}
|
||||
path = tmp_path / "evidence.json"
|
||||
path.write_text(json.dumps(evidence), encoding="utf-8")
|
||||
assert validate(path)["passed"] is True
|
||||
|
||||
|
||||
def test_missing_direct_response_fails(tmp_path):
|
||||
path = tmp_path / "evidence.json"
|
||||
path.write_text(json.dumps({"experiment": "6-5", "cases": []}), encoding="utf-8")
|
||||
assert validate(path)["passed"] is False
|
||||
Reference in New Issue
Block a user