-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_traced_groq_mock.py
More file actions
58 lines (43 loc) · 2 KB
/
Copy pathtest_traced_groq_mock.py
File metadata and controls
58 lines (43 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""End-to-end verification of TracedGroq using a real langchain-core fake chat model.
Uses ``FakeListChatModel`` (a real ``BaseChatModel`` subclass) so the full
LangChain callback path still fires (``on_chat_model_start`` /
``on_llm_end``) without needing a Groq API key.
"""
from __future__ import annotations
import os
import sys
import tempfile
_REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
_SDK_PATH = os.path.join(_REPO_ROOT, "packages", "python-sdk")
if os.path.isdir(_SDK_PATH) and _SDK_PATH not in sys.path:
sys.path.insert(0, _SDK_PATH)
from langchain_core.language_models.fake_chat_models import FakeListChatModel
from agent_devtools import AgentDebugger
from agent_devtools.adapters.groq import wrap_groq
def main() -> None:
tmp = tempfile.mkdtemp()
db = os.path.join(tmp, "trace.db")
debugger = AgentDebugger(name="mock-groq", db_path=db, auto_open_browser=False, port=4188)
fake = FakeListChatModel(responses=["Hello, Alice! How can I help you today?"])
traced = wrap_groq(fake, debugger)
print(f"Traced wrapper: {traced!r}")
print(f"Model name propagated: {traced.model_name}")
with debugger.run("mock-groq") as run:
answer = traced.invoke(
[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hi, my name is Bob"},
]
)
print(f"Answer: {answer.content}")
runs = debugger.store.list_runs()
assert runs, "expected at least one run"
events = debugger.store.get_events(runs[0]["id"])
types = [e.type for e in events]
print(f"Event types: {types}")
assert "prompt.assembled" in types, "expected prompt.assembled from on_chat_model_start"
assert "model.response" in types, "expected model.response from on_llm_end"
assert runs[0]["status"] == "ok", f"run should be ok, got {runs[0]['status']}"
print("\nTRACED GROQ MOCK TEST PASSED")
if __name__ == "__main__":
main()