Repository: truera/trulens
Issue: [BUG]Error when calling trulens on my own dataset
Root cause: Validation Gap

**Bug Description**
What happened?
Now I am using my own data set, which contains question, context and response，like
```
data_samples = {
    'question': ['xxx', 'xxx'],
    'response': ['xxx', 'xxx'],
    'contexts' : [['xxx'], 
    ['xxx']],
}
```
At present, the values of response are all none, that is, there are only question and context in my csv file. My processing code is as follows:
`
```
import pandas
import os
from datasets import Dataset
import ast
cwd = os.getcwd()
relative_path = '/testset_v2.csv'
file_path = cwd + relative_path
try:
    data_df = pandas.read_csv(file_path, header=0, skip_blank_lines=True, encoding="GB18030")
except Exception as e:
    print(")
# data_df = pandas.read_csv(file_path,header=0,skip_blank_lines=True,encoding="GB18030")

print(data_df.head(6))
def convert_to_trulens_format(input_df):
    question_list ,context_list ,response_list = [], [], []

    question_list = input_df['question'].to_list()
    response_list = input_df['response'].to_list()
    context_list = input_df.contexts.to_list()
    context_list = [[context] for context in context_list]
    for i in range(len(context_list)):
        context = ast.literal_eval(context_list[i][0])
        flattened_context = [item for sublist in context for item in sublist]
        context_list[i] = [' '.join(flattened_context)]

    
    data_samples = {"prompt": question_list,
                    "context": context_list,
                    "response":response_list,#
}

    ragas_ds = pandas.DataFrame(data_samples)           
    return ragas_ds

df = convert_to_trulens_format(data_df)
print(type(df))


from trulens_eval.schema.feedback 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.feedback import Feedback
from trulens_eval.feedback.provider.openai import AzureOpenAI as fAzureOpenAI
# from dotenv import load_dotenv
# load_dotenv()
import os
os.environ["OPENAI_API_KEY"] = ''
os.environ["OPENAI_API_BASE"] =''
from trulens_eval.feedback.provider import OpenAI
from trulens_eval.feedback.feedback import Feedback
# from trulens_eval.schema import FeedbackResult

# Initialize provider class
openai = OpenAI()
# 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(openai.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)
    temp.append(result)

for feedback, feedback_result in rec.wait_for_feedback_results().items():
    print(feedback.name, feedback_result.result)
    print('hello')`
```

Running this code results in the following error：
openai request failed <class 'openai.AuthenticationError'>=Error code: 401 - {'error': {'message': 'Your authentication token is not from a valid issuer.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_issuer'}}. Retries remaining=0.
Feedback Function exception caught: Traceback (most recent call last):
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\feedback.py", line 899, in run
    result_and_meta, part_cost = mod_base_endpoint.Endpoint.track_all_costs_tally(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\provider\endpoint\base.py", line 496, in track_all_costs_tally
    result, cbs = Endpoint.track_all_costs(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\provider\endpoint\base.py", line 477, in track_all_costs
    return Endpoint._track_costs(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\provider\endpoint\base.py", line 574, in _track_costs
    result: T = __func(*args, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\provider\base.py", line 308, in qs_relevance  
    return self.context_relevance(question, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\provider\base.py", line 288, in context_relevance
    return self.generate_score(
           ^^^^^^^^^^^^^^^^^^^^
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\provider\base.py", line 161, in generate_score    response = self.endpoint.run_in_pace(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\provider\endpoint\base.py", line 308, in run_in_pace
    raise RuntimeError(
RuntimeError: Endpoint openai request failed 4 time(s):
        Error code: 401 - {'error': {'message': 'Your authentication token is not from a valid issuer.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_issuer'}}
        Error code: 401 - {'error': {'message': 'Your authentication token is not from a valid issuer.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_issuer'}}
        Error code: 401 - {'error': {'message': 'Your authentication token is not from a valid issuer.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_issuer'}}
        Error code: 401 - {'error': {'message': 'Your authentication token is not from a valid issuer.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_issuer'}}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\deepeval\.venv\Lib\site-packages\trulens_eval\feedback\feedback.py", line 913, in run
    raise RuntimeError(
RuntimeError: Evaluation of qs_relevance failed on inputs:{'context': [' some chinese contextx.

qs_relevance None
hello

How to solve this problem? Look forward to your reply, thank you!


<!-- Greeting -->
Hey there, @kmr666! I'm here to assist you with any bugs, questions, or contributions you have while waiting for a human maintainer. Let's squash those bugs together! 🤖

<!-- Answer -->
To resolve the `openai.AuthenticationError` with error code 401, stating that the authentication token is not from a valid issuer, ensure that you have correctly set the `OPENAI_API_KEY` environment variable with a valid API key. Here is the relevant code snippet:

```python
import os
os.environ["OPENAI_API_KEY"] = "sk-..."
```

Make sure to replace `"sk-..."` with your actual OpenAI API key. If the issue persists, verify that the API key is still active and has the necessary permissions <sup>[[1]](https://github.com/truera/trulens/blob/main/trulens_eval/examples/expositional/frameworks/openai_assistants/openai_assistants_api.ipynb)</sup>.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*