-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdecorator_example.py
More file actions
37 lines (24 loc) · 917 Bytes
/
decorator_example.py
File metadata and controls
37 lines (24 loc) · 917 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
36
37
"""Decorator shorthand for simple prompt-to-response agents.
Use this pattern when your agent is a simple function that takes a prompt
and returns a result. For more complex agents with multi-turn conversations
or state, use the context manager pattern instead.
Prerequisites:
1. Start agentevals dev server:
$ agentevals serve --dev --port 8001
2. Set your API key:
$ export OPENAI_API_KEY="your-key-here"
Usage:
$ python examples/sdk_example/decorator_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(eval_set_id="sdk-decorator-demo")
llm = ChatOpenAI(model="gpt-4o-mini")
@app.agent
def my_agent(prompt):
return llm.invoke(prompt).content
app.run(["What is 2 + 2?", "Tell me a joke", "Is 17 prime?"])