The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Harrison/output error (#3094)
Harrison Chaseaad0a498ac69
diff --git a/docs/modules/agents/tools/examples/jira.ipynb b/docs/modules/agents/toolkits/examples/jira.ipynbsimilarity index 100%rename from docs/modules/agents/tools/examples/jira.ipynbrename to docs/modules/agents/toolkits/examples/jira.ipynbdiff --git a/docs/modules/agents/toolkits/examples/openapi.ipynb b/docs/modules/agents/toolkits/examples/openapi.ipynbindex 0fee994821..e7a306bb47 100644--- a/docs/modules/agents/toolkits/examples/openapi.ipynb+++ b/docs/modules/agents/toolkits/examples/openapi.ipynb@@ -15,7 +15,7 @@"id": "a389367b","metadata": {},"source": [- "# 1st example: hierarchical planning agent\n",+ "## 1st example: hierarchical planning agent\n","\n","In this example, we'll consider an approach called hierarchical planning, common in robotics and appearing in recent works for LLMs X robotics. We'll see it's a viable approach to start working with a massive API spec AND to assist with user queries that require multiple steps against the API.\n","\n",@@ -31,7 +31,7 @@"id": "4b6ecf6e","metadata": {},"source": [- "## To start, let's collect some OpenAPI specs."+ "### To start, let's collect some OpenAPI specs."]},{@@ -169,7 +169,7 @@"id": "76349780","metadata": {},"source": [- "## How big is this spec?"+ "### How big is this spec?"]},{@@ -229,7 +229,7 @@"id": "cbc4964e","metadata": {},"source": [- "## Let's see some examples!\n",+ "### Let's see some examples!\n","\n","Starting with GPT-4. (Some robustness iterations under way for GPT-3 family.)"]@@ -759,7 +759,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.9.0"+ "version": "3.9.1"}},"nbformat": 4,diff --git a/docs/modules/indexes/document_loaders/examples/confluence.ipynb b/docs/modules/indexes/document_loaders/examples/confluence.ipynbindex 59e9a4f75c..38bbf00865 100644--- a/docs/modules/indexes/document_loaders/examples/confluence.ipynb+++ b/docs/modules/indexes/document_loaders/examples/confluence.ipynb@@ -1,18 +1,20 @@{"cells": [{- "attachments": {},"cell_type": "markdown","metadata": {},"source": ["# Confluence\n","\n",- "A loader for Confluence pages. Port of https://llamahub.ai/l/confluence\n",+ "A loader for Confluence pages.\n",+ "\n","\n","This currently supports both username/api_key and Oauth2 login.\n","\n",+ "\n","Specify a list page_ids and/or space_key to load in the corresponding pages into Document objects, if both are specified the union of both sets will be returned.\n","\n",+ "\n","You can also specify a boolean `include_attachments` to include attachments, this is set to False by default, if set to True all attachments will be downloaded and ConfluenceReader will extract the text from the attachments and add it to the Document object. Currently supported attachment types are: PDF, PNG, JPEG/JPG, SVG, Word and Excel.\n","\n","Hint: space_key and page_id can both be found in the URL of a page in Confluence - https://yoursite.atlassian.com/wiki/spaces/<space_key>/pages/<page_id>\n"@@ -37,15 +39,22 @@],"metadata": {"kernelspec": {- "display_name": "Python 3",+ "display_name": "Python 3 (ipykernel)","language": "python","name": "python3"},"language_info": {+ "codemirror_mode": {+ "name": "ipython",+ "version": 3+ },+ "file_extension": ".py",+ "mimetype": "text/x-python","name": "python",- "version": "3.9.7 (default, Mar 5 2023, 20:59:52) \n[Clang 12.0.0 (clang-1200.0.32.2)]"+ "nbconvert_exporter": "python",+ "pygments_lexer": "ipython3",+ "version": "3.9.1"},- "orig_nbformat": 4,"vscode": {"interpreter": {"hash": "cc99336516f23363341912c6723b01ace86f02e26b4290be1efc0677e2e2ec24"diff --git a/docs/modules/indexes/document_loaders/examples/discord_loader.ipynb b/docs/modules/indexes/document_loaders/examples/discord_loader.ipynbindex 8324feef96..2b28d47d6f 100644--- a/docs/modules/indexes/document_loaders/examples/discord_loader.ipynb+++ b/docs/modules/indexes/document_loaders/examples/discord_loader.ipynb@@ -59,7 +59,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.10.9"+ "version": "3.9.1"}},"nbformat": 4,diff --git a/docs/modules/indexes/document_loaders/examples/twitter.ipynb b/docs/modules/indexes/document_loaders/examples/twitter.ipynbindex 3713ad4f0e..9df5a784c7 100644--- a/docs/modules/indexes/document_loaders/examples/twitter.ipynb+++ b/docs/modules/indexes/document_loaders/examples/twitter.ipynb@@ -62,8 +62,8 @@{"cell_type": "code","execution_count": 4,+ "id": "05fe33b9","metadata": {- "collapsed": false,"pycharm": {"name": "#%%\n"}@@ -106,7 +106,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.11.2"+ "version": "3.9.1"}},"nbformat": 4,diff --git a/docs/use_cases/question_answering/semantic-search-over-chat.ipynb b/docs/use_cases/question_answering/semantic-search-over-chat.ipynbindex d2166e2145..f1e2c65410 100644--- a/docs/use_cases/question_answering/semantic-search-over-chat.ipynb+++ b/docs/use_cases/question_answering/semantic-search-over-chat.ipynb@@ -4,10 +4,10 @@"cell_type": "markdown","metadata": {},"source": [- "# Semantic Search over a group chat messages\n",- "In this tutorial, we are going to use Langchain + Deep Lake with GPT4 to semantically search a group chat.\n",+ "# Question answering over a group chat messages\n",+ "In this tutorial, we are going to use Langchain + Deep Lake with GPT4 to semantically search and ask questions over a group chat.\n","\n",- "View a working demo here: https://twitter.com/thisissukh_/status/1647223328363679745"+ "View a working demo [here](https://twitter.com/thisissukh_/status/1647223328363679745)"]},{@@ -83,7 +83,7 @@"Generate a group chat conversation with three friends talking about their day, referencing real places and fictional names. Make it funny and as detailed as possible.\n","```\n","\n",- "I've already generated such a chat in `../../messages.txt`. We can keep it simple and use this for our example.\n",+ "I've already generated such a chat in `messages.txt`. We can keep it simple and use this for our example.\n","\n","## 3. Ingest chat embeddings\n","\n",@@ -144,8 +144,10 @@]},{- "cell_type": "markdown",+ "cell_type": "code",+ "execution_count": null,"metadata": {},+ "outputs": [],"source": []}],diff --git a/langchain/agents/chat/output_parser.py b/langchain/agents/chat/output_parser.pyindex 0d07e7e0c2..71a8edd7dd 100644--- a/langchain/agents/chat/output_parser.py+++ b/langchain/agents/chat/output_parser.py@@ -2,12 +2,16 @@ import jsonfrom typing import Unionfrom langchain.agents.agent import AgentOutputParser-from langchain.schema import AgentAction, AgentFinish+from langchain.agents.chat.prompt import FORMAT_INSTRUCTIONS+from langchain.schema import AgentAction, AgentFinish, OutputParserExceptionFINAL_ANSWER_ACTION = "Final Answer:"class ChatOutputParser(AgentOutputParser):+ def get_format_instructions(self) -> str:+ return FORMAT_INSTRUCTIONS+def parse(self, text: str) -> Union[AgentAction, AgentFinish]:if FINAL_ANSWER_ACTION in text:return AgentFinish(@@ -19,4 +23,4 @@ class ChatOutputParser(AgentOutputParser):return AgentAction(response["action"], response["action_input"], text)except Exception:- raise ValueError(f"Could not parse LLM output: {text}")+ raise OutputParserException(f"Could not parse LLM output: {text}")diff --git a/langchain/agents/conversational/output_parser.py b/langchain/agents/conversational/output_parser.pyindex a8cdf8445f..f11eb540b7 100644--- a/langchain/agents/conversational/output_parser.py+++ b/langchain/agents/conversational/output_parser.py@@ -2,12 +2,16 @@ import refrom typing import Unionfrom langchain.agents.agent import AgentOutputParser-from langchain.schema import AgentAction, AgentFinish+from langchain.agents.conversational.prompt import FORMAT_INSTRUCTIONS+from langchain.schema import AgentAction, AgentFinish, OutputParserExceptionclass ConvoOutputParser(AgentOutputParser):ai_prefix: str = "AI"+ def get_format_instructions(self) -> str:+ return FORMAT_INSTRUCTIONS+def parse(self, text: str) -> Union[AgentAction, AgentFinish]:if f"{self.ai_prefix}:" in text:return AgentFinish(@@ -16,7 +20,7 @@ class ConvoOutputParser(AgentOutputParser):regex = r"Action: (.*?)[\n]*Action Input: (.*)"match = re.search(regex, text)if not match:- raise ValueError(f"Could not parse LLM output: `{text}`")+ raise OutputParserException(f"Could not parse LLM output: `{text}`")action = match.group(1)action_input = match.group(2)return AgentAction(action.strip(), action_input.strip(" ").strip('"'), text)diff --git a/langchain/agents/mrkl/output_parser.py b/langchain/agents/mrkl/output_parser.pyindex 8e9c0f1618..0309609bb9 100644--- a/langchain/agents/mrkl/output_parser.py+++ b/langchain/agents/mrkl/output_parser.py@@ -2,12 +2,16 @@ import refrom typing import Unionfrom langchain.agents.agent import AgentOutputParser-from langchain.schema import AgentAction, AgentFinish+from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS+from langchain.schema import AgentAction, AgentFinish, OutputParserExceptionFINAL_ANSWER_ACTION = "Final Answer:"class MRKLOutputParser(AgentOutputParser):+ def get_format_instructions(self) -> str:+ return FORMAT_INSTRUCTIONS+def parse(self, text: str) -> Union[AgentAction, AgentFinish]:if FINAL_ANSWER_ACTION in text:return AgentFinish(@@ -17,7 +21,7 @@ class MRKLOutputParser(AgentOutputParser):regex = r"Action\s*\d*\s*:(.*?)\nAction\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)"match = re.search(regex, text, re.DOTALL)if not match:- raise ValueError(f"Could not parse LLM output: `{text}`")+ raise OutputParserException(f"Could not parse LLM output: `{text}`")action = match.group(1).strip()action_input = match.group(2)return AgentAction(action, action_input.strip(" ").strip('"'), text)diff --git a/langchain/agents/react/output_parser.py b/langchain/agents/react/output_parser.pyindex 6b96f216bc..f63cd3e266 100644--- a/langchain/agents/react/output_parser.py+++ b/langchain/agents/react/output_parser.py@@ -2,21 +2,23 @@ import refrom typing import Unionfrom langchain.agents.agent import AgentOutputParser-from langchain.schema import AgentAction, AgentFinish+from langchain.schema import AgentAction, AgentFinish, OutputParserExceptionclass ReActOutputParser(AgentOutputParser):def parse(self, text: str) -> Union[AgentAction, AgentFinish]:action_prefix = "Action: "if not text.strip().split("\n")[-1].startswith(action_prefix):- raise ValueError(f"Could not parse LLM Output: {text}")+ raise OutputParserException(f"Could not parse LLM Output: {text}")action_block = text.strip().split("\n")[-1]action_str = action_block[len(action_prefix) :]# Parse out the action and the directive.re_matches = re.search(r"(.*?)\[(.*?)\]", action_str)if re_matches is None:- raise ValueError(f"Could not parse action directive: {action_str}")+ raise OutputParserException(+ f"Could not parse action directive: {action_str}"+ )action, action_input = re_matches.group(1), re_matches.group(2)if action == "Finish":return AgentFinish({"output": action_input}, text)diff --git a/langchain/agents/self_ask_with_search/output_parser.py b/langchain/agents/self_ask_with_search/output_parser.pyindex 241a931792..009c616130 100644--- a/langchain/agents/self_ask_with_search/output_parser.py+++ b/langchain/agents/self_ask_with_search/output_parser.py@@ -1,7 +1,7 @@from typing import Unionfrom langchain.agents.agent import AgentOutputParser-from langchain.schema import AgentAction, AgentFinish+from langchain.schema import AgentAction, AgentFinish, OutputParserExceptionclass SelfAskOutputParser(AgentOutputParser):@@ -12,7 +12,7 @@ class SelfAskOutputParser(AgentOutputParser):if followup not in last_line:finish_string = "So the final answer is: "if finish_string not in last_line:- raise ValueError(f"Could not parse output: {text}")+ raise OutputParserException(f"Could not parse output: {text}")return AgentFinish({"output": last_line[len(finish_string) :]}, text)after_colon = text.split(":")[-1]diff --git a/tests/unit_tests/agents/test_mrkl.py b/tests/unit_tests/agents/test_mrkl.pyindex 8cf4f6f8d0..68c71b300e 100644--- a/tests/unit_tests/agents/test_mrkl.py+++ b/tests/unit_tests/agents/test_mrkl.py@@ -9,7 +9,7 @@ from langchain.agents.mrkl.output_parser import MRKLOutputParserfrom langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIXfrom langchain.agents.tools import Toolfrom langchain.prompts import PromptTemplate-from langchain.schema import AgentAction+from langchain.schema import AgentAction, OutputParserExceptionfrom tests.unit_tests.llms.fake_llm import FakeLLM@@ -98,7 +98,7 @@ def test_get_final_answer_multiline() -> None:def test_bad_action_input_line() -> None:"""Test handling when no action input found."""llm_output = "Thought: I need to search for NBA\n" "Action: Search\n" "Thought: NBA"- with pytest.raises(ValueError):+ with pytest.raises(OutputParserException):get_action_and_input(llm_output)@@ -107,7 +107,7 @@ def test_bad_action_line() -> None:llm_output = ("Thought: I need to search for NBA\n" "Thought: Search\n" "Action Input: NBA")- with pytest.raises(ValueError):+ with pytest.raises(OutputParserException):get_action_and_input(llm_output)