Skip to content

Commit

Permalink
fix: add prepare_data to avoid evaluation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
billmetangmo authored Jul 3, 2024
1 parent d5be006 commit 2fc1e6b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions etl/experiments/backtesting_prompt.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import os
from langchain.chains import ConversationalRetrievalChain
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain.chat_models import ChatOpenAI
from langchain.document_loaders.csv_loader import CSVLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain_openai import ChatOpenAI
from langchain_community.document_loaders import CSVLoader
from langchain_openai import OpenAIEmbeddings
from langchain.prompts.chat import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
SystemMessagePromptTemplate,
)
from langsmith.evaluation import evaluate, LangChainStringEvaluator
from langchain.vectorstores import FAISS
from langchain_community.vectorstores import FAISS

def prepare_data(run, example):
return {
"prediction": run.outputs['answer'],
"reference": example.outputs['answer'],
"input": example.inputs['question'],
}

system_template = """Vous êtes un assistant IA qui fournit des informations sur les associations camerounaises en France. Vous recevez une question et fournissez une réponse claire et structurée. Lorsque cela est pertinent, utilisez des points et des listes pour structurer vos réponses.
Expand Down Expand Up @@ -62,13 +68,16 @@

# List of evaluators to score the outputs of target task
evaluators = [
LangChainStringEvaluator("cot_qa")
LangChainStringEvaluator(
"context_qa",
prepare_data=prepare_data
)
]

# Evaluate the target task
results = evaluate(
chain.invoke,
data=dataset,
evaluators=evaluators,
experiment_prefix=experiment_prefix,
)
experiment_prefix=experiment_prefix
)

0 comments on commit 2fc1e6b

Please sign in to comment.