truera / trulens

Evaluation and Tracking for LLM Experiments
https://www.trulens.org/
MIT License
2.05k stars 177 forks source link

Issue with Trulens Evaluation and TruChain(using LangChain) #776

Closed morhyak closed 7 months ago

morhyak commented 8 months ago

I'm currently working on LLM evaluation using Trulens and Azure openai and encountering some issues with the code. Here's the relevant portion of my code:

retriever = vectorstore .as_retriever()

prompt = hub.pull("rlm/rag-prompt")

def format_docs(docs):
    return "\n\n".join(doc.page_content for doc in docs)

rag_chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

When attempting to apply the Trulens recorder with the following code:


# TruLens Eval chain recorder
chain_recorder = TruChain(
    rag_chain, app_id="Chain1_ChatApplication", feedbacks=[f_qa_relevance, f_context_relevance, f_groundedness])
I encounter the error:
ValidationError: 1 validation error for TruChain
app
  Can't instantiate abstract class Chain with abstract methods _call, input_keys, output_keys (type=type_error)

I also tried applying TruChain with an llm Langchain chain:

chain = LLMChain(llm=llm, prompt=prompt)

qa = RetrievalQA.from_chain_type(
    llm=llm,
    retriever=vectorstore.as_retriever()
)
chain_recorder = TruChain(
    qa, app_id="contextual-chatbot", feedbacks=[f_qa_relevance, f_context_relevance, f_groundedness]
)

However, this results in the error:(in the chain_recorder part)

TypeError: Object of type 'OpenAI' is not JSON serializable I'm using Python 3.10.11 and have also tested with Python 3.9. The relevant package versions are as follows:

langchain==0.1.0 langchain-community==0.0.9 langchain-core==0.1.7 langchainhub==0.1.14 trulens-eval==0.18.1

piotrm0 commented 8 months ago

Hi @morhyak , can you run this on latest release?