Merge branch 'main' into wfh/reflexion

This commit is contained in:
William FH
2024-02-19 08:22:11 -08:00
committed by GitHub
4 changed files with 950 additions and 140 deletions
File diff suppressed because one or more lines are too long
+54 -28
View File
@@ -48,13 +48,12 @@
"If you want to run this locally (e.g., on your laptop), use [Ollama](https://ollama.ai/library/mistral/tags):\n",
"\n",
"* Download [Ollama app](https://ollama.ai/).\n",
"* Download a `Mistral` model e.g., `ollama pull mistral:7b-instruct`, from various Mistral versions [here](https://ollama.ai/library/mistral) and Mixtral versions [here](https://ollama.ai/library/mixtral) available.\n",
"* Download LLaMA2 `ollama pull llama2:latest` to use Ollama embeddings.\n",
"* Download a `Mistral` model e.g., `ollama pull mistral:instruct`, from various Mistral versions [here](https://ollama.ai/library/mistral) and Mixtral versions [here](https://ollama.ai/library/mixtral) available.\n",
"* Set flags indicating we will run locally and the Mistral model downloaded:\n",
" \n",
"```\n",
"run_local = \"Yes\"\n",
"local_llm = \"mistral:7b-instruct\"\n",
"local_llm = \"mistral:instruct\"\n",
"```\n",
"\n",
"### Tracing \n",
@@ -70,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 1,
"id": "abc064ab-7de1-4d03-a987-cd3078438d61",
"metadata": {},
"outputs": [],
@@ -84,14 +83,14 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 2,
"id": "9f644869-436e-4bf6-a267-b2465c7b5aef",
"metadata": {},
"outputs": [],
"source": [
"# Flags for running locally\n",
"\n",
"run_local = \"No\"\n",
"run_local = \"Yes\"\n",
"local_llm = \"mistral:instruct\""
]
},
@@ -113,10 +112,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "254ae533-79e0-42f4-b200-1ec9160e1d3d",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"bert_load_from_file: gguf version = 2\n",
"bert_load_from_file: gguf alignment = 32\n",
"bert_load_from_file: gguf data offset = 695552\n",
"bert_load_from_file: model name = BERT\n",
"bert_load_from_file: model architecture = bert\n",
"bert_load_from_file: model file type = 1\n",
"bert_load_from_file: bert tokenizer vocab = 30522\n"
]
}
],
"source": [
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
"from langchain_community.document_loaders import WebBaseLoader\n",
@@ -187,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 4,
"id": "10028794-2fbc-43f9-aa4c-7fe3abd69c1e",
"metadata": {},
"outputs": [],
@@ -224,7 +237,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 5,
"id": "447d1333-082d-479a-a6fa-0ac0df78bb9d",
"metadata": {},
"outputs": [],
@@ -484,12 +497,12 @@
"source": [
"## Build Graph\n",
"\n",
"The just follows the flow we outlined in the figure above."
"This just follows the flow we outlined in the figure above."
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 6,
"id": "0a63776c-f9cd-46ce-b8cf-95c066dc5b06",
"metadata": {},
"outputs": [],
@@ -540,7 +553,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"id": "3ab1d8df-a74e-4b48-a30b-e39bbfd5925a",
"metadata": {},
"outputs": [
@@ -552,32 +565,45 @@
"\"Node 'retrieve':\"\n",
"'\\n---\\n'\n",
"---CHECK RELEVANCE---\n",
"---GRADE: DOCUMENT NOT RELEVANT---\n",
"---GRADE: DOCUMENT RELEVANT---\n",
"---GRADE: DOCUMENT RELEVANT---\n",
"---GRADE: DOCUMENT RELEVANT---\n",
"---GRADE: DOCUMENT RELEVANT---\n",
"\"Node 'grade_documents':\"\n",
"'\\n---\\n'\n",
"---DECIDE TO GENERATE---\n",
"---DECISION: TRANSFORM QUERY and RUN WEB SEARCH---\n",
"---TRANSFORM QUERY---\n",
"\"Node 'transform_query':\"\n",
"'\\n---\\n'\n",
"---WEB SEARCH---\n",
"\"Node 'web_search':\"\n",
"'\\n---\\n'\n",
"---DECISION: GENERATE---\n",
"---GENERATE---\n",
"\"Node 'generate':\"\n",
"'\\n---\\n'\n",
"\"Node '__end__':\"\n",
"'\\n---\\n'\n",
"('In agent-based systems, episodic memory can be likened to a long-term memory '\n",
" \"module that records agents' experiences in natural language, with retrieval \"\n",
" 'based on relevance, recency, and importance. Semantic memory is similar to '\n",
" 'an external vector store that provides agents with the ability to retain and '\n",
" 'recall information over extended periods. Procedural memory can be seen as '\n",
" 'the reflection mechanism that synthesizes memories into higher-level '\n",
" \"inferences, guiding the agent's future behavior.\")\n"
"(' In an LLM (large language model)-powered autonomous agent system, LLM '\n",
" 'functions as the agents brain, complemented by several key components: '\n",
" 'planning and memory.\\n'\n",
" '\\n'\n",
" 'Planning involves breaking down large tasks into smaller subgoals for '\n",
" 'efficient handling of complex tasks and self-criticism and refinement to '\n",
" 'improve results.\\n'\n",
" '\\n'\n",
" 'Memory includes short-term memory, which utilizes in-context learning, and '\n",
" 'long-term memory, providing the agent with the capability to retain and '\n",
" 'recall information over extended periods using an external vector store and '\n",
" 'fast retrieval. The agent also learns to call external APIs for missing '\n",
" 'information.\\n'\n",
" '\\n'\n",
" 'Types of Memory:\\n'\n",
" '1. Sensory Memory: retains impressions of sensory information for a few '\n",
" 'seconds.\\n'\n",
" '2. Short-Term Memory (STM) or Working Memory: stores information needed for '\n",
" 'complex cognitive tasks and lasts for 20-30 seconds.\\n'\n",
" '3. Long-Term Memory (LTM): stores information for a remarkably long time, '\n",
" 'with two subtypes: explicit/declarative memory and implicit/procedural '\n",
" 'memory.\\n'\n",
" '\\n'\n",
" 'The agent uses LLM as its core controller, which can be extended beyond '\n",
" 'generating well-written copies, stories, essays, and programs to a powerful '\n",
" 'general problem solver.')\n"
]
}
],
+1 -1
View File
@@ -223,7 +223,7 @@
" return {\"keys\": {\"documents\": documents, \"question\": question}}\n",
"\n",
"\n",
"def generate(state):\n",
"def generate(state):a\n",
" \"\"\"\n",
" Generate answer\n",
"\n",
File diff suppressed because one or more lines are too long