improve logging (#66)

harrison/prompt_examples
Harrison Chase 2 years ago committed by GitHub
parent 818b06ebbc
commit f772934108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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"
]
},
{

@ -2,10 +2,15 @@
from abc import ABC, abstractmethod
from 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
@abstractmethod
def 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}

@ -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:

@ -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:

@ -49,7 +49,6 @@ class ReActChain(Chain, BaseModel):
"""LLM wrapper to use."""
docstore: Docstore
"""Docstore to use."""
verbose: bool = False
input_key: str = "question" #: :meta private:
output_key: str = "answer" #: :meta private:

@ -89,7 +89,6 @@ class SelfAskWithSearchChain(Chain, BaseModel):
"""LLM wrapper to use."""
search_chain: SerpAPIChain
"""Search chain to use."""
verbose: bool = False
input_key: str = "question" #: :meta private:
output_key: str = "answer" #: :meta private:

@ -26,7 +26,6 @@ class SQLDatabaseChain(Chain, BaseModel):
"""LLM wrapper to use."""
database: SQLDatabase
"""SQL Database to connect to."""
verbose: bool = False
input_key: str = "query" #: :meta private:
output_key: str = "result" #: :meta private:

Loading…
Cancel
Save