From 5d4a3b154f9863e689fb0886729f88d9a9f3fb89 Mon Sep 17 00:00:00 2001 From: Josh Reini <60949774+joshreini1@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:14:44 -0400 Subject: [PATCH] Releases/rc trulens eval 0.17.0b (#541) * bump version in init to 0.17.0a * bump version, remove .py files from readme * version bump quickstarts * version bump readmes 17b * version bump init to 17b * version bump quickstarts 17b * version bump into wider docs automation 17b --- docs/trulens_eval/gh_top_intro.md | 12 +- docs/trulens_eval/intro.md | 12 +- .../colab/langchain_quickstart_colab.ipynb | 55 +++-- .../colab/llama_index_quickstart_colab.ipynb | 46 ++-- .../colab/text2text_quickstart_colab.ipynb | 50 ++-- .../examples/quickstart/langchain_async.ipynb | 2 +- .../quickstart/langchain_quickstart.ipynb | 2 +- .../langchain_retrieval_agent.ipynb | 2 +- .../quickstart/llama_index_async.ipynb | 2 +- .../quickstart/llama_index_quickstart.ipynb | 2 +- .../quickstart/pinecone_quickstart.ipynb | 2 +- .../examples/quickstart/prototype_evals.ipynb | 2 +- .../py_script_quickstarts/all_tools.py | 214 +++++++++++------- .../langchain_quickstart.py | 83 ++++--- .../llama_index_quickstart.py | 60 +++-- .../text2text_quickstart.py | 69 +++--- .../quickstart/summarization_eval.ipynb | 2 +- .../quickstart/text2text_quickstart.ipynb | 2 +- trulens_eval/generated_files/all_tools.ipynb | 2 +- trulens_eval/trulens_eval/__init__.py | 2 +- 20 files changed, 346 insertions(+), 277 deletions(-) diff --git a/docs/trulens_eval/gh_top_intro.md b/docs/trulens_eval/gh_top_intro.md index 16f134c18..1b6735236 100644 --- a/docs/trulens_eval/gh_top_intro.md +++ b/docs/trulens_eval/gh_top_intro.md @@ -43,15 +43,15 @@ TruLens supports the evaluation of tracking for any LLM app framework. Choose a **Langchain** -[langchain_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/langchain_quickstart.ipynb). -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb) +[langchain_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/langchain_quickstart.ipynb). +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb) **Llama-Index** -[llama_index_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb). -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb) +[llama_index_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb). +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb) **Custom Text to Text Apps** -[text2text_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/text2text_quickstart.ipynb). -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb) \ No newline at end of file +[text2text_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/text2text_quickstart.ipynb). +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb) \ No newline at end of file diff --git a/docs/trulens_eval/intro.md b/docs/trulens_eval/intro.md index 409ad8af4..9c420b552 100644 --- a/docs/trulens_eval/intro.md +++ b/docs/trulens_eval/intro.md @@ -46,18 +46,18 @@ TruLens supports the evaluation of tracking for any LLM app framework. Choose a **Langchain** -[langchain_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/langchain_quickstart.ipynb). -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb) +[langchain_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/langchain_quickstart.ipynb). +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb) **Llama-Index** -[llama_index_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb). -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb) +[llama_index_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb). +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb) **Custom Text to Text Apps** -[text2text_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/text2text_quickstart.ipynb). -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0a/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb) +[text2text_quickstart.ipynb](https://github.com/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/text2text_quickstart.ipynb). +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/releases/rc-trulens-eval-0.17.0b/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb) ### 💡 Contributing diff --git a/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb b/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb index 7d0266da9..8ddf1188d 100644 --- a/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb +++ b/trulens_eval/examples/quickstart/colab/langchain_quickstart_colab.ipynb @@ -17,7 +17,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "4d8bd621", + "id": "002ffae2", "metadata": {}, "source": [ "# Langchain Quickstart\n", @@ -30,17 +30,17 @@ { "cell_type": "code", "execution_count": null, - "id": "e32c8ad8", + "id": "f028b402", "metadata": {}, "outputs": [], "source": [ - "# ! pip install trulens_eval==0.17.0a langchain>=0.0.263" + "# ! pip install trulens_eval==0.17.0b langchain>=0.0.263" ] }, { "attachments": {}, "cell_type": "markdown", - "id": "1b5822db", + "id": "9c313e70", "metadata": {}, "source": [ "## Setup\n", @@ -51,7 +51,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6ff3805d", + "id": "e8dc32cc", "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "d4703d64", + "id": "ecd0e34e", "metadata": {}, "source": [ "### Import from LangChain and TruLens" @@ -72,7 +72,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3accbb8e", + "id": "2159b8c3", "metadata": {}, "outputs": [], "source": [ @@ -95,7 +95,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "9f2043ff", + "id": "7faab30e", "metadata": {}, "source": [ "### Create Simple LLM Application\n", @@ -106,7 +106,7 @@ { "cell_type": "code", "execution_count": null, - "id": "67703ade", + "id": "e00c3ff8", "metadata": {}, "outputs": [], "source": [ @@ -128,7 +128,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "8e0a7c70", + "id": "b1ac78fe", "metadata": {}, "source": [ "### Send your first request" @@ -137,7 +137,7 @@ { "cell_type": "code", "execution_count": null, - "id": "005409f4", + "id": "8c6c3032", "metadata": {}, "outputs": [], "source": [ @@ -147,7 +147,7 @@ { "cell_type": "code", "execution_count": null, - "id": "93aafd5a", + "id": "d0ceda72", "metadata": {}, "outputs": [], "source": [ @@ -159,7 +159,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "6b87ddde", + "id": "5790ac98", "metadata": {}, "source": [ "## Initialize Feedback Function(s)" @@ -167,8 +167,7 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "11d1f315", + "id": "fcfce0cc", "metadata": {}, "outputs": [], "source": [ @@ -184,7 +183,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "2002422b", + "id": "0c23d029", "metadata": {}, "source": [ "## Instrument chain for logging with TruLens" @@ -193,7 +192,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8b6dda74", + "id": "a07c1fb1", "metadata": {}, "outputs": [], "source": [ @@ -205,7 +204,7 @@ { "cell_type": "code", "execution_count": null, - "id": "faf179c3", + "id": "7a632846", "metadata": {}, "outputs": [], "source": [ @@ -217,7 +216,7 @@ }, { "cell_type": "markdown", - "id": "a1e95335", + "id": "6bacc4fc", "metadata": {}, "source": [ "## Retrieve records and feedback" @@ -226,7 +225,7 @@ { "cell_type": "code", "execution_count": null, - "id": "37b0e597", + "id": "8856f6a0", "metadata": {}, "outputs": [], "source": [ @@ -241,7 +240,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5c1f1720", + "id": "09d4ec4f", "metadata": {}, "outputs": [], "source": [ @@ -263,7 +262,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "8e9293ed", + "id": "d79a1fd0", "metadata": {}, "source": [ "## Explore in a Dashboard" @@ -272,7 +271,7 @@ { "cell_type": "code", "execution_count": null, - "id": "95e4dabd", + "id": "502832e1", "metadata": {}, "outputs": [], "source": [ @@ -284,7 +283,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "85a83b30", + "id": "43ba08ab", "metadata": {}, "source": [ "Alternatively, you can run `trulens-eval` from a command line in the same folder to start the dashboard." @@ -293,7 +292,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "867fbc1c", + "id": "2a22d99d", "metadata": {}, "source": [ "### Chain Leaderboard\n", @@ -326,7 +325,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "5d4329eb", + "id": "a8dff588", "metadata": {}, "source": [ "Note: Feedback functions evaluated in the deferred manner can be seen in the \"Progress\" page of the TruLens dashboard." @@ -335,7 +334,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "06bc5f81", + "id": "2790a01c", "metadata": {}, "source": [ "## Or view results directly in your notebook" @@ -344,7 +343,7 @@ { "cell_type": "code", "execution_count": null, - "id": "feb52898", + "id": "b2292133", "metadata": {}, "outputs": [], "source": [ diff --git a/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb b/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb index c46ac0330..d6f06c562 100644 --- a/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb +++ b/trulens_eval/examples/quickstart/colab/llama_index_quickstart_colab.ipynb @@ -17,7 +17,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "8d9feb48", + "id": "c5eaac4f", "metadata": {}, "source": [ "# Llama-Index Quickstart\n", @@ -32,7 +32,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "7592f07c", + "id": "3748542b", "metadata": {}, "source": [ "## Setup\n", @@ -44,17 +44,17 @@ { "cell_type": "code", "execution_count": null, - "id": "ab35c4a0", + "id": "f446f16a", "metadata": {}, "outputs": [], "source": [ - "# pip install trulens-eval==0.17.0a llama_index>=0.8.29post1 html2text>=2020.1.16" + "# pip install trulens-eval==0.17.0b llama_index>=0.8.29post1 html2text>=2020.1.16" ] }, { "attachments": {}, "cell_type": "markdown", - "id": "9e61fca6", + "id": "cd5b5573", "metadata": {}, "source": [ "### Add API keys\n", @@ -64,7 +64,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ccadc9ac", + "id": "486ad3fa", "metadata": {}, "outputs": [], "source": [ @@ -75,7 +75,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "2475410a", + "id": "93b4e1db", "metadata": {}, "source": [ "### Import from LlamaIndex and TruLens" @@ -84,7 +84,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3aa6d6af", + "id": "e8b7313d", "metadata": {}, "outputs": [], "source": [ @@ -98,7 +98,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "03d62c4e", + "id": "887948e0", "metadata": {}, "source": [ "### Create Simple LLM Application\n", @@ -109,7 +109,7 @@ { "cell_type": "code", "execution_count": null, - "id": "654c2513", + "id": "1062b008", "metadata": {}, "outputs": [], "source": [ @@ -126,7 +126,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "64e61c9a", + "id": "70210c29", "metadata": {}, "source": [ "### Send your first request" @@ -135,7 +135,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ce91006b", + "id": "fc57d186", "metadata": {}, "outputs": [], "source": [ @@ -146,7 +146,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "d280ff6d", + "id": "c5dfae8e", "metadata": {}, "source": [ "## Initialize Feedback Function(s)" @@ -155,7 +155,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7562f17a", + "id": "7a0815f3", "metadata": {}, "outputs": [], "source": [ @@ -184,7 +184,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "60814999", + "id": "f1673633", "metadata": {}, "source": [ "## Instrument app for logging with TruLens" @@ -193,7 +193,7 @@ { "cell_type": "code", "execution_count": null, - "id": "834a4ed4", + "id": "93d0c4c8", "metadata": {}, "outputs": [], "source": [ @@ -205,7 +205,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2e9e73c4", + "id": "3a6c44b6", "metadata": {}, "outputs": [], "source": [ @@ -217,7 +217,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "76beb4b4", + "id": "5fe5388d", "metadata": {}, "source": [ "## Explore in a Dashboard" @@ -226,7 +226,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6fb3d7f4", + "id": "68e6599e", "metadata": {}, "outputs": [], "source": [ @@ -238,7 +238,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "a305729f", + "id": "de40b12b", "metadata": {}, "source": [ "Alternatively, you can run `trulens-eval` from a command line in the same folder to start the dashboard." @@ -247,7 +247,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "0e6066be", + "id": "5d60f5e6", "metadata": {}, "source": [ "Note: Feedback functions evaluated in the deferred manner can be seen in the \"Progress\" page of the TruLens dashboard." @@ -256,7 +256,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "9bb9aa57", + "id": "d1820e9b", "metadata": {}, "source": [ "## Or view results directly in your notebook" @@ -265,7 +265,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5f9fa905", + "id": "a99a5872", "metadata": {}, "outputs": [], "source": [ diff --git a/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb b/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb index 3f144a8ec..b70026894 100644 --- a/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb +++ b/trulens_eval/examples/quickstart/colab/text2text_quickstart_colab.ipynb @@ -17,7 +17,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "0ecbdfa3", + "id": "717a6a81", "metadata": {}, "source": [ "# Text to Text Quickstart\n", @@ -30,17 +30,17 @@ { "cell_type": "code", "execution_count": null, - "id": "876032a8", + "id": "9b54e4ad", "metadata": {}, "outputs": [], "source": [ - "# ! pip install trulens_eval==0.17.0a" + "# ! pip install trulens_eval==0.17.0b" ] }, { "attachments": {}, "cell_type": "markdown", - "id": "bab73ba7", + "id": "6c510cc1", "metadata": {}, "source": [ "## Setup\n", @@ -51,7 +51,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e05e8c4f", + "id": "b060d97a", "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ { "cell_type": "code", "execution_count": null, - "id": "db07936d", + "id": "9ae903cc", "metadata": {}, "outputs": [], "source": [ @@ -74,7 +74,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "7b67eb2e", + "id": "a7a7da5e", "metadata": {}, "source": [ "### Import from TruLens" @@ -83,7 +83,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3564582a", + "id": "0d1505d2", "metadata": {}, "outputs": [], "source": [ @@ -97,7 +97,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "541d99ec", + "id": "3d72e8d8", "metadata": {}, "source": [ "### Create Simple Text to Text Application\n", @@ -108,7 +108,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d8ebea10", + "id": "7b493645", "metadata": {}, "outputs": [], "source": [ @@ -125,7 +125,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b523e5be", + "id": "c51c54c4", "metadata": {}, "outputs": [], "source": [ @@ -138,7 +138,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "fca07271", + "id": "f4d1a935", "metadata": {}, "source": [ "### Send your first request" @@ -147,7 +147,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e233960e", + "id": "822fe3d7", "metadata": {}, "outputs": [], "source": [ @@ -159,7 +159,7 @@ { "cell_type": "code", "execution_count": null, - "id": "541d9269", + "id": "77242a92", "metadata": {}, "outputs": [], "source": [ @@ -169,7 +169,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "f767bfc2", + "id": "deabb675", "metadata": {}, "source": [ "## Initialize Feedback Function(s)" @@ -178,7 +178,7 @@ { "cell_type": "code", "execution_count": null, - "id": "84545974", + "id": "6edab32b", "metadata": {}, "outputs": [], "source": [ @@ -192,7 +192,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "866790f4", + "id": "28e20b8d", "metadata": {}, "source": [ "## Instrument the callable for logging with TruLens" @@ -201,7 +201,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9982869c", + "id": "749cf951", "metadata": {}, "outputs": [], "source": [ @@ -213,7 +213,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e6552e92", + "id": "c9cc017d", "metadata": {}, "outputs": [], "source": [ @@ -224,7 +224,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9b455c6a", + "id": "557e6dea", "metadata": {}, "outputs": [], "source": [ @@ -235,7 +235,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "256dc9e5", + "id": "e7204a01", "metadata": {}, "source": [ "## Explore in a Dashboard" @@ -244,7 +244,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e67635bd", + "id": "3930557c", "metadata": {}, "outputs": [], "source": [ @@ -256,7 +256,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "bc8ab2b1", + "id": "ffd15b23", "metadata": {}, "source": [ "Alternatively, you can run `trulens-eval` from a command line in the same folder to start the dashboard." @@ -265,7 +265,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "2e583555", + "id": "40bf50bb", "metadata": {}, "source": [ "## Or view results directly in your notebook" @@ -274,7 +274,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6b33bd3a", + "id": "0279d417", "metadata": {}, "outputs": [], "source": [ diff --git a/trulens_eval/examples/quickstart/langchain_async.ipynb b/trulens_eval/examples/quickstart/langchain_async.ipynb index 93e45f3e8..a35bf8d8f 100644 --- a/trulens_eval/examples/quickstart/langchain_async.ipynb +++ b/trulens_eval/examples/quickstart/langchain_async.ipynb @@ -28,7 +28,7 @@ "metadata": {}, "outputs": [], "source": [ - "# ! pip install trulens_eval==0.17.0a langchain>=0.0.263" + "# ! pip install trulens_eval==0.17.0b langchain>=0.0.263" ] }, { diff --git a/trulens_eval/examples/quickstart/langchain_quickstart.ipynb b/trulens_eval/examples/quickstart/langchain_quickstart.ipynb index f941d1a9a..d7ff96432 100644 --- a/trulens_eval/examples/quickstart/langchain_quickstart.ipynb +++ b/trulens_eval/examples/quickstart/langchain_quickstart.ipynb @@ -18,7 +18,7 @@ "metadata": {}, "outputs": [], "source": [ - "# ! pip install trulens_eval==0.17.0a langchain>=0.0.263" + "# ! pip install trulens_eval==0.17.0b langchain>=0.0.263" ] }, { diff --git a/trulens_eval/examples/quickstart/langchain_retrieval_agent.ipynb b/trulens_eval/examples/quickstart/langchain_retrieval_agent.ipynb index 553e53297..03e84106e 100644 --- a/trulens_eval/examples/quickstart/langchain_retrieval_agent.ipynb +++ b/trulens_eval/examples/quickstart/langchain_retrieval_agent.ipynb @@ -23,7 +23,7 @@ "metadata": {}, "outputs": [], "source": [ - "#! pip install trulens_eval==0.17.0a langchain==0.0.315 unstructured==0.10.23 chromadb==0.4.14" + "#! pip install trulens_eval==0.17.0b langchain==0.0.315 unstructured==0.10.23 chromadb==0.4.14" ] }, { diff --git a/trulens_eval/examples/quickstart/llama_index_async.ipynb b/trulens_eval/examples/quickstart/llama_index_async.ipynb index bd5cdc066..84324128d 100644 --- a/trulens_eval/examples/quickstart/llama_index_async.ipynb +++ b/trulens_eval/examples/quickstart/llama_index_async.ipynb @@ -24,7 +24,7 @@ "metadata": {}, "outputs": [], "source": [ - "# ! pip install trulens_eval==0.17.0a llama_index>=0.8.29post1 html2text>=2020.1.16" + "# ! pip install trulens_eval==0.17.0b llama_index>=0.8.29post1 html2text>=2020.1.16" ] }, { diff --git a/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb b/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb index b79513c9c..3b8432ec2 100644 --- a/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb +++ b/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb @@ -31,7 +31,7 @@ "metadata": {}, "outputs": [], "source": [ - "# pip install trulens-eval==0.17.0a llama_index>=0.8.29post1 html2text>=2020.1.16" + "# pip install trulens-eval==0.17.0b llama_index>=0.8.29post1 html2text>=2020.1.16" ] }, { diff --git a/trulens_eval/examples/quickstart/pinecone_quickstart.ipynb b/trulens_eval/examples/quickstart/pinecone_quickstart.ipynb index 0d7e121ce..3eda015b9 100644 --- a/trulens_eval/examples/quickstart/pinecone_quickstart.ipynb +++ b/trulens_eval/examples/quickstart/pinecone_quickstart.ipynb @@ -29,7 +29,7 @@ "metadata": {}, "outputs": [], "source": [ - "#! pip install trulens-eval==0.17.0a llama_index>=0.8.29post1 pinecone-client>=2.2.2 nltk>=3.8.1 html2text>=2020.1.16" + "#! pip install trulens-eval==0.17.0b llama_index>=0.8.29post1 pinecone-client>=2.2.2 nltk>=3.8.1 html2text>=2020.1.16" ] }, { diff --git a/trulens_eval/examples/quickstart/prototype_evals.ipynb b/trulens_eval/examples/quickstart/prototype_evals.ipynb index 26ce6c256..5eb82ee14 100644 --- a/trulens_eval/examples/quickstart/prototype_evals.ipynb +++ b/trulens_eval/examples/quickstart/prototype_evals.ipynb @@ -32,7 +32,7 @@ "metadata": {}, "outputs": [], "source": [ - "#! pip install trulens-eval==0.17.0a" + "#! pip install trulens-eval==0.17.0b" ] }, { diff --git a/trulens_eval/examples/quickstart/py_script_quickstarts/all_tools.py b/trulens_eval/examples/quickstart/py_script_quickstarts/all_tools.py index 6cff6225e..a481ce8ae 100644 --- a/trulens_eval/examples/quickstart/py_script_quickstarts/all_tools.py +++ b/trulens_eval/examples/quickstart/py_script_quickstarts/all_tools.py @@ -2,14 +2,14 @@ # coding: utf-8 # # Langchain Quickstart -# +# # In this quickstart you will create a simple LLM Chain and learn how to log it and get feedback on an LLM response. -# +# # [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/main/trulens_eval/examples/quickstart/langchain_quickstart.ipynb) # In[ ]: -# ! pip install trulens_eval==0.17.0a langchain>=0.0.263 +# ! pip install trulens_eval==0.17.0b langchain>=0.0.263 # ## Setup # ### Add API keys @@ -17,24 +17,22 @@ # In[ ]: -import os +import os os.environ["OPENAI_API_KEY"] = "..." os.environ["HUGGINGFACE_API_KEY"] = "..." + # ### Import from LangChain and TruLens # In[ ]: + from IPython.display import JSON # Imports main tools: -from trulens_eval import Feedback -from trulens_eval import Huggingface -from trulens_eval import Tru -from trulens_eval import TruChain +from trulens_eval import TruChain, Feedback, Huggingface, Tru from trulens_eval.schema import FeedbackResult - tru = Tru() # Imports from langchain to build app. You may need to install langchain first @@ -42,16 +40,17 @@ # ! pip install langchain>=0.0.170 from langchain.chains import LLMChain from langchain.llms import OpenAI -from langchain.prompts.chat import ChatPromptTemplate +from langchain.prompts.chat import ChatPromptTemplate, PromptTemplate from langchain.prompts.chat import HumanMessagePromptTemplate -from langchain.prompts.chat import PromptTemplate + # ### Create Simple LLM Application -# +# # This example uses a LangChain framework and OpenAI LLM # In[ ]: + full_prompt = HumanMessagePromptTemplate( prompt=PromptTemplate( template= @@ -66,22 +65,28 @@ chain = LLMChain(llm=llm, prompt=chat_prompt_template, verbose=True) + # ### Send your first request # In[ ]: + prompt_input = '¿que hora es?' + # In[ ]: + llm_response = chain(prompt_input) display(llm_response) + # ## Initialize Feedback Function(s) # In[ ]: + # Initialize Huggingface-based feedback function collection class: hugs = Huggingface() @@ -90,82 +95,93 @@ # By default this will check language match on the main app input and main app # output. + # ## Instrument chain for logging with TruLens # In[ ]: -tru_recorder = TruChain( - chain, app_id='Chain1_ChatApplication', feedbacks=[f_lang_match] -) + +tru_recorder = TruChain(chain, + app_id='Chain1_ChatApplication', + feedbacks=[f_lang_match]) + # In[ ]: + with tru_recorder as recording: llm_response = chain(prompt_input) display(llm_response) + # ## Retrieve records and feedback # In[ ]: + # The record of the ap invocation can be retrieved from the `recording`: -rec = recording.get() # use .get if only one record +rec = recording.get() # use .get if only one record # recs = recording.records # use .records if multiple display(rec) + # In[ ]: + # The results of the feedback functions can be rertireved from the record. These # are `Future` instances (see `concurrent.futures`). You can use `as_completed` # to wait until they have finished evaluating. from concurrent.futures import as_completed -for feedback_future in as_completed(rec.feedback_results): +for feedback_future in as_completed(rec.feedback_results): feedback, feedback_result = feedback_future.result() - + feedback: Feedback feedbac_result: FeedbackResult display(feedback.name, feedback_result.result) + # ## Explore in a Dashboard # In[ ]: -tru.run_dashboard() # open a local streamlit app to explore + +tru.run_dashboard() # open a local streamlit app to explore # tru.stop_dashboard() # stop if needed + # Alternatively, you can run `trulens-eval` from a command line in the same folder to start the dashboard. # ### Chain Leaderboard -# +# # Understand how your LLM application is performing at a glance. Once you've set up logging and evaluation in your application, you can view key performance statistics including cost and average feedback value across all of your LLM apps using the chain leaderboard. As you iterate new versions of your LLM application, you can compare their performance across all of the different quality metrics you've set up. -# +# # Note: Average feedback values are returned and displayed in a range from 0 (worst) to 1 (best). -# +# # ![Chain Leaderboard](https://www.trulens.org/assets/images/Leaderboard.png) -# +# # To dive deeper on a particular chain, click "Select Chain". -# +# # ### Understand chain performance with Evaluations -# +# # To learn more about the performance of a particular chain or LLM model, we can select it to view its evaluations at the record level. LLM quality is assessed through the use of feedback functions. Feedback functions are extensible methods for determining the quality of LLM responses and can be applied to any downstream LLM task. Out of the box we provide a number of feedback functions for assessing model agreement, sentiment, relevance and more. -# +# # The evaluations tab provides record-level metadata and feedback on the quality of your LLM application. -# +# # ![Evaluations](https://www.trulens.org/assets/images/Leaderboard.png) -# +# # ### Deep dive into full chain metadata -# +# # Click on a record to dive deep into all of the details of your chain stack and underlying LLM, captured by tru_chain_recorder. -# +# # ![Explore a Chain](https://www.trulens.org/assets/images/Chain_Explore.png) -# +# # If you prefer the raw format, you can quickly get it using the "Display full chain json" or "Display full record json" buttons at the bottom of the page. # Note: Feedback functions evaluated in the deferred manner can be seen in the "Progress" page of the TruLens dashboard. @@ -174,104 +190,129 @@ # In[ ]: -tru.get_records_and_feedback(app_ids=[] - )[0] # pass an empty list of app_ids to get all + +tru.get_records_and_feedback(app_ids=[])[0] # pass an empty list of app_ids to get all + # # Logging Methods -# +# # ## Automatic Logging -# +# # The simplest method for logging with TruLens is by wrapping with TruChain and including the tru argument, as shown in the quickstart. -# +# # This is done like so: # In[ ]: -truchain = TruChain(chain, app_id='Chain1_ChatApplication', tru=tru) + +truchain = TruChain( + chain, + app_id='Chain1_ChatApplication', + tru=tru +) truchain("This will be automatically logged.") + # Feedback functions can also be logged automatically by providing them in a list to the feedbacks arg. # In[ ]: + truchain = TruChain( chain, app_id='Chain1_ChatApplication', - feedbacks=[f_lang_match], # feedback functions + feedbacks=[f_lang_match], # feedback functions tru=tru ) truchain("This will be automatically logged.") + # ## Manual Logging -# +# # ### Wrap with TruChain to instrument your chain # In[ ]: + tc = TruChain(chain, app_id='Chain1_ChatApplication') + # ### Set up logging and instrumentation -# +# # Making the first call to your wrapped LLM Application will now also produce a log or "record" of the chain execution. -# +# # In[ ]: + prompt_input = 'que hora es?' gpt3_response, record = tc.call_with_record(prompt_input) + # We can log the records but first we need to log the chain itself. # In[ ]: + tru.add_app(app=truchain) + # Then we can log the record: # In[ ]: + tru.add_record(record) + # ### Log App Feedback # Capturing app feedback such as user feedback of the responses can be added with one call. # In[ ]: + thumb_result = True -tru.add_feedback( - name="👍 (1) or 👎 (0)", record_id=record.record_id, result=thumb_result -) +tru.add_feedback(name="👍 (1) or 👎 (0)", + record_id=record.record_id, + result=thumb_result) + # ### Evaluate Quality -# +# # Following the request to your app, you can then evaluate LLM quality using feedback functions. This is completed in a sequential call to minimize latency for your application, and evaluations will also be logged to your local machine. -# +# # To get feedback on the quality of your LLM, you can use any of the provided feedback functions or add your own. -# +# # To assess your LLM quality, you can provide the feedback functions to `tru.run_feedback()` in a list provided to `feedback_functions`. -# +# # In[ ]: + feedback_results = tru.run_feedback_functions( - record=record, feedback_functions=[f_lang_match] + record=record, + feedback_functions=[f_lang_match] ) display(feedback_results) + # After capturing feedback, you can then log it to your local database. # In[ ]: + tru.add_feedbacks(feedback_results) + # ### Out-of-band Feedback evaluation -# +# # In the above example, the feedback function evaluation is done in the same process as the chain evaluation. The alternative approach is the use the provided persistent evaluator started via `tru.start_deferred_feedback_evaluator`. Then specify the `feedback_mode` for `TruChain` as `deferred` to let the evaluator handle the feedback functions. -# +# # For demonstration purposes, we start the evaluator here but it can be started in another process. # In[ ]: + truchain: TruChain = TruChain( chain, app_id='Chain1_ChatApplication', @@ -284,25 +325,22 @@ truchain("This will be logged by deferred evaluator.") tru.stop_evaluator() + # # Custom Functions -# +# # Feedback functions are an extensible framework for evaluating LLMs. You can add your own feedback functions to evaluate the qualities required by your application by updating `trulens_eval/feedback.py`, or simply creating a new provider class and feedback function in youre notebook. If your contributions would be useful for others, we encourage you to contribute to TruLens! -# +# # Feedback functions are organized by model provider into Provider classes. -# +# # The process for adding new feedback functions is: # 1. Create a new Provider class or locate an existing one that applies to your feedback function. If your feedback function does not rely on a model provider, you can create a standalone class. Add the new feedback function method to your selected class. Your new method can either take a single text (str) as a parameter or both prompt (str) and response (str). It should return a float between 0 (worst) and 1 (best). # In[ ]: -from trulens_eval import Feedback -from trulens_eval import Provider -from trulens_eval import Select -from trulens_eval import Tru +from trulens_eval import Provider, Feedback, Select, Tru class StandAlone(Provider): - def custom_feedback(self, my_text_field: str) -> float: """ A dummy function of text inputs to float outputs. @@ -320,53 +358,57 @@ def custom_feedback(self, my_text_field: str) -> float: # In[ ]: + standalone = StandAlone() -f_custom_function = Feedback(standalone.custom_feedback - ).on(my_text_field=Select.RecordOutput) +f_custom_function = Feedback(standalone.custom_feedback).on( + my_text_field=Select.RecordOutput +) + # 3. Your feedback function is now ready to use just like the out of the box feedback functions. Below is an example of it being used. # In[ ]: + tru = Tru() feedback_results = tru.run_feedback_functions( - record=record, feedback_functions=[f_custom_function] + record=record, + feedback_functions=[f_custom_function] ) tru.add_feedbacks(feedback_results) + # ## Multi-Output Feedback functions # Trulens also supports multi-output feedback functions. As a typical feedback function will output a float between 0 and 1, multi-output should output a dictionary of `output_key` to a float between 0 and 1. The feedbacks table will display the feedback with column `feedback_name:::outputkey` # In[ ]: -multi_output_feedback = Feedback( - lambda input_param: { - 'output_key1': 0.1, - 'output_key2': 0.9 - }, name="multi" -).on(input_param=Select.RecordOutput) + +multi_output_feedback = Feedback(lambda input_param: {'output_key1': 0.1, 'output_key2': 0.9}, name="multi").on( + input_param=Select.RecordOutput +) feedback_results = tru.run_feedback_functions( - record=record, feedback_functions=[multi_output_feedback] + record=record, + feedback_functions=[multi_output_feedback] ) tru.add_feedbacks(feedback_results) + # In[ ]: + # Aggregators will run on the same dict keys. import numpy as np - -multi_output_feedback = Feedback( - lambda input_param: { - 'output_key1': 0.1, - 'output_key2': 0.9 - }, - name="multi-agg" -).on(input_param=Select.RecordOutput).aggregate(np.mean) +multi_output_feedback = Feedback(lambda input_param: {'output_key1': 0.1, 'output_key2': 0.9}, name="multi-agg").on( + input_param=Select.RecordOutput +).aggregate(np.mean) feedback_results = tru.run_feedback_functions( - record=record, feedback_functions=[multi_output_feedback] + record=record, + feedback_functions=[multi_output_feedback] ) tru.add_feedbacks(feedback_results) + # In[ ]: @@ -376,16 +418,12 @@ def dict_aggregator(list_dict_input): for dict_input in list_dict_input: agg += dict_input['output_key1'] return agg - - -multi_output_feedback = Feedback( - lambda input_param: { - 'output_key1': 0.1, - 'output_key2': 0.9 - }, - name="multi-agg-dict" -).on(input_param=Select.RecordOutput).aggregate(dict_aggregator) +multi_output_feedback = Feedback(lambda input_param: {'output_key1': 0.1, 'output_key2': 0.9}, name="multi-agg-dict").on( + input_param=Select.RecordOutput +).aggregate(dict_aggregator) feedback_results = tru.run_feedback_functions( - record=record, feedback_functions=[multi_output_feedback] + record=record, + feedback_functions=[multi_output_feedback] ) tru.add_feedbacks(feedback_results) + diff --git a/trulens_eval/examples/quickstart/py_script_quickstarts/langchain_quickstart.py b/trulens_eval/examples/quickstart/py_script_quickstarts/langchain_quickstart.py index 25ba7d2c9..e428e49d1 100644 --- a/trulens_eval/examples/quickstart/py_script_quickstarts/langchain_quickstart.py +++ b/trulens_eval/examples/quickstart/py_script_quickstarts/langchain_quickstart.py @@ -2,14 +2,14 @@ # coding: utf-8 # # Langchain Quickstart -# +# # In this quickstart you will create a simple LLM Chain and learn how to log it and get feedback on an LLM response. -# +# # [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/main/trulens_eval/examples/quickstart/langchain_quickstart.ipynb) # In[ ]: -# ! pip install trulens_eval==0.17.0a langchain>=0.0.263 +# ! pip install trulens_eval==0.17.0b langchain>=0.0.263 # ## Setup # ### Add API keys @@ -17,24 +17,22 @@ # In[ ]: -import os +import os os.environ["OPENAI_API_KEY"] = "..." os.environ["HUGGINGFACE_API_KEY"] = "..." + # ### Import from LangChain and TruLens # In[ ]: + from IPython.display import JSON # Imports main tools: -from trulens_eval import Feedback -from trulens_eval import Huggingface -from trulens_eval import Tru -from trulens_eval import TruChain +from trulens_eval import TruChain, Feedback, Huggingface, Tru from trulens_eval.schema import FeedbackResult - tru = Tru() # Imports from langchain to build app. You may need to install langchain first @@ -42,16 +40,17 @@ # ! pip install langchain>=0.0.170 from langchain.chains import LLMChain from langchain.llms import OpenAI -from langchain.prompts.chat import ChatPromptTemplate +from langchain.prompts.chat import ChatPromptTemplate, PromptTemplate from langchain.prompts.chat import HumanMessagePromptTemplate -from langchain.prompts.chat import PromptTemplate + # ### Create Simple LLM Application -# +# # This example uses a LangChain framework and OpenAI LLM # In[ ]: + full_prompt = HumanMessagePromptTemplate( prompt=PromptTemplate( template= @@ -66,22 +65,28 @@ chain = LLMChain(llm=llm, prompt=chat_prompt_template, verbose=True) + # ### Send your first request # In[ ]: + prompt_input = '¿que hora es?' + # In[ ]: + llm_response = chain(prompt_input) display(llm_response) + # ## Initialize Feedback Function(s) # In[ ]: + # Initialize Huggingface-based feedback function collection class: hugs = Huggingface() @@ -90,82 +95,93 @@ # By default this will check language match on the main app input and main app # output. + # ## Instrument chain for logging with TruLens # In[ ]: -tru_recorder = TruChain( - chain, app_id='Chain1_ChatApplication', feedbacks=[f_lang_match] -) + +tru_recorder = TruChain(chain, + app_id='Chain1_ChatApplication', + feedbacks=[f_lang_match]) + # In[ ]: + with tru_recorder as recording: llm_response = chain(prompt_input) display(llm_response) + # ## Retrieve records and feedback # In[ ]: + # The record of the ap invocation can be retrieved from the `recording`: -rec = recording.get() # use .get if only one record +rec = recording.get() # use .get if only one record # recs = recording.records # use .records if multiple display(rec) + # In[ ]: + # The results of the feedback functions can be rertireved from the record. These # are `Future` instances (see `concurrent.futures`). You can use `as_completed` # to wait until they have finished evaluating. from concurrent.futures import as_completed -for feedback_future in as_completed(rec.feedback_results): +for feedback_future in as_completed(rec.feedback_results): feedback, feedback_result = feedback_future.result() - + feedback: Feedback feedbac_result: FeedbackResult display(feedback.name, feedback_result.result) + # ## Explore in a Dashboard # In[ ]: -tru.run_dashboard() # open a local streamlit app to explore + +tru.run_dashboard() # open a local streamlit app to explore # tru.stop_dashboard() # stop if needed + # Alternatively, you can run `trulens-eval` from a command line in the same folder to start the dashboard. # ### Chain Leaderboard -# +# # Understand how your LLM application is performing at a glance. Once you've set up logging and evaluation in your application, you can view key performance statistics including cost and average feedback value across all of your LLM apps using the chain leaderboard. As you iterate new versions of your LLM application, you can compare their performance across all of the different quality metrics you've set up. -# +# # Note: Average feedback values are returned and displayed in a range from 0 (worst) to 1 (best). -# +# # ![Chain Leaderboard](https://www.trulens.org/assets/images/Leaderboard.png) -# +# # To dive deeper on a particular chain, click "Select Chain". -# +# # ### Understand chain performance with Evaluations -# +# # To learn more about the performance of a particular chain or LLM model, we can select it to view its evaluations at the record level. LLM quality is assessed through the use of feedback functions. Feedback functions are extensible methods for determining the quality of LLM responses and can be applied to any downstream LLM task. Out of the box we provide a number of feedback functions for assessing model agreement, sentiment, relevance and more. -# +# # The evaluations tab provides record-level metadata and feedback on the quality of your LLM application. -# +# # ![Evaluations](https://www.trulens.org/assets/images/Leaderboard.png) -# +# # ### Deep dive into full chain metadata -# +# # Click on a record to dive deep into all of the details of your chain stack and underlying LLM, captured by tru_chain_recorder. -# +# # ![Explore a Chain](https://www.trulens.org/assets/images/Chain_Explore.png) -# +# # If you prefer the raw format, you can quickly get it using the "Display full chain json" or "Display full record json" buttons at the bottom of the page. # Note: Feedback functions evaluated in the deferred manner can be seen in the "Progress" page of the TruLens dashboard. @@ -174,5 +190,6 @@ # In[ ]: -tru.get_records_and_feedback(app_ids=[] - )[0] # pass an empty list of app_ids to get all + +tru.get_records_and_feedback(app_ids=[])[0] # pass an empty list of app_ids to get all + diff --git a/trulens_eval/examples/quickstart/py_script_quickstarts/llama_index_quickstart.py b/trulens_eval/examples/quickstart/py_script_quickstarts/llama_index_quickstart.py index 43724660e..a283f5249 100644 --- a/trulens_eval/examples/quickstart/py_script_quickstarts/llama_index_quickstart.py +++ b/trulens_eval/examples/quickstart/py_script_quickstarts/llama_index_quickstart.py @@ -2,70 +2,75 @@ # coding: utf-8 # # Llama-Index Quickstart -# +# # In this quickstart you will create a simple Llama Index App and learn how to log it and get feedback on an LLM response. -# +# # For evaluation, we will leverage the "hallucination triad" of groundedness, context relevance and answer relevance. -# +# # [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/main/trulens_eval/examples/quickstart/llama_index_quickstart.ipynb) # ## Setup -# +# # ### Install dependencies # Let's install some of the dependencies for this notebook if we don't have them already # In[ ]: -# pip install trulens-eval==0.17.0a llama_index>=0.8.29post1 html2text>=2020.1.16 +# pip install trulens-eval==0.17.0b llama_index>=0.8.29post1 html2text>=2020.1.16 # ### Add API keys # For this quickstart, you will need Open AI and Huggingface keys. The OpenAI key is used for embeddings and GPT, and the Huggingface key is used for evaluation. # In[ ]: -import os +import os os.environ["OPENAI_API_KEY"] = "..." + # ### Import from LlamaIndex and TruLens # In[ ]: -from trulens_eval import Feedback -from trulens_eval import Tru -from trulens_eval import TruLlama + +from trulens_eval import Feedback, Tru, TruLlama from trulens_eval.feedback import Groundedness from trulens_eval.feedback.provider.openai import OpenAI tru = Tru() + # ### Create Simple LLM Application -# +# # This example uses LlamaIndex which internally uses an OpenAI LLM. # In[ ]: -from llama_index import SimpleWebPageReader -from llama_index import VectorStoreIndex -documents = SimpleWebPageReader(html_to_text=True).load_data( - ["http://paulgraham.com/worked.html"] -) +from llama_index import VectorStoreIndex, SimpleWebPageReader + +documents = SimpleWebPageReader( + html_to_text=True +).load_data(["http://paulgraham.com/worked.html"]) index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine() + # ### Send your first request # In[ ]: + response = query_engine.query("What did the author do growing up?") print(response) + # ## Initialize Feedback Function(s) # In[ ]: + import numpy as np # Initialize provider class @@ -76,7 +81,8 @@ # Define a groundedness feedback function f_groundedness = Feedback(grounded.groundedness_measure_with_cot_reasons).on( TruLlama.select_source_nodes().node.text -).on_output().aggregate(grounded.grounded_statements_aggregator) + ).on_output( + ).aggregate(grounded.grounded_statements_aggregator) # Question/answer relevance between overall question and answer. f_qa_relevance = Feedback(openai.relevance).on_input_output() @@ -84,32 +90,37 @@ # Question/statement relevance between question and each context chunk. f_qs_relevance = Feedback(openai.qs_relevance).on_input().on( TruLlama.select_source_nodes().node.text -).aggregate(np.mean) + ).aggregate(np.mean) + # ## Instrument app for logging with TruLens # In[ ]: -tru_query_engine_recorder = TruLlama( - query_engine, + +tru_query_engine_recorder = TruLlama(query_engine, app_id='LlamaIndex_App1', - feedbacks=[f_groundedness, f_qa_relevance, f_qs_relevance] -) + feedbacks=[f_groundedness, f_qa_relevance, f_qs_relevance]) + # In[ ]: + # or as context manager with tru_query_engine_recorder as recording: query_engine.query("What did the author do growing up?") + # ## Explore in a Dashboard # In[ ]: -tru.run_dashboard() # open a local streamlit app to explore + +tru.run_dashboard() # open a local streamlit app to explore # tru.stop_dashboard() # stop if needed + # Alternatively, you can run `trulens-eval` from a command line in the same folder to start the dashboard. # Note: Feedback functions evaluated in the deferred manner can be seen in the "Progress" page of the TruLens dashboard. @@ -118,5 +129,6 @@ # In[ ]: -tru.get_records_and_feedback(app_ids=[] - )[0] # pass an empty list of app_ids to get all + +tru.get_records_and_feedback(app_ids=[])[0] # pass an empty list of app_ids to get all + diff --git a/trulens_eval/examples/quickstart/py_script_quickstarts/text2text_quickstart.py b/trulens_eval/examples/quickstart/py_script_quickstarts/text2text_quickstart.py index 66c8552c9..bb78d5008 100644 --- a/trulens_eval/examples/quickstart/py_script_quickstarts/text2text_quickstart.py +++ b/trulens_eval/examples/quickstart/py_script_quickstarts/text2text_quickstart.py @@ -2,14 +2,14 @@ # coding: utf-8 # # Text to Text Quickstart -# +# # In this quickstart you will create a simple text to text application and learn how to log it and get feedback. -# +# # [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/truera/trulens/blob/main/trulens_eval/examples/quickstart/text2text_quickstart.ipynb) # In[ ]: -# ! pip install trulens_eval==0.17.0a +# ! pip install trulens_eval==0.17.0b # ## Setup # ### Add API keys @@ -17,32 +17,33 @@ # In[ ]: -import os +import os os.environ["OPENAI_API_KEY"] = "..." os.environ["HUGGINGFACE_API_KEY"] = "..." + # In[ ]: -import openai +import openai openai.api_key = os.environ["OPENAI_API_KEY"] + # ### Import from TruLens # In[ ]: + from IPython.display import JSON # Imports main tools: -from trulens_eval import Feedback -from trulens_eval import Huggingface -from trulens_eval import Tru - +from trulens_eval import Feedback, Huggingface, Tru tru = Tru() + # ### Create Simple Text to Text Application -# +# # This example uses a bare bones OpenAI LLM, and a non-LLM just for demonstration purposes. # In[ ]: @@ -50,26 +51,18 @@ def llm_standalone(prompt): return openai.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=[ - { - "role": - "system", - "content": - "You are a question and answer bot, and you answer super upbeat." - }, { - "role": "user", - "content": prompt - } + model="gpt-3.5-turbo", + messages=[ + {"role": "system", "content": "You are a question and answer bot, and you answer super upbeat."}, + {"role": "user", "content": prompt} ] )["choices"][0]["message"]["content"] # In[ ]: -import hashlib - +import hashlib def simple_hash_callable(prompt): h = hashlib.shake_256(prompt.encode('utf-8')) return str(h.hexdigest(20)) @@ -79,60 +72,70 @@ def simple_hash_callable(prompt): # In[ ]: -prompt_input = "How good is language AI?" + +prompt_input="How good is language AI?" prompt_output = llm_standalone(prompt_input) prompt_output + # In[ ]: + simple_hash_callable(prompt_input) + # ## Initialize Feedback Function(s) # In[ ]: + # Initialize Huggingface-based feedback function collection class: hugs = Huggingface() # Define a sentiment feedback function using HuggingFace. f_sentiment = Feedback(hugs.positive_sentiment).on_output() + # ## Instrument the callable for logging with TruLens # In[ ]: + from trulens_eval import TruBasicApp +tru_llm_standalone_recorder = TruBasicApp(llm_standalone, app_id="Happy Bot", feedbacks=[f_sentiment]) +tru_simple_hash_callable_recorder = TruBasicApp(simple_hash_callable, app_id="Hasher", feedbacks=[f_sentiment]) -tru_llm_standalone_recorder = TruBasicApp( - llm_standalone, app_id="Happy Bot", feedbacks=[f_sentiment] -) -tru_simple_hash_callable_recorder = TruBasicApp( - simple_hash_callable, app_id="Hasher", feedbacks=[f_sentiment] -) # In[ ]: + with tru_llm_standalone_recorder as recording: tru_llm_standalone_recorder.app(prompt_input) + # In[ ]: + with tru_simple_hash_callable_recorder as recording: tru_simple_hash_callable_recorder.app(prompt_input) + # ## Explore in a Dashboard # In[ ]: -tru.run_dashboard() # open a local streamlit app to explore + +tru.run_dashboard() # open a local streamlit app to explore # tru.stop_dashboard() # stop if needed + # Alternatively, you can run `trulens-eval` from a command line in the same folder to start the dashboard. # ## Or view results directly in your notebook # In[ ]: -tru.get_records_and_feedback(app_ids=[] - )[0] # pass an empty list of app_ids to get all + +tru.get_records_and_feedback(app_ids=[])[0] # pass an empty list of app_ids to get all + diff --git a/trulens_eval/examples/quickstart/summarization_eval.ipynb b/trulens_eval/examples/quickstart/summarization_eval.ipynb index 2ee2c4309..94aaafe46 100644 --- a/trulens_eval/examples/quickstart/summarization_eval.ipynb +++ b/trulens_eval/examples/quickstart/summarization_eval.ipynb @@ -32,7 +32,7 @@ "metadata": {}, "outputs": [], "source": [ - "\"\"\"!pip install trulens_eval==0.17.0a\n", + "\"\"\"!pip install trulens_eval==0.17.0b\n", " bert_score==0.3.13 \\\n", " evaluate==0.4.0 \\\n", " absl-py==1.4.0 \\\n", diff --git a/trulens_eval/examples/quickstart/text2text_quickstart.ipynb b/trulens_eval/examples/quickstart/text2text_quickstart.ipynb index 51014f5dc..4ff94fa4c 100644 --- a/trulens_eval/examples/quickstart/text2text_quickstart.ipynb +++ b/trulens_eval/examples/quickstart/text2text_quickstart.ipynb @@ -18,7 +18,7 @@ "metadata": {}, "outputs": [], "source": [ - "# ! pip install trulens_eval==0.17.0a" + "# ! pip install trulens_eval==0.17.0b" ] }, { diff --git a/trulens_eval/generated_files/all_tools.ipynb b/trulens_eval/generated_files/all_tools.ipynb index 0fcf669d2..0202cf232 100644 --- a/trulens_eval/generated_files/all_tools.ipynb +++ b/trulens_eval/generated_files/all_tools.ipynb @@ -18,7 +18,7 @@ "metadata": {}, "outputs": [], "source": [ - "# ! pip install trulens_eval==0.17.0a langchain>=0.0.263" + "# ! pip install trulens_eval==0.17.0b langchain>=0.0.263" ] }, { diff --git a/trulens_eval/trulens_eval/__init__.py b/trulens_eval/trulens_eval/__init__.py index 3329b4137..53aef8ed4 100644 --- a/trulens_eval/trulens_eval/__init__.py +++ b/trulens_eval/trulens_eval/__init__.py @@ -78,7 +78,7 @@ """ -__version__ = "0.17.0a" +__version__ = "0.17.0b" from trulens_eval.feedback import Bedrock from trulens_eval.feedback import Feedback