The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
improve logging (#66)
Harrison Chasef77293410837
diff --git a/examples/mrkl.ipynb b/examples/mrkl.ipynbindex 3e4b40e2ab..e1a50364ba 100644--- a/examples/mrkl.ipynb+++ b/examples/mrkl.ipynb@@ -20,9 +20,9 @@"source": ["llm = OpenAI(temperature=0)\n","search = SerpAPIChain()\n",- "llm_math_chain = LLMMathChain(llm=llm)\n",+ "llm_math_chain = LLMMathChain(llm=llm, verbose=True)\n","db = SQLDatabase.from_uri(\"sqlite:///../notebooks/Chinook.db\")\n",- "db_chain = SQLDatabaseChain(llm=llm, database=db)\n",+ "db_chain = SQLDatabaseChain(llm=llm, database=db, verbose=True)\n","chains = [\n"," ChainConfig(\n"," action_name = \"Search\",\n",@@ -63,6 +63,9 @@"name": "stdout","output_type": "stream","text": [+ "\n",+ "\n",+ "\u001b[1m> Entering new chain...\u001b[0m\n","What is the age of Olivia Wilde's boyfriend raised to the 0.23 power?\n","Thought:\u001b[102m I need to find the age of Olivia Wilde's boyfriend\n","Action: Search\n",@@ -75,10 +78,23 @@"Thought:\u001b[102m I need to calculate 28 to the 0.23 power\n","Action: Calculator\n","Action Input: 28^0.23\u001b[0m\n",+ "\n",+ "\u001b[1m> Entering new chain...\u001b[0m\n",+ "28^0.23\u001b[102m\n",+ "\n",+ "```python\n",+ "print(28**0.23)\n",+ "```\n",+ "\u001b[0m\n",+ "Answer: \u001b[103m2.1520202182226886\n",+ "\u001b[0m\n",+ "\u001b[1m> Finished chain.\u001b[0m\n",+ "\n","Observation: \u001b[103mAnswer: 2.1520202182226886\n","\u001b[0m\n","Thought:\u001b[102m I now know the final answer\n",- "Final Answer: 2.1520202182226886\u001b[0m"+ "Final Answer: 2.1520202182226886\u001b[0m\n",+ "\u001b[1m> Finished chain.\u001b[0m\n"]},{@@ -106,6 +122,9 @@"name": "stdout","output_type": "stream","text": [+ "\n",+ "\n",+ "\u001b[1m> Entering new chain...\u001b[0m\n","Who recently released an album called 'The Storm Before the Calm' and are they in the FooBar database? If so, what albums of theirs are in the FooBar database?\n","Thought:\u001b[102m I need to find an album called 'The Storm Before the Calm'\n","Action: Search\n",@@ -114,13 +133,30 @@"Thought:\u001b[102m I need to check if Alanis is in the FooBar database\n","Action: FooBar DB\n","Action Input: \"Does Alanis Morissette exist in the FooBar database?\"\u001b[0m\n",+ "\n",+ "\u001b[1m> Entering new chain...\u001b[0m\n",+ "Does Alanis Morissette exist in the FooBar database?\n",+ "SQLQuery:\u001b[102m SELECT * FROM Artist WHERE Name = 'Alanis Morissette'\u001b[0m\n",+ "SQLResult: \u001b[103m[(4, 'Alanis Morissette')]\u001b[0m\n",+ "Answer:\u001b[102m Yes\u001b[0m\n",+ "\u001b[1m> Finished chain.\u001b[0m\n",+ "\n","Observation: \u001b[101m Yes\u001b[0m\n","Thought:\u001b[102m I need to find out what albums of Alanis's are in the FooBar database\n","Action: FooBar DB\n","Action Input: \"What albums by Alanis Morissette are in the FooBar database?\"\u001b[0m\n",+ "\n",+ "\u001b[1m> Entering new chain...\u001b[0m\n",+ "What albums by Alanis Morissette are in the FooBar database?\n",+ "SQLQuery:\u001b[102m SELECT Title FROM Album WHERE ArtistId = (SELECT ArtistId FROM Artist WHERE Name = 'Alanis Morissette')\u001b[0m\n",+ "SQLResult: \u001b[103m[('Jagged Little Pill',)]\u001b[0m\n",+ "Answer:\u001b[102m The album \"Jagged Little Pill\" by Alanis Morissette is in the FooBar database.\u001b[0m\n",+ "\u001b[1m> Finished chain.\u001b[0m\n",+ "\n","Observation: \u001b[101m The album \"Jagged Little Pill\" by Alanis Morissette is in the FooBar database.\u001b[0m\n","Thought:\u001b[102m I now know the final answer\n",- "Final Answer: The album \"Jagged Little Pill\" by Alanis Morissette is the only album by Alanis Morissette in the FooBar database.\u001b[0m"+ "Final Answer: The album \"Jagged Little Pill\" by Alanis Morissette is the only album by Alanis Morissette in the FooBar database.\u001b[0m\n",+ "\u001b[1m> Finished chain.\u001b[0m\n"]},{diff --git a/langchain/chains/base.py b/langchain/chains/base.pyindex 4d200bd0ce..dfc48c59b9 100644--- a/langchain/chains/base.py+++ b/langchain/chains/base.py@@ -2,10 +2,15 @@from abc import ABC, abstractmethodfrom typing import Any, Dict, List+from pydantic import BaseModel-class Chain(ABC):++class Chain(BaseModel, ABC):"""Base interface that all chains should implement."""+ verbose: bool = False+ """Whether to print out the code that was executed."""+@property@abstractmethoddef input_keys(self) -> List[str]:@@ -36,6 +41,10 @@ class Chain(ABC):def __call__(self, inputs: Dict[str, Any]) -> Dict[str, str]:"""Run the logic of this chain and add to output."""self._validate_inputs(inputs)+ if self.verbose:+ print("\n\n\033[1m> Entering new chain...\033[0m")outputs = self._run(inputs)+ if self.verbose:+ print("\n\033[1m> Finished chain.\033[0m")self._validate_outputs(outputs)return {**inputs, **outputs}diff --git a/langchain/chains/llm_math/base.py b/langchain/chains/llm_math/base.pyindex 49aaf1bbc8..6da1754534 100644--- a/langchain/chains/llm_math/base.py+++ b/langchain/chains/llm_math/base.py@@ -23,8 +23,6 @@ class LLMMathChain(Chain, BaseModel):llm: LLM"""LLM wrapper to use."""- verbose: bool = False- """Whether to print out the code that was executed."""input_key: str = "question" #: :meta private:output_key: str = "answer" #: :meta private:diff --git a/langchain/chains/mrkl/base.py b/langchain/chains/mrkl/base.pyindex 80b4e5c0e5..4ad5d564b6 100644--- a/langchain/chains/mrkl/base.py+++ b/langchain/chains/mrkl/base.py@@ -72,8 +72,6 @@ class MRKLChain(Chain, BaseModel):"""Prompt to use as router."""action_to_chain_map: Dict[str, Callable]"""Mapping from action name to chain to execute."""- verbose: bool = False- """Whether to print out the code that was executed."""input_key: str = "question" #: :meta private:output_key: str = "answer" #: :meta private:diff --git a/langchain/chains/react/base.py b/langchain/chains/react/base.pyindex 30594d1943..2cd4dd2589 100644--- a/langchain/chains/react/base.py+++ b/langchain/chains/react/base.py@@ -49,7 +49,6 @@ class ReActChain(Chain, BaseModel):"""LLM wrapper to use."""docstore: Docstore"""Docstore to use."""- verbose: bool = Falseinput_key: str = "question" #: :meta private:output_key: str = "answer" #: :meta private:diff --git a/langchain/chains/self_ask_with_search/base.py b/langchain/chains/self_ask_with_search/base.pyindex e9d965a006..26df99ee89 100644--- a/langchain/chains/self_ask_with_search/base.py+++ b/langchain/chains/self_ask_with_search/base.py@@ -89,7 +89,6 @@ class SelfAskWithSearchChain(Chain, BaseModel):"""LLM wrapper to use."""search_chain: SerpAPIChain"""Search chain to use."""- verbose: bool = Falseinput_key: str = "question" #: :meta private:output_key: str = "answer" #: :meta private:diff --git a/langchain/chains/sql_database/base.py b/langchain/chains/sql_database/base.pyindex e30c42fd35..47db1265c3 100644--- a/langchain/chains/sql_database/base.py+++ b/langchain/chains/sql_database/base.py@@ -26,7 +26,6 @@ class SQLDatabaseChain(Chain, BaseModel):"""LLM wrapper to use."""database: SQLDatabase"""SQL Database to connect to."""- verbose: bool = Falseinput_key: str = "query" #: :meta private:output_key: str = "result" #: :meta private: