diff --git a/docs/modules/agents/tools/examples/jira.ipynb b/docs/modules/agents/toolkits/examples/jira.ipynb similarity index 100% rename from docs/modules/agents/tools/examples/jira.ipynb rename to docs/modules/agents/toolkits/examples/jira.ipynb diff --git a/docs/modules/agents/toolkits/examples/openapi.ipynb b/docs/modules/agents/toolkits/examples/openapi.ipynb index 0fee9948..e7a306bb 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.ipynb index 59e9a4f7..38bbf008 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//pages/\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.ipynb index 8324feef..2b28d47d 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.ipynb index 3713ad4f..9df5a784 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.ipynb index d2166e21..f1e2c654 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.py index 0d07e7e0..71a8edd7 100644 --- a/langchain/agents/chat/output_parser.py +++ b/langchain/agents/chat/output_parser.py @@ -2,12 +2,16 @@ import json from typing import Union from 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, OutputParserException FINAL_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.py index a8cdf844..f11eb540 100644 --- a/langchain/agents/conversational/output_parser.py +++ b/langchain/agents/conversational/output_parser.py @@ -2,12 +2,16 @@ import re from typing import Union from 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, OutputParserException class 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.py index 8e9c0f16..0309609b 100644 --- a/langchain/agents/mrkl/output_parser.py +++ b/langchain/agents/mrkl/output_parser.py @@ -2,12 +2,16 @@ import re from typing import Union from 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, OutputParserException FINAL_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.py index 6b96f216..f63cd3e2 100644 --- a/langchain/agents/react/output_parser.py +++ b/langchain/agents/react/output_parser.py @@ -2,21 +2,23 @@ import re from typing import Union from langchain.agents.agent import AgentOutputParser -from langchain.schema import AgentAction, AgentFinish +from langchain.schema import AgentAction, AgentFinish, OutputParserException class 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.py index 241a9317..009c6161 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 Union from langchain.agents.agent import AgentOutputParser -from langchain.schema import AgentAction, AgentFinish +from langchain.schema import AgentAction, AgentFinish, OutputParserException class 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.py index 8cf4f6f8..68c71b30 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 MRKLOutputParser from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX from langchain.agents.tools import Tool from langchain.prompts import PromptTemplate -from langchain.schema import AgentAction +from langchain.schema import AgentAction, OutputParserException from 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)