Skip to content

Commit 8ba8d2c

Browse files
pjoshi30Preetam Joshi
andauthored
Fixing context parsing issue with analyze_eval decorator (#26)
* Initial commit Adding the Aimon Rely README, images, the postman collection, a simple client and examples. A few small changes for error handling in the client and the example application. Getting the Aimon API key from the streamlit app updating README Updating langchain example gif Updating API endpoint Adding V2 API with support for conciseness, completeness and toxicity checks (#1) * Adding V2 API with support for conciseness, completeness and toxicity checks. * Removing prints and updating config for the example application. * Updating README --------- Co-authored-by: Preetam Joshi <[email protected]> Updating postman collection Fixed the simple aimon client's handling of batch requests. Updated postman collection. Added support for a user_query parameter in the input data dictionary. Updating readme Fixed bug in the example app Uploading client code Adding more convenience APIs Fixing bug in create_dataset Added Github actions config to publish to PyPI. Cleaned up dependencies and updated documentation. Fixing langchain example Fixing doc links Formatting changes Changes for aimon-rely * Adding instruction adherence and hallucination v0.2 to the client Updating git ignore Adding more to gitignore Removing .idea files * Fixing doc string * Updating documentation * Updating Client to use V3 API * Fixing test * Updating tests * Updating documentation in the client * Adding .streamlit dir to .gitignore * initial version of decorators for syntactic sugar * A few more changes * updating analyze and detect decorators * Adding new notebooks * Fixing bug in analyze decorator * Updating Detect decorator to make it simpler. Adding Metaflow example. Adding documentation for the chatbot. * fixing chatbot example * Fixed issue in detect decorator. Improved code organization. * fixed typo * Updated the decorators with a more cleaner interface. Added a metaflow analyze example. * Updated version * Updated Notebook * Fixing context parsing issue with analyze_eval decorator --------- Co-authored-by: Preetam Joshi <[email protected]>
1 parent 672ef77 commit 8ba8d2c

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

aimon/decorators/analyze.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ def _run_eval(self, func, args, kwargs):
111111
results = []
112112
for record in dataset_collection_records:
113113
result = func(record["context_docs"], record["user_query"], record["prompt"], *args, **kwargs)
114-
114+
_context = record['context_docs'] if isinstance(record['context_docs'], list) else [record['context_docs']]
115115
# TODO: Add instructions and config to the payload once supported
116116
payload = {
117117
"application_id": self._am_app.id,
118118
"version": self._am_app.version,
119119
"prompt": record['prompt'] or "",
120120
"user_query": record['user_query'] or "",
121-
"context_docs": [d for d in record['context_docs']],
121+
"context_docs": [d for d in _context],
122122
"output": result,
123123
"evaluation_id": self._eval.id,
124124
"evaluation_run_id": eval_run.id,

examples/notebooks/aimon_decorators_langchain_summarization_0_5_0.ipynb

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 8,
6+
"id": "d8495fd8-cd0a-406f-8f20-f6b66fd585fe",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"\u001b[33mWARNING: You are using pip version 20.2.3; however, version 24.2 is available.\n",
14+
"You should consider upgrading via the '/Users/preetamjoshi/projects/aimon/pj_aimon_rely/examples/chatbot/chtbot/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n"
15+
]
16+
}
17+
],
18+
"source": [
19+
"!pip install langchain langchain-community --quiet"
20+
]
21+
},
322
{
423
"cell_type": "code",
524
"execution_count": 1,
@@ -18,7 +37,7 @@
1837
"outputs": [],
1938
"source": [
2039
"import os\n",
21-
"openai_api_key = os.getenv(\"OPEN_AI_KEY\")"
40+
"openai_api_key = os.getenv(\"OPENAI_API_KEY\")"
2241
]
2342
},
2443
{
@@ -29,7 +48,7 @@
2948
"outputs": [],
3049
"source": [
3150
"analyze_eval = AnalyzeEval(\n",
32-
" Application(\"app_jun18_2024\"),\n",
51+
" Application(\"decorator_app_test\"),\n",
3352
" Model(\"my_gpt4_model_fine_tuned\", \"GPT-4\"), \n",
3453
" api_key=os.getenv(\"AIMON_API_KEY\"),\n",
3554
" evaluation_name=\"simple_eval\",\n",
@@ -39,13 +58,13 @@
3958
},
4059
{
4160
"cell_type": "code",
42-
"execution_count": 4,
61+
"execution_count": 5,
4362
"id": "d5c3e5f0-7611-4e44-ba32-b721fba56218",
4463
"metadata": {},
4564
"outputs": [],
4665
"source": [
4766
"analyze_prod = AnalyzeProd(\n",
48-
" Application(\"llm_marketing_summarization_app\"), \n",
67+
" Application(\"decorator_app_prod\"), \n",
4968
" Model(\"my_gpt4_model_v2\", \"GPT-4\"), \n",
5069
" values_returned=[\"context\", \"generated_text\"],\n",
5170
" api_key=os.getenv(\"AIMON_API_KEY\")\n",
@@ -64,7 +83,7 @@
6483
},
6584
{
6685
"cell_type": "code",
67-
"execution_count": 5,
86+
"execution_count": 4,
6887
"id": "af98abfc-c04d-4cc7-ba3c-62f550de0c99",
6988
"metadata": {},
7089
"outputs": [],
@@ -97,17 +116,17 @@
97116
},
98117
{
99118
"cell_type": "code",
100-
"execution_count": 6,
119+
"execution_count": 5,
101120
"id": "bcdddfa8-43c7-446a-9337-3ad0f16a015e",
102121
"metadata": {},
103122
"outputs": [
104123
{
105124
"name": "stderr",
106125
"output_type": "stream",
107126
"text": [
108-
"/Users/preetamjoshi/projects/aimon/pj_aimon_rely/examples/mflow/lib/python3.9/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `OpenAI` was deprecated in LangChain 0.0.10 and will be removed in 0.3.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import OpenAI`.\n",
127+
"/Users/preetamjoshi/projects/aimon/pj_aimon_rely/examples/chatbot/chtbot/lib/python3.9/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `OpenAI` was deprecated in LangChain 0.0.10 and will be removed in 0.3.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import OpenAI`.\n",
109128
" warn_deprecated(\n",
110-
"/Users/preetamjoshi/projects/aimon/pj_aimon_rely/examples/mflow/lib/python3.9/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The method `Chain.run` was deprecated in langchain 0.1.0 and will be removed in 0.3.0. Use invoke instead.\n",
129+
"/Users/preetamjoshi/projects/aimon/pj_aimon_rely/examples/chatbot/chtbot/lib/python3.9/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The method `Chain.run` was deprecated in langchain 0.1.0 and will be removed in 0.3.0. Use invoke instead.\n",
111130
" warn_deprecated(\n"
112131
]
113132
}
@@ -118,15 +137,15 @@
118137
},
119138
{
120139
"cell_type": "code",
121-
"execution_count": 7,
140+
"execution_count": 6,
122141
"id": "d6e94b08-0e2a-4860-a4f2-30d9ddea17af",
123142
"metadata": {},
124143
"outputs": [
125144
{
126145
"name": "stdout",
127146
"output_type": "stream",
128147
"text": [
129-
"[(' Acme recently launched version 2.1 of their Python library, which has deep integrations with the Python ecosystem and has been proven to be beneficial for developers. This new version includes features like async support and improved error handling.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), ('\\n\\nTo configure the Acme python client, follow the official documentation which includes setting up environment variables and installing dependencies for both basic and advanced setups.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client is compatible with Python 3.6+ and multiple databases, including MySQL, PostgreSQL, and MongoDB. It is also suitable for cross-language projects with Node.js.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client may have installation, package conflicts, and connectivity issues. Troubleshooting involves checking the Python environment, dependencies, and log files, with specific error resolutions available in the online help section.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' Acme recently launched version 2.1 of their Python library, which has deep integrations with the Python ecosystem and has been proven to be beneficial for developers. This new version includes features like async support and improved error handling.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), ('\\n\\nTo configure the Acme python client, follow the official documentation which includes setting up environment variables and installing dependencies for both basic and advanced setups.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client is compatible with Python 3.6+ and multiple databases, including MySQL, PostgreSQL, and MongoDB. It is also suitable for cross-language projects with Node.js.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client may have installation, package conflicts, and connectivity issues. Troubleshooting involves checking the Python environment, dependencies, and log files, with specific error resolutions available in the online help section.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.'))]\n"
148+
"[(' Acme recently launched version 2.1 of their Python library, which has deep integrations with the Python ecosystem and has been proven to be valuable for developers. This new version includes features like async support and improved error handling. Acme also supports Javascript and Java.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), ('\\n\\nTo configure the Acme python client, follow the official documentation which includes setting up environment variables and installing dependencies for both basic and advanced setups.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client is compatible with Python 3.6+ and multiple databases, including MySQL, PostgreSQL, and MongoDB. It is also suitable for cross-language projects with Node.js.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client may have installation, package conflicts, and connectivity issues. Troubleshooting involves checking the Python environment, dependencies, and log files, with specific error resolutions available in the online help section.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' Acme recently launched version 2.1 of their Python library, which has deep integrations with the Python ecosystem and has been proven to be valuable for developers. This new version includes features like async support and improved error handling. Acme also supports Javascript and Java.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), ('\\n\\nTo configure the Acme python client, follow the official documentation which includes setting up environment variables and installing dependencies for both basic and advanced setups.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client is compatible with Python 3.6+ and multiple databases, including MySQL, PostgreSQL, and MongoDB. It is also suitable for cross-language projects with Node.js.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.')), (' The Acme python client may have installation, package conflicts, and connectivity issues. Troubleshooting involves checking the Python environment, dependencies, and log files, with specific error resolutions available in the online help section.', AnalyzeCreateResponse(message='Data successfully sent to AIMon.'))]\n"
130149
]
131150
}
132151
],
@@ -146,7 +165,7 @@
146165
},
147166
{
148167
"cell_type": "code",
149-
"execution_count": 8,
168+
"execution_count": 12,
150169
"id": "44438e7f-5652-46b5-9244-cbf2977d9d48",
151170
"metadata": {},
152171
"outputs": [],
@@ -174,7 +193,7 @@
174193
},
175194
{
176195
"cell_type": "code",
177-
"execution_count": 9,
196+
"execution_count": 13,
178197
"id": "bb81a8ad-e10a-43f5-9682-844d9ab2ccb4",
179198
"metadata": {},
180199
"outputs": [],
@@ -194,7 +213,7 @@
194213
},
195214
{
196215
"cell_type": "code",
197-
"execution_count": 11,
216+
"execution_count": 14,
198217
"id": "1e0dc9d7-e0b0-4a05-8967-0e06179486a3",
199218
"metadata": {},
200219
"outputs": [],
@@ -204,7 +223,7 @@
204223
},
205224
{
206225
"cell_type": "code",
207-
"execution_count": 12,
226+
"execution_count": 15,
208227
"id": "5515eafd-8644-4792-a69e-23625a026c6c",
209228
"metadata": {},
210229
"outputs": [

0 commit comments

Comments
 (0)