Skip to content

Commit

Permalink
extract query_str from query bundle as main input for llama_index apps (
Browse files Browse the repository at this point in the history
#690)

* extra query_str from query bundle as main input

* add test to dev_notebook

* notes for dev notebook
  • Loading branch information
piotrm0 authored Dec 18, 2023
1 parent cb40418 commit 05e1a46
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
69 changes: 58 additions & 11 deletions trulens_eval/examples/experimental/dev_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cost"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -327,15 +318,71 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"record = recs.get()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Llama-Index testing\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from trulens_eval import Feedback, Tru, TruLlama\n",
"from trulens_eval.feedback import Groundedness\n",
"from trulens_eval.feedback.provider.openai import OpenAI\n",
"\n",
"tru = Tru()\n",
"\n",
"from llama_index import VectorStoreIndex, QueryBundle\n",
"from llama_index.readers.web import SimpleWebPageReader\n",
"\n",
"documents = SimpleWebPageReader(\n",
" html_to_text=True\n",
").load_data([\"http://paulgraham.com/worked.html\"])\n",
"index = VectorStoreIndex.from_documents(documents)\n",
"\n",
"query_engine = index.as_query_engine()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tru_query_engine_recorder = TruLlama(query_engine,\n",
" app_id='LlamaIndex_App1',\n",
" feedbacks=[])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# or as context manager\n",
"with tru_query_engine_recorder as recording:\n",
" print(query_engine.query(QueryBundle(\"What did the author do growing up?\")))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"recs.get()"
"rec = recording.get().layout_calls_as_app() # important\n",
"from trulens_eval.utils.serial import Lens\n",
"next(Lens().app.query[0].args.str_or_query_bundle.get(rec))"
]
},
{
Expand Down
6 changes: 5 additions & 1 deletion trulens_eval/trulens_eval/tru_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ def main_input(

if 'str_or_query_bundle' in bindings.arguments:
# llama_index specific
return bindings.arguments['str_or_query_bundle']
str_or_bundle = bindings.arguments['str_or_query_bundle']
if isinstance(str_or_bundle, QueryBundle):
return str_or_bundle.query_str
else:
return str_or_bundle

elif 'message' in bindings.arguments:
# llama_index specific
Expand Down

0 comments on commit 05e1a46

Please sign in to comment.