Open 0930mcx opened 1 week ago
@0930mcx pls rotate you key, it's exposed. We removed it from your issue in the meantime.
Hey @0930mcx - you can initialize your provider with the base URL like this:
from trulens.providers.openai.provider import OpenAI
feedback_provider = OpenAI(
model_engine="glm-4v-9b",
base_url="http://0.0.0.0:8000/v1/",
api_key="your_api_key"
)
@0930mcx any success changing the base model like I'm showing above?
I wrote the feedback functions but it is not available, the dashboard shows that "No feedback functions found." and the feedback functions are not performed actually. My code is following: import os
os.environ["OPENAI_API_BASE"] = os.environ["OPENAI_API_KEY"] = from trulens.core import TruSession, FeedbackMode
session = TruSession() session.reset_database() import os import urllib.request
url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt" file_path = "data/paul_graham_essay.txt"
if not os.path.exists("data"): os.makedirs("data")
if not os.path.exists(file_path): urllib.request.urlretrieve(url, file_path) from llama_index.core import Settings from llama_index.core import SimpleDirectoryReader from llama_index.core import VectorStoreIndex from llama_index.llms.openai import OpenAI
Settings.chunk_size = 128 Settings.chunk_overlap = 16 Settings.llm = OpenAI()
documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(similarity_top_k=3)
response = query_engine.query("What did the author do growing up?")
print(response)
import numpy as np from trulens.apps.llamaindex import TruLlama from trulens.core import Feedback from trulens.providers.openai import OpenAI
Initialize provider class
provider = OpenAI()
select context to be used in feedback. the location of context is app specific.
context = TruLlama.select_context(query_engine)
Define a groundedness feedback function
f_groundedness = ( Feedback( provider.groundedness_measure_with_cot_reasons, name="Groundedness" ) .on(context.collect()) # collect context chunks into a list .on_output() )
Question/answer relevance between overall question and answer.
f_answer_relevance = Feedback( provider.relevance_with_cot_reasons, name="Answer Relevance" ).on_input_output()
Question/statement relevance between question and each context chunk.
f_context_relevance = ( Feedback( provider.context_relevance_with_cot_reasons, name="Context Relevance" ) .on_input() .on(context) .aggregate(np.mean) ) tru_query_engine_recorder = TruLlama( query_engine, app_name="LlamaIndex_App", app_version="base", feedbacks=[f_groundedness, f_answer_relevance, f_context_relevance], feedback_mode=FeedbackMode.WITH_APP_THREAD )
or as context manager
from trulens_eval import Tru tru = Tru() tru.run_dashboard() from trulens.dashboard.display import get_feedback_result with tru_query_engine_recorder as recording: query_engine.query("What did the author do growing up?")