-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] Running on existing data #1215
Comments
Hey @funkjo - you can wait for computation and then display feedback results using the following: for feedback, feedback_result in rec.wait_for_feedback_results().items():
print(feedback.name, feedback_result.result) Does that help? |
@sfc-gh-jreini thanks for the comment. Not seeing any results when trying that out. Code runs but prints nothing. Here is the full code FYI: import pandas as pd
data = {
'prompt': ['Where is Germany?', 'What is the capital of France?'],
'response': ['Germany is in Europe', 'The capital of France is Paris'],
'context': ['Germany is a country located in Europe.', 'France is a country in Europe and its capital is Paris.']
}
df = pd.DataFrame(data)
df.head()
from trulens_eval import Select
from trulens_eval.tru_virtual import VirtualApp
from trulens_eval.tru_virtual import VirtualRecord
virtual_app = dict(
llm=dict(
modelname="some llm component model name"
),
template="information about the template I used in my app",
debug="all of these fields are completely optional"
)
virtual_app = VirtualApp(virtual_app) # can start with the prior dictionary
virtual_app[Select.RecordCalls.llm.maxtokens] = 1024
retriever_component = Select.RecordCalls.retriever
virtual_app[retriever_component] = "this is the retriever component"
context_call = retriever_component.get_context
data_dict = df.to_dict('records')
data = []
for record in data_dict:
rec = VirtualRecord(
main_input=record['prompt'],
main_output=record['response'],
calls=
{
context_call: dict(
args=[record['prompt']],
rets=[record['context']]
)
}
)
data.append(rec)
from trulens_eval.feedback.provider import OpenAI
from trulens_eval.feedback.feedback import Feedback
from trulens_eval.feedback.provider.openai import AzureOpenAI as fAzureOpenAI
from azure.identity import EnvironmentCredential
from dotenv import load_dotenv
load_dotenv()
import os
# Get token so you don't need API key anymore in env
def getToken():
""" gets the AzureAD token from AzureAD """
credential = EnvironmentCredential()
token = credential.get_token("get token url")
print("token acquired ")
return token
fopenai = fAzureOpenAI(
api_key=getToken().token,
azure_deployment=os.environ["CHATGPT_DEPLOYMENT"],
azure_endpoint=os.environ["OPENAI_URL"],
deployment_name=os.environ["CHATGPT_MODEL"],
api_version=os.environ["OPENAI_API_VERSION"]
)
# Select context to be used in feedback. We select the return values of the
# virtual `get_context` call in the virtual `retriever` component. Names are
# arbitrary except for `rets`.
context = context_call.rets[:]
# Question/statement relevance between question and each context chunk.
f_context_relevance = (
Feedback(fopenai.qs_relevance)
.on_input()
.on(context)
from trulens_eval.tru_virtual import TruVirtual
virtual_recorder = TruVirtual(
app_id="a virtual app",
app=virtual_app,
feedbacks=[f_context_relevance]
)
temp = []
for record in data:
result = virtual_recorder.add_record(record=record, feedback_mode=f_context_relevance)
temp.append(result)
for feedback, feedback_result in rec.wait_for_feedback_results().items():
print(feedback.name, feedback_result.result)
print('hello') |
@sfc-gh-jreini when I print the output of add_record that I saved in a temp list, I see the following:
at the very end, |
I think the issue here might be your setting of feedback mode. Feedback mode should be set when you set up the recorder, and for record in data:
result = virtual_recorder.add_record(record=record, feedback_mode=f_context_relevance)
temp.append(result) To run feedbacks immediately when the record is added, this argument can be left out altogether. for record in data:
result = virtual_recorder.add_record(record=record)
temp.append(result) To run feedbacks in virtual_recorder = TruVirtual(
app_id="a virtual app",
app=virtual_app,
feedbacks=[f_context_relevance, f_groundedness, f_qa_relevance],
feedback_mode = "deferred" # optional
)
for record in data:
result = virtual_recorder.add_record(record=record)
temp.append(result)
tru.start_evaluator() |
I made the suggested change and removed feedback_mode parameter in add_record for feedback, feedback_result in rec.wait_for_feedback_results().items():
print(feedback.name, feedback_result.result)
print('hello') output:
|
Thanks @funkjo - was able to replicate this. Will work on a solution this week. |
thanks @sfc-gh-jreini any update on this? |
Feature Description
Easier way to obtain feedback results when running feedbacks through virtual recorder and virtual app
Reason
I am following the documentation here and after running
I am unable to figure out how to obtain the results of the question relevance feedback function
Importance of Feature
The value this unlocks is the ability to very easily run feedback functions on large amounts of data after they have been logged, rather than during runtime of LLM application.
The text was updated successfully, but these errors were encountered: