-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcontext_manager_example.py
More file actions
35 lines (24 loc) · 954 Bytes
/
context_manager_example.py
File metadata and controls
35 lines (24 loc) · 954 Bytes
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
"""Drop-in streaming for existing agent code using the AgentEvals SDK.
This is the primary SDK pattern — wrap your existing code in a context manager
and traces stream to the agentevals UI automatically.
Prerequisites:
1. Start agentevals dev server:
$ agentevals serve --dev --port 8001
2. (Optional) Start UI:
$ cd ui && npm run dev
3. Set your API key:
$ export OPENAI_API_KEY="your-key-here"
Usage:
$ python examples/sdk_example/context_manager_example.py
"""
import logging
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from agentevals import AgentEvals
logging.basicConfig(level=logging.INFO)
load_dotenv(override=True)
app = AgentEvals()
llm = ChatOpenAI(model="gpt-4o-mini")
with app.session(eval_set_id="sdk-context-manager-demo", metadata={"model": "gpt-4o-mini"}):
print(llm.invoke("What is 2 + 2?").content)
print(llm.invoke("Is that number prime?").content)