truera/trulens

Error Executing llama_index_quickstart.ipynb

Closed this issue · 12 comments

Keep running into this error when executing this block of code within the quickstart

# or as context manager
with tru_query_engine_recorder as recording:
    query_engine.query("What did the author do growing up?")
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[20], line 2
      1 # or as context manager
----> 2 with tru_query_engine_recorder as recording:
      3     query_engine.query("What did the author do growing up?")

File c:\Users\TurnerZ\Documents\GitHub\amaliai-hr\.venv\Lib\site-packages\trulens_eval\app.py:842, in App.__exit__(self, exc_type, exc_value, exc_tb)
    839 self.recording_contexts.reset(ctx.token)
    841 if exc_type is not None:
--> 842     raise exc_value
    844 return

Cell In[20], line 3
      1 # or as context manager
      2 with tru_query_engine_recorder as recording:
----> 3     query_engine.query("What did the author do growing up?")

File c:\Users\TurnerZ\Documents\GitHub\amaliai-hr\.venv\Lib\site-packages\trulens_eval\instruments.py:633, in Instrument.tracked_method_wrapper.<locals>.tru_wrapper(*args, **kwargs)
    625 @functools.wraps(func)
    626 def tru_wrapper(*args, **kwargs):
    627     logger.debug(
    628         f"{query}: calling instrumented sync method {func} of type {type(func)}, "
    629         f"iscoroutinefunction={is_really_coroutinefunction(func)}, "
    630         f"isasyncgeneratorfunction={inspect.isasyncgenfunction(func)}"
...
--> 267         result = coro.send(None)
    268     else:
    269         result = coro.throw(exc)

RuntimeError: cannot reuse already awaited coroutine

The docs I'm using: link
llama-index version: llama-index 0.10.6
trulens version: trulens-eva 0.23.0

We're currently working on supporting the newest llama-index release. Currently supported llama-index versions are: llama-index >= 0.9.26, <0.10.0

@Timmy485 - The migration is coming in #891 , can you install from that branch and give it a try? Thanks!

Yep that fixed it. Got the notebook running now
Any ETA on when the update itself would be rolled out tho?

The update was merged in main this morning and will be released out today or tomorrow. Thanks @Timmy485 !

Thank you for this fix, Josh. It's working for me except when I try and run the dashboard, I get the following error:

ImportError: cannot import name 'ServiceContext' from 'llama_index' (unknown location)

With Llama 10, I suppose it should be llama_index.core

Thanks!

Can you share the full stack trace?

Can you share the full stack trace?

Traceback (most recent call last):
File "C:\Users\jonathan.friedman\AppData\Local\anaconda3\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in run_script
exec(code, module.dict)
File "C:\Users\jonathan.friedman\OneDrive - Palladium International, LLC\Documents\Kenya\Nishauri\llama10\Lib\site-packages\trulens_eval\Leaderboard.py", line 15, in
from trulens_eval.db_migration import MIGRATION_UNKNOWN_STR
File "C:\Users\jonathan.friedman\AppData\Local\anaconda3\lib\site-packages\trulens_eval_init
.py", line 83, in
from trulens_eval.feedback import Bedrock
File "C:\Users\jonathan.friedman\AppData\Local\anaconda3\lib\site-packages\trulens_eval\feedback_init_.py", line 14, in
from trulens_eval.feedback.embeddings import Embeddings
File "C:\Users\jonathan.friedman\AppData\Local\anaconda3\lib\site-packages\trulens_eval\feedback\embeddings.py", line 3, in
from llama_index import ServiceContext
ImportError: cannot import name 'ServiceContext' from 'llama_index' (unknown location)

Can you check to ensure you're installed from the current GitHub version?

! pip uninstall trulens_eval -y # to remove existing version
! pip install git+https://github.com/truera/trulens#subdirectory=trulens_eval

Tested this out and am not seeing your error.

@Timmy485 Can you please let us know if this is resolved now?

@yuvneshtruera it was resolved and the issue got closed earlier on, it became more of @JDFPalladium issue when it got reopened

@yuvneshtruera it was resolved and the issue got closed earlier on, it became more of @JDFPalladium issue when it got reopened

The dashboard is working for me now. I have no remaining issue.

Good morning everyone,
please can someone help me to fix this ? I am having an issue running this block of code

# or as context manager 
with tru_query_engine_recorder as recording: 
    query_engine.query("What did the author do growing up?")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[14], line 2
      1 # or as context manager
----> 2 with tru_query_engine_recorder as recording:
      3     query_engine.query("What did the author do growing up?")

File ~/anaconda3/envs/llamaindex/lib/python3.11/site-packages/trulens_eval/app.py:739, in App.__exit__(self, exc_type, exc_value, exc_tb)
    736 self.recording_contexts.reset(ctx.token)
    738 if exc_type is not None:
--> 739     raise exc_value
    741 return

Cell In[14], line 3
      1 # or as context manager
      2 with tru_query_engine_recorder as recording:
----> 3     query_engine.query("What did the author do growing up?")

File ~/anaconda3/envs/llamaindex/lib/python3.11/site-packages/trulens_eval/instruments.py:784, in Instrument.tracked_method_wrapper.<locals>.tru_wrapper(*args, **kwargs)
    778     # If stack has only 1 thing on it, we are looking at a "root
    779     # call". Create a record of the result and notify the app:
    781     if len(stack) == 1:
    782         # If this is a root call, notify app to add the completed record
    783         # into its containers:
--> 784         ctx.app._on_add_record(
    785             ctx=ctx,
    786             func=func,
    787             sig=sig,
    788             bindings=bindings,
    789             ret=rets,
    790             error=error,
    791             perf=Perf(start_time=start_time, end_time=end_time),
    792             cost=cost
    793         )
    795 if error is not None:
    796     raise error

File ~/anaconda3/envs/llamaindex/lib/python3.11/site-packages/trulens_eval/app.py:782, in App._on_add_record(self, ctx, func, sig, bindings, ret, error, perf, cost)
    769     return Record(
    770         main_input=jsonify(main_in),
    771         main_output=jsonify(main_out),
   (...)
    778         meta=jsonify(record_metadata)
    779     )
    781 # Finishing record needs to be done in a thread lock, done there:
--> 782 record = ctx.finish_record(build_record)
    784 if error is not None:
    785     # May block on DB.
    786     self._handle_error(record=record, error=error)

File ~/anaconda3/envs/llamaindex/lib/python3.11/site-packages/trulens_eval/app.py:381, in RecordingContext.finish_record(self, calls_to_record)
    375 """
    376 Run the given function to build a record from the tracked calls and any
    377 pre-specified metadata.
    378 """
    380 with self.lock:
--> 381     record = calls_to_record(self.calls, self.record_metadata)
    382     self.calls = []
    383     self.records.append(record)

File ~/anaconda3/envs/llamaindex/lib/python3.11/site-packages/trulens_eval/app.py:766, in App._on_add_record.<locals>.build_record(calls, record_metadata)
    762 calls = list(calls)
    764 assert len(calls) > 0, "No information recorded in call."
--> 766 main_in = self.main_input(func, sig, bindings)
    767 main_out = self.main_output(func, sig, bindings, ret)
    769 return Record(
    770     main_input=jsonify(main_in),
    771     main_output=jsonify(main_out),
   (...)
    778     meta=jsonify(record_metadata)
    779 )

File ~/anaconda3/envs/llamaindex/lib/python3.11/site-packages/trulens_eval/tru_llama.py:279, in TruLlama.main_input(self, func, sig, bindings)
    277 str_or_bundle = bindings.arguments['str_or_query_bundle']
    278 if isinstance(str_or_bundle, QueryBundle):
--> 279     return str_or_bundle.query_str
    280 else:
    281     return str_or_bundle

AttributeError: 'str' object has no attribute 'query_str'

I am using trulens 0.20.3 and llama-index-core 0.10.23.post1