You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
This update refactors the provided examples incorporating the
corresponding async blocks. The changes enable the code to be executed
seamlessly without any further modifications.
Key Changes:
Asynchronous Functionality: Wrapped relevant code in an async def
function, allowing for proper asynchronous execution. This eliminates
any runtime issues associated with unhandled asynchronous operations.
Evaluator LLM Initialization: Clearly demonstrates the creation of the
evaluator_llm object using the LangchainLLMWrapper with the ChatOpenAI
model set to gpt-4o. This change improves clarity as the setup of the
evaluator was previously not self-explanatory.
Code Readability: Improved formatting and organization of import
statements for better readability and maintainability.
content="Can you provide me with details about Einstein's theory of relativity?"
44
+
),
45
+
AIMessage(
46
+
content="Sure, let me retrieve the relevant information for you.",
47
+
tool_calls=[
48
+
ToolCall(
49
+
name="document_search",
50
+
args={"query": "Einstein's theory of relativity"},
51
+
)
52
+
],
53
+
),
54
+
ToolMessage(
55
+
content="Found relevant documents: 1. Relativity: The Special and the General Theory, 2. General Theory of Relativity by A. Einstein."
56
+
),
57
+
AIMessage(
58
+
content="I found some documents on Einstein's theory of relativity. Which one would you like to know more about: 'Relativity: The Special and the General Theory' or 'General Theory of Relativity by A. Einstein'?"
59
+
),
60
+
HumanMessage(content="Tell me about the 'General Theory of Relativity'."),
61
+
AIMessage(
62
+
content="Got it! Let me fetch more details from 'General Theory of Relativity by A. Einstein'.",
63
+
tool_calls=[
64
+
ToolCall(
65
+
name="document_retrieve",
66
+
args={"document": "General Theory of Relativity by A. Einstein"},
67
+
)
68
+
],
69
+
),
70
+
ToolMessage(
71
+
content="The document discusses how gravity affects the fabric of spacetime, describing the relationship between mass and spacetime curvature."
72
+
),
73
+
AIMessage(
74
+
content="The 'General Theory of Relativity' explains how gravity affects the fabric of spacetime and the relationship between mass and spacetime curvature. Would you like more details or a specific explanation?"
75
+
),
76
+
HumanMessage(
77
+
content="No, that's perfect. By the way, do you know any good recipes for a chocolate cake?"
78
+
),
79
+
AIMessage(
80
+
content="Sure! Let me find a simple and delicious recipe for a chocolate cake.",
content="Here’s a popular recipe for a chocolate cake: Ingredients include flour, sugar, cocoa powder, eggs, milk, and butter. Instructions: Mix dry ingredients, add wet ingredients, and bake at 350°F for 30-35 minutes."
87
+
),
88
+
AIMessage(
89
+
content="I found a great recipe for chocolate cake! Would you like the full details, or is that summary enough?"
HumanMessage(content="Can you provide me with details about Einstein's theory of relativity?"),
34
-
AIMessage(content="Sure, let me retrieve the relevant information for you.", tool_calls=[
35
-
ToolCall(name="document_search", args={"query": "Einstein's theory of relativity"})
36
-
]),
37
-
ToolMessage(content="Found relevant documents: 1. Relativity: The Special and the General Theory, 2. General Theory of Relativity by A. Einstein."),
38
-
AIMessage(content="I found some documents on Einstein's theory of relativity. Which one would you like to know more about: 'Relativity: The Special and the General Theory' or 'General Theory of Relativity by A. Einstein'?"),
39
-
HumanMessage(content="Tell me about the 'General Theory of Relativity'."),
40
-
AIMessage(content="Got it! Let me fetch more details from 'General Theory of Relativity by A. Einstein'.", tool_calls=[
41
-
ToolCall(name="document_retrieve", args={"document": "General Theory of Relativity by A. Einstein"})
42
-
]),
43
-
ToolMessage(content="The document discusses how gravity affects the fabric of spacetime, describing the relationship between mass and spacetime curvature."),
44
-
AIMessage(content="The 'General Theory of Relativity' explains how gravity affects the fabric of spacetime and the relationship between mass and spacetime curvature. Would you like more details or a specific explanation?"),
45
-
HumanMessage(content="No, that's perfect. By the way, do you know any good recipes for a chocolate cake?"),
46
-
AIMessage(content="Sure! Let me find a simple and delicious recipe for a chocolate cake.", tool_calls=[
ToolMessage(content="Here’s a popular recipe for a chocolate cake: Ingredients include flour, sugar, cocoa powder, eggs, milk, and butter. Instructions: Mix dry ingredients, add wet ingredients, and bake at 350°F for 30-35 minutes."),
50
-
AIMessage(content="I found a great recipe for chocolate cake! Would you like the full details, or is that summary enough?")
`ToolCallAccuracy` is a metric that can be used to evaluate the performance of the LLM in identifying and calling the required tools to complete a given task. This metric needs `user_input` and `reference_tool_calls` to evaluate the performance of the LLM in identifying and calling the required tools to complete a given task. The metric is computed by comparing the `reference_tool_calls` with the Tool calls made by the AI. The values range between 0 and 1, with higher values indicating better performance.
79
127
80
128
```python
129
+
130
+
import asyncio
131
+
132
+
from ragas.dataset_schema import MultiTurnSample
133
+
from ragas.messages import AIMessage, HumanMessage, ToolCall, ToolMessage
81
134
from ragas.metrics import ToolCallAccuracy
82
-
from ragas.dataset_schema import MultiTurnSample
83
-
from ragas.messages import HumanMessage,AIMessage,ToolMessage,ToolCall
84
135
85
-
sample = [
86
-
HumanMessage(content="What's the weather like in New York right now?"),
87
-
AIMessage(content="The current temperature in New York is 75°F and it's partly cloudy.", tool_calls=[
88
-
ToolCall(name="weather_check", args={"location": "New York"})
89
-
]),
90
-
HumanMessage(content="Can you translate that to Celsius?"),
91
-
AIMessage(content="Let me convert that to Celsius for you.", tool_calls=[
0 commit comments