-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy patha.py
More file actions
164 lines (140 loc) · 4.82 KB
/
a.py
File metadata and controls
164 lines (140 loc) · 4.82 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from deepeval.tracing import (
observe,
update_current_span,
update_current_trace,
update_llm_span,
)
import asyncio
from deepeval.prompt import Prompt
prompt = Prompt(alias="Message Prompt")
prompt.pull()
@observe(
type="llm",
model="gemini-2.5-flash",
cost_per_input_token=0.0000003,
cost_per_output_token=0.0000025,
metric_collection="default123",
)
async def meta_agent(query: str):
update_current_span(
input=query,
output=query,
expected_output=query,
retrieval_context=[query],
metadata={"query": query},
name="meta_agent",
)
update_llm_span(
input_token_count=10,
output_token_count=10,
# prompt=prompt,
)
update_current_trace(
name="meta_agent",
thread_id="fetch 11",
input=query,
output=query,
expected_output=query,
retrieval_context=[query],
user_id="clickhouse user",
tags=["test", "example"],
metadata={"query": {"query": query}},
test_case_id="ffb10651-010e-4d37-9947-b75324c31971",
)
return query
async def run_parallel_examples():
tasks = [
meta_agent("How tall is Mount Everest?"),
# meta_agent("What's the capital of Brazil?"),
# meta_agent("Who won the last World Cup?"),
# meta_agent("Explain quantum entanglement."),
# meta_agent("What's the latest iPhone model?"),
# meta_agent("How do I cook a perfect steak?"),
# meta_agent("Tell me a joke about robots."),
# meta_agent("What causes lightning?"),
# meta_agent("Who painted the Mona Lisa?"),
# meta_agent("What's the population of Japan?"),
# meta_agent("How do vaccines work?"),
# meta_agent("Recommend a good sci-fi movie."),
]
await asyncio.gather(*tasks)
asyncio.run(run_parallel_examples())
# # ############################################################
# # ############################################################
# # ############################################################
# from deepeval import evaluate
# from deepeval.metrics import AnswerRelevancyMetric
# from deepeval.test_case import LLMTestCase
# evaluate(
# test_cases=[
# LLMTestCase(
# input="How tall is Mount Everest?",
# actual_output="Mount Everest is 8,848 meters tall.",
# expected_output="Mount Everest is 8,848 meters tall.",
# ),
# ],
# metrics=[AnswerRelevancyMetric()],
# )
# ############################################################
# ############################################################
# ############################################################
# from deepeval import evaluate
# from deepeval.metrics import TurnRelevancyMetric
# from deepeval.test_case import ConversationalTestCase, Turn
# evaluate(
# test_cases=[
# ConversationalTestCase(
# turns=[
# Turn(
# role="user",
# content="Hello, how are you?",
# ),
# Turn(
# role="assistant",
# content="I'm doing well, thanks for asking! How can I help you today?",
# ),
# Turn(
# role="user",
# content="Can you explain what answer relevancy means?",
# ),
# Turn(
# role="assistant",
# content=(
# "Answer relevancy measures how well a response directly addresses "
# "the user's question, focusing on usefulness and alignment with intent."
# ),
# ),
# ],
# ),
# ],
# metrics=[TurnRelevancyMetric()],
# )
######
# from deepeval.tracing import observe, update_current_trace
# from deepeval.metrics import AnswerRelevancyMetric
# from deepeval.dataset import EvaluationDataset
# from openai import OpenAI
# @observe()
# def llm_app(query: str) -> str:
# @observe()
# def retriever(query: str) -> list[str]:
# chunks = ["List", "of", "text", "chunks"]
# update_current_trace(retrieval_context=chunks)
# return chunks
# @observe(type="llm")
# def generator(query: str, text_chunks: list[str]) -> str:
# res = (
# OpenAI()
# .chat.completions.create(
# model="gpt-4o", messages=[{"role": "user", "content": query}]
# )
# .choices[0]
# .message.content
# )
# update_current_trace(input=query, output=res)
# return res
# return generator(query, retriever(query))
# dataset = EvaluationDataset()
# dataset.pull(alias="Playground Dataset")
# for golden in dataset.evals_iterator(metrics=[AnswerRelevancyMetric()]):
# llm_app(golden.input)