From 1cb53e6727ecffa95ea91da51a39d79ed68c5789 Mon Sep 17 00:00:00 2001 From: Joschka Braun Date: Fri, 8 Sep 2023 17:27:26 -0700 Subject: [PATCH 1/5] fix: fix samples --- .../cookbook/tracing_with_deployed_prompt.py | 22 +++++++++++++------ .../tracing_with_open_ai_endpoint_directly.py | 6 ++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/parea/cookbook/tracing_with_deployed_prompt.py b/parea/cookbook/tracing_with_deployed_prompt.py index c6bcd996..be7774e0 100644 --- a/parea/cookbook/tracing_with_deployed_prompt.py +++ b/parea/cookbook/tracing_with_deployed_prompt.py @@ -1,5 +1,6 @@ import os from datetime import datetime +from typing import Tuple from dotenv import load_dotenv @@ -9,13 +10,13 @@ load_dotenv() -p = Parea(api_key=os.getenv("PAREA_API_KEY")) +p = Parea(api_key="pai-c8dff73cbeca3160e5ebe0b4f51ee1d4ed2f7270d4a149817c8fcb8e8313ca5c") def deployed_argument_generator(query: str, additional_description: str = "") -> str: return p.completion( Completion( - deployment_id="p-Ar-Oi14-nBxHUiradyql9", + deployment_id="p-RG8d9rfJc_0cctwfpb_n6", llm_inputs={ "additional_description": additional_description, "date": f"{datetime.now()}", @@ -28,7 +29,7 @@ def deployed_argument_generator(query: str, additional_description: str = "") -> def deployed_critic(argument: str) -> str: return p.completion( Completion( - deployment_id="p-W2yPy93tAczYrxkipjli6", + deployment_id="p-fXgZytT3dJjXD_71TDR4s", llm_inputs={"argument": argument}, ) ).content @@ -37,7 +38,7 @@ def deployed_critic(argument: str) -> str: def deployed_refiner(query: str, additional_description: str, current_arg: str, criticism: str) -> str: return p.completion( Completion( - deployment_id="p-8Er1Xo0GDGF2xtpmMOpbn", + deployment_id="p--G2s9okMTvBEh3d8YqLY2", llm_inputs={ "additional_description": additional_description, "date": f"{datetime.now()}", @@ -52,7 +53,7 @@ def deployed_refiner(query: str, additional_description: str, current_arg: str, def deployed_refiner2(query: str, additional_description: str, current_arg: str, criticism: str) -> CompletionResponse: return p.completion( Completion( - deployment_id="p-8Er1Xo0GDGF2xtpmMOpbn", + deployment_id="p--G2s9okMTvBEh3d8YqLY2", llm_inputs={ "additional_description": additional_description, "date": f"{datetime.now()}", @@ -71,6 +72,14 @@ def deployed_argument_chain(query: str, additional_description: str = "") -> str return deployed_refiner(query, additional_description, argument, criticism) +@trace +def deployed_argument_chain2(query: str, additional_description: str = "") -> Tuple[str, str]: + trace_id = get_current_trace_id() + argument = deployed_argument_generator(query, additional_description) + criticism = deployed_critic(argument) + return deployed_refiner(query, additional_description, argument, criticism), trace_id + + @trace( tags=["cookbook-example-deployed", "feedback_tracked-deployed"], metadata={"source": "python-sdk", "deployed": True}, @@ -88,11 +97,10 @@ def deployed_argument_chain_tags_metadata(query: str, additional_description: st ) print(result1) - result2 = deployed_argument_chain( + result2, trace_id2 = deployed_argument_chain2( "Whether wine is good for you.", additional_description="Provide a concise, few sentence argument on why wine is good for you.", ) - trace_id2 = get_current_trace_id() print(result2) p.record_feedback( FeedbackRequest( diff --git a/parea/cookbook/tracing_with_open_ai_endpoint_directly.py b/parea/cookbook/tracing_with_open_ai_endpoint_directly.py index 77c8ed8c..6d9683ae 100644 --- a/parea/cookbook/tracing_with_open_ai_endpoint_directly.py +++ b/parea/cookbook/tracing_with_open_ai_endpoint_directly.py @@ -17,6 +17,7 @@ @trace def argument_chain(query: str, additional_description: str = "") -> str: + trace_id = get_current_trace_id() argument = ( openai.ChatCompletion.create( model="gpt-3.5-turbo-0613", @@ -75,15 +76,14 @@ def argument_chain(query: str, additional_description: str = "") -> str: .message["content"] ) - return refined_argument + return refined_argument, trace_id if __name__ == "__main__": - result = argument_chain( + result, trace_id = argument_chain( "Whether sparkling water is good for you.", additional_description="Provide a concise, few sentence argument on why sparkling water is good for you.", ) - trace_id = get_current_trace_id() print(result) p.record_feedback( FeedbackRequest( From 466fb37e8d0a2b0b892b5fe193763c703943e402 Mon Sep 17 00:00:00 2001 From: Joschka Braun Date: Fri, 8 Sep 2023 17:41:56 -0700 Subject: [PATCH 2/5] fix: update notebook --- parea/cookbook/tracing_with_Parea_sdk.ipynb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/parea/cookbook/tracing_with_Parea_sdk.ipynb b/parea/cookbook/tracing_with_Parea_sdk.ipynb index 35a3c079..50b7513a 100644 --- a/parea/cookbook/tracing_with_Parea_sdk.ipynb +++ b/parea/cookbook/tracing_with_Parea_sdk.ipynb @@ -10,7 +10,7 @@ "source": [ "# LLM Tracing\n", "\n", - "With the Parea SDK, you can gain visibility into **any LLM application**. Together with the web application, Parea speeds up your debugging, evaluating, and monitoring workflows. \n", + "With the Parea SDK, you can gain visibility into **any LLM application**. Together with the web application, Parea speeds up your debugging, evaluating, and monitoring workflows.\n", "Parea is also framework and provider-agnostic. Parea traces your prompts and chains, whether deployed from Parea or within your codebase.\n", "\n", "We will create a simple chat app and instrument logging with Parea. We will also add tags and other metadata to enrich our traces. The chat app uses three 'chained' components to generate a text argument on a provided subject:\n", @@ -111,11 +111,10 @@ "p = Parea(api_key=os.getenv(\"PAREA_API_KEY\"))\n", "\n", "\n", - "@trace\n", "def argument_generator(query: str, additional_description: str = \"\") -> str:\n", " return p.completion(\n", " Completion(\n", - " deployment_id=\"p-Ar-Oi14-nBxHUiradyql9\",\n", + " deployment_id=\"p-RG8d9rfJc_0cctwfpb_n6\",\n", " llm_inputs={\n", " \"additional_description\": additional_description,\n", " \"date\": f\"{datetime.now()}\",\n", @@ -125,16 +124,19 @@ " ).content\n", "\n", "\n", - "@trace\n", "def critic(argument: str) -> str:\n", - " return p.completion(Completion(deployment_id=\"p-W2yPy93tAczYrxkipjli6\", llm_inputs={\"argument\": argument})).content\n", + " return p.completion(\n", + " Completion(\n", + " deployment_id=\"p-fXgZytT3dJjXD_71TDR4s\",\n", + " llm_inputs={\"argument\": argument},\n", + " )\n", + " ).content\n", "\n", "\n", - "@trace\n", "def refiner(query: str, additional_description: str, current_arg: str, criticism: str) -> str:\n", " return p.completion(\n", " Completion(\n", - " deployment_id=\"p-8Er1Xo0GDGF2xtpmMOpbn\",\n", + " deployment_id=\"p--G2s9okMTvBEh3d8YqLY2\",\n", " llm_inputs={\n", " \"additional_description\": additional_description,\n", " \"date\": f\"{datetime.now()}\",\n", @@ -283,7 +285,6 @@ "\n", "\n", "# let's return the full CompletionResponse to see what other information is returned\n", - "@trace\n", "def refiner2(query: str, additional_description: str, current_arg: str, criticism: str) -> CompletionResponse:\n", " return p.completion(\n", " Completion(\n", From 1212633b75044cd22f6023fcf364228a566e85b3 Mon Sep 17 00:00:00 2001 From: Joschka Braun Date: Fri, 8 Sep 2023 17:44:21 -0700 Subject: [PATCH 3/5] style --- parea/cookbook/tracing_with_deployed_prompt.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/parea/cookbook/tracing_with_deployed_prompt.py b/parea/cookbook/tracing_with_deployed_prompt.py index be7774e0..5d072896 100644 --- a/parea/cookbook/tracing_with_deployed_prompt.py +++ b/parea/cookbook/tracing_with_deployed_prompt.py @@ -1,7 +1,8 @@ import os -from datetime import datetime from typing import Tuple +from datetime import datetime + from dotenv import load_dotenv from parea import Parea @@ -10,7 +11,7 @@ load_dotenv() -p = Parea(api_key="pai-c8dff73cbeca3160e5ebe0b4f51ee1d4ed2f7270d4a149817c8fcb8e8313ca5c") +p = Parea(api_key=os.getenv('PAREA_API_KEY')) def deployed_argument_generator(query: str, additional_description: str = "") -> str: From 9a97acddb02f1dd68cfefb31967c3c0568910478 Mon Sep 17 00:00:00 2001 From: Joschka Braun Date: Fri, 8 Sep 2023 17:48:20 -0700 Subject: [PATCH 4/5] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d871f467..56e7f086 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "parea-ai" packages = [{ include = "parea" }] -version = "0.2.5" +version = "0.2.6" description = "Parea python sdk" readme = "README.md" authors = ["joel-parea-ai "] From e2bc043e63b10c01dcc1e34934df89209b4e8f33 Mon Sep 17 00:00:00 2001 From: Joschka Braun Date: Fri, 8 Sep 2023 17:49:16 -0700 Subject: [PATCH 5/5] style --- parea/cookbook/tracing_with_deployed_prompt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parea/cookbook/tracing_with_deployed_prompt.py b/parea/cookbook/tracing_with_deployed_prompt.py index 5d072896..058bd04f 100644 --- a/parea/cookbook/tracing_with_deployed_prompt.py +++ b/parea/cookbook/tracing_with_deployed_prompt.py @@ -1,6 +1,6 @@ -import os from typing import Tuple +import os from datetime import datetime from dotenv import load_dotenv @@ -11,7 +11,7 @@ load_dotenv() -p = Parea(api_key=os.getenv('PAREA_API_KEY')) +p = Parea(api_key=os.getenv("PAREA_API_KEY")) def deployed_argument_generator(query: str, additional_description: str = "") -> str: