├── retrivers ├── __init__.py └── llama_time_weighted_retriever.py ├── vectorestores ├── __init__.py ├── tests │ ├── __init__.py │ └── test_chroma.py └── chroma.py ├── generative_agents ├── __init__.py ├── tests │ ├── __init__.py │ ├── test_memory.py │ └── test_agent.py ├── llama_memory.py └── llama_generative_agent.py ├── .pre-commit-config.yaml ├── README.md ├── .gitignore ├── LICENSE └── llama_generative_agent.ipynb /retrivers/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vectorestores/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /generative_agents/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vectorestores/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /generative_agents/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vectorestores/tests/test_chroma.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from chroma import EnhancedChroma 3 | from langchain.embeddings import LlamaCppEmbeddings 4 | 5 | 6 | def test(): 7 | local_path = "/Users/jon/Downloads/ggml-vicuna-13b-1.1-q4_2.bin" 8 | embeddings = LlamaCppEmbeddings(model_path=local_path) 9 | 10 | vs = EnhancedChroma.from_texts([], embedding=embeddings) 11 | 12 | docs = vs.similarity_search_with_score("how does tommie feel?", k=1) 13 | print(docs) 14 | 15 | 16 | def test_default_relevance_score_fn(): 17 | print(default_relevance_score_fn(14000.0)) 18 | print(default_relevance_score_fn(0)) 19 | print(default_relevance_score_fn(20000.0)) 20 | print(default_relevance_score_fn(200000.0)) 21 | print(default_relevance_score_fn(2000000.0)) 22 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/psf/black 3 | rev: 23.1.0 4 | hooks: 5 | - id: black 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.4.0 8 | hooks: 9 | - id: end-of-file-fixer 10 | - id: trailing-whitespace 11 | - repo: https://github.com/PyCQA/flake8 12 | rev: 6.0.0 13 | hooks: 14 | - id: flake8 15 | - repo: https://github.com/pycqa/isort 16 | rev: 5.12.0 17 | hooks: 18 | - id: isort 19 | - repo: https://github.com/pre-commit/mirrors-mypy 20 | rev: v1.1.1 21 | hooks: 22 | - id: mypy 23 | additional_dependencies: [tokenize-rt==3.2.0] 24 | args: [--ignore-missing-imports, --follow-imports, skip] 25 | - repo: https://github.com/pre-commit/mirrors-prettier 26 | rev: v3.0.0-alpha.6 # Use the sha or tag you want to point at 27 | hooks: 28 | - id: prettier 29 | types_or: [html, javascript] -------------------------------------------------------------------------------- /generative_agents/tests/test_memory.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from chroma import EnhancedChroma 3 | from langchain import LlamaCpp 4 | from langchain.embeddings import LlamaCppEmbeddings 5 | from langchain.retrievers import TimeWeightedVectorStoreRetriever 6 | from llama_memory import LlamaGenerativeAgentMemory 7 | 8 | local_path = "/Users/jon/Downloads/ggml-vicuna-13b-1.1-q4_2.bin" 9 | 10 | 11 | def new_memory_retriever(): 12 | embeddings_model = LlamaCppEmbeddings(model_path=local_path) 13 | vs = EnhancedChroma(embedding_function=embeddings_model) 14 | return TimeWeightedVectorStoreRetriever( 15 | vectorstore=vs, other_score_keys=["importance"], k=15 16 | ) 17 | 18 | 19 | def test(): 20 | llm = LlamaCpp(model_path=local_path, verbose=True) 21 | memory = LlamaGenerativeAgentMemory( 22 | llm=llm, 23 | memory_retriever=new_memory_retriever(), 24 | verbose=True, 25 | reflection_threshold=8 26 | # we will give this a relatively low number to show how reflection works 27 | ) 28 | print( 29 | memory._score_memory_importance( 30 | "Tommie remembers his dog, Bruno, from when he was a kid" 31 | ) 32 | ) 33 | -------------------------------------------------------------------------------- /retrivers/llama_time_weighted_retriever.py: -------------------------------------------------------------------------------- 1 | from copy import deepcopy 2 | from datetime import datetime 3 | from typing import Any, List, Optional 4 | 5 | from langchain.retrievers import TimeWeightedVectorStoreRetriever 6 | from langchain.schema import Document 7 | 8 | 9 | def _get_hours_passed(time: datetime, ref_time: datetime | str) -> float: 10 | """Get the hours passed between two datetime objects.""" 11 | if isinstance(ref_time, str): 12 | ref_time = datetime.fromisoformat(ref_time) 13 | return (time - ref_time).total_seconds() / 3600 14 | 15 | 16 | class LlamaTimeWeightedVectorStoreRetriever(TimeWeightedVectorStoreRetriever): 17 | def add_documents(self, documents: List[Document], **kwargs: Any) -> List[str]: 18 | """Add documents to vectorstore.""" 19 | current_time = kwargs.get("current_time", datetime.now()) 20 | # Avoid mutating input documents 21 | dup_docs = [deepcopy(d) for d in documents] 22 | for i, doc in enumerate(dup_docs): 23 | if "last_accessed_at" not in doc.metadata: 24 | doc.metadata["last_accessed_at"] = str(current_time) 25 | if "created_at" not in doc.metadata: 26 | doc.metadata["created_at"] = str(current_time) 27 | doc.metadata["buffer_idx"] = len(self.memory_stream) + i 28 | self.memory_stream.extend(dup_docs) 29 | return self.vectorstore.add_documents(dup_docs, **kwargs) 30 | 31 | def _get_combined_score( 32 | self, 33 | document: Document, 34 | vector_relevance: Optional[float], 35 | current_time: datetime, 36 | ) -> float: 37 | """Return the combined score for a document.""" 38 | hours_passed = _get_hours_passed( 39 | current_time, 40 | document.metadata["last_accessed_at"], 41 | ) 42 | score = (1.0 - self.decay_rate) ** hours_passed 43 | for key in self.other_score_keys: 44 | if key in document.metadata: 45 | score += document.metadata[key] 46 | if vector_relevance is not None: 47 | score += vector_relevance 48 | return score 49 | -------------------------------------------------------------------------------- /generative_agents/llama_memory.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import re 3 | from datetime import datetime 4 | from typing import List 5 | 6 | from langchain import PromptTemplate 7 | from langchain.experimental.generative_agents.memory import \ 8 | GenerativeAgentMemory 9 | from langchain.schema import Document 10 | 11 | logger = logging.getLogger(__name__) 12 | 13 | 14 | class LlamaGenerativeAgentMemory(GenerativeAgentMemory): 15 | def _score_memory_importance(self, memory_content: str) -> float: 16 | """Score the absolute importance of the given memory.""" 17 | template = ( 18 | "On the scale of 1 to 10, where 1 is not important at all" 19 | + " (e.g., brushing teeth, making bed) and 10 is" 20 | + " extremely important (e.g., a break up, college" 21 | + " acceptance), rate the importance of the" 22 | + " following piece of memory. You must respond with a single integer." 23 | + "\nMemory: I met my wife Jane when I was 23" 24 | + "\nRating: 9" 25 | "\nMemory: I visited Italy in 2020" 26 | "\nRating: 5" 27 | "\nMemory: {memory_content}" 28 | "\nRating: " 29 | ) 30 | prompt = PromptTemplate.from_template(template) 31 | 32 | score = self.chain(prompt).run(memory_content=memory_content).strip() 33 | 34 | logger.warning(f"Importance score: {score}") 35 | match = re.search(r"^\D*(\d+)", score) 36 | if match: 37 | return (float(score[0]) / 10) * self.importance_weight 38 | else: 39 | return 0.0 40 | 41 | def format_memories_detail(self, relevant_memories: List[Document]) -> str: 42 | content_strs = set() 43 | content = [] 44 | for mem in relevant_memories: 45 | if mem.page_content in content_strs: 46 | continue 47 | content_strs.add(mem.page_content) 48 | created_time = datetime.fromisoformat(mem.metadata["created_at"]).strftime( 49 | "%B %d, %Y, %I:%M %p" 50 | ) 51 | content.append(f"- {created_time}: {mem.page_content.strip()}") 52 | return "\n".join([f"{mem}" for mem in content]) 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![image](https://user-images.githubusercontent.com/109661872/236526585-acc7b215-8181-4385-aadf-e908b6279251.png) 3 | 4 | 5 | 6 | # LLaMA Generative Agent 7 | A generative agent implementation for LLaMA based models, derived from langchain's implementation. 8 | 9 | Since LangChain and Chroma has introduced non-backward compatible changes, please **use the following versions:** 10 | 11 | - chroma: 0.3.21 12 | - langchain: 0.0.192 13 | 14 | **This project is still in its early stages. The generative agent's inference is currently quite slow and may not produce reasonable answers. Any suggestions or advice on improving its performance would be greatly appreciated!** 15 | 16 | 17 | 18 | # Demo 19 | To run the demo, you need to download a LLaMA based model from huggingface, for example: 20 | 21 | https://huggingface.co/eachadea/ggml-vicuna-13b-1.1/tree/main 22 | 23 | And replace the model path before runing the following notebook: 24 | 25 | https://github.com/UranusSeven/llama_generative_agent/blob/main/llama_generative_agent.ipynb 26 | 27 | ## Summary of a agent's core characteristics 28 | | | OpenAI | LLaMA | 29 | |---|---|---| 30 | | Without observations | No statements were provided about Tommie's core characteristics. | I'm sorry, I do not have enough information about "Tommie" to provide a summary of their core characteristics. Could you please provide more context or details about who or what Tommie refers to? | 31 | | With observations | Tommie is a tired, hungry person who is trying to get some rest after seeing a new home. He remembers his dog from when he was a kid and notices the new neighbors have a cat. The road noise at night may be bothering him. | 1. Tommie remembers his dog Bruno from when he was a kid. 2. Tommie sees the new home. 3. The road is noisy at night. 4. The new neighbors have a cat. 5. Tommie tries to get some rest. 6. Tommie feels tired from driving so far. 7. Tommie is hungry. | 32 | 33 | ## Memory’s importance score 34 | | Observation | importance score | 35 | |---|---| 36 | | Tommie remembers his dog, Bruno, from when he was a kid. | 8 | 37 | | Tommie feels tired from driving so far. | 1 | 38 | | Tommie sees the new home. | 8 | 39 | | The new neighbors have a cat. | 2 | 40 | | The road is noisy at night. | 2 | 41 | | Tommie is hungry. | 1 | 42 | | Tommie tries to get some rest. | 1 | 43 | 44 | ## Reaction 45 | ``` 46 | Observation: Tommie sees his neighbor's cat 47 | Reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything. 48 | ``` 49 | 50 | ## Dialogue 51 | ``` 52 | Dad: Have you got a new job? 53 | Tommie: No, I haven't found one yet. 54 | ``` 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | .idea/ 161 | 162 | # Chroma 163 | .chroma/ -------------------------------------------------------------------------------- /generative_agents/tests/test_agent.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from langchain import LlamaCpp 3 | from langchain.embeddings import LlamaCppEmbeddings 4 | 5 | from retrivers.llama_time_weighted_retriever import LlamaTimeWeightedVectorStoreRetriever 6 | from vectorestores.chroma import EnhancedChroma 7 | from ..llama_generative_agent import LlamaGenerativeAgent 8 | from ..llama_memory import LlamaGenerativeAgentMemory 9 | 10 | 11 | @pytest.fixture 12 | def model_path(): 13 | return "/Users/jon/Downloads/ggml-vicuna-13b-1.1-q4_2.bin" 14 | # return "/Users/jon/Documents/models/stable-vicuna-13B.ggml.q5_1.bin" 15 | 16 | 17 | @pytest.fixture 18 | def llm(model_path): 19 | return LlamaCpp(model_path=model_path, verbose=True, n_batch=256, temperature=0.3, n_ctx=2048, 20 | use_mmap=False, stop=["###"]) 21 | 22 | 23 | @pytest.fixture 24 | def retriever(model_path, llm): 25 | embeddings_model = LlamaCppEmbeddings(model_path=model_path) 26 | vs = EnhancedChroma(embedding_function=embeddings_model) 27 | return LlamaTimeWeightedVectorStoreRetriever( 28 | vectorstore=vs, 29 | other_score_keys=["importance"], k=15 30 | ) 31 | 32 | 33 | @pytest.fixture 34 | def memory(llm, retriever): 35 | return LlamaGenerativeAgentMemory( 36 | llm=llm, 37 | memory_retriever=retriever, 38 | reflection_threshold=8, 39 | # we will give this a relatively low number to show how reflection works 40 | verbose=True, 41 | ) 42 | 43 | 44 | @pytest.fixture 45 | def agent(retriever, memory, llm) -> LlamaGenerativeAgent: 46 | return LlamaGenerativeAgent( 47 | name="Tommie", 48 | age=25, 49 | traits="anxious, likes design, talkative", # You can add more persistent traits here 50 | status="looking for a job", 51 | # When connected to a virtual world, we can have the characters update their status 52 | memory_retriever=retriever, 53 | llm=llm, 54 | memory=memory, 55 | verbose=True, 56 | ) 57 | 58 | 59 | def test_compute_agent_summary(agent): 60 | # expected: No statements were provided about Tommie's core characteristics. 61 | for _ in range(5): 62 | print(agent.get_summary(force_refresh=True)) 63 | 64 | 65 | def test_get_entity_from_observation(agent): 66 | # expected: Jon 67 | print( 68 | agent._get_entity_from_observation("Jon says What are you most worried about today?") 69 | ) 70 | 71 | 72 | def test_get_entity_action(agent): 73 | # expected: Jon is asking what the person is most worried about on that day. 74 | print( 75 | agent._get_entity_action( 76 | "Jon says What are you most worried about today?", "Jon") 77 | ) 78 | 79 | 80 | def test_summarize_related_memories(agent): 81 | print( 82 | agent.summarize_related_memories( 83 | "Jon says What are you most worried about today?") 84 | ) 85 | 86 | 87 | def test_summarize_speaker_memories(agent): 88 | """ 89 | What is the relationship between Tommie and Person A? 90 | Context from memory: 91 | - May 04, 2023, 10:58 PM: Tommie sees the new home 92 | - May 04, 2023, 10:58 PM: Tommie remembers his dog, Bruno, from when he was a kid 93 | - May 04, 2023, 10:59 PM: Tommie is hungry 94 | - May 04, 2023, 11:00 PM: Tommie tries to get some rest. 95 | - May 04, 2023, 10:58 PM: Tommie feels tired from driving so far 96 | - May 04, 2023, 10:59 PM: The new neighbors have a cat 97 | - May 04, 2023, 10:59 PM: The road is noisy at night 98 | Relevant context: 99 | """ 100 | print( 101 | agent.summarize_speaker_memories("Jon", "What are you most worried about today?") 102 | ) 103 | 104 | 105 | def test_generate_dialogue(agent): 106 | print( 107 | agent.generate_dialogue("Jon", "What are you most worried about today?") 108 | ) 109 | -------------------------------------------------------------------------------- /vectorestores/chroma.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from typing import Any, Callable, Dict, List, Optional, Tuple 3 | 4 | import chromadb 5 | from chromadb.errors import NoIndexException 6 | from langchain.schema import Document 7 | from langchain.vectorstores import Chroma 8 | 9 | logger = logging.getLogger(__name__) 10 | 11 | 12 | def default_relevance_score_fn(score: float): 13 | import math 14 | 15 | return 1 / (1 + math.exp(-score / 100000)) - 0.5 16 | 17 | 18 | def _results_to_docs_and_scores(results: Any) -> List[Tuple[Document, float]]: 19 | return [ 20 | # TODO: Chroma can do batch querying, 21 | # we shouldn't hard code to the 1st result 22 | (Document(page_content=result[0], metadata=result[1] or {}), result[2]) 23 | for result in zip( 24 | results["documents"][0], 25 | results["metadatas"][0], 26 | results["distances"][0], 27 | ) 28 | ] 29 | 30 | 31 | class EnhancedChroma(Chroma): 32 | def __init__( 33 | self, 34 | relevance_score_fn: Callable[[float], float] = default_relevance_score_fn, 35 | **kwargs, 36 | ): 37 | super().__init__(**kwargs) 38 | self.relevance_score_fn = relevance_score_fn 39 | 40 | def _similarity_search_with_relevance_scores( 41 | self, query: str, k: int = 4, **kwargs: Any 42 | ) -> List[Tuple[Document, float]]: 43 | """Return docs and their similarity scores on a scale from 0 to 1.""" 44 | if self.relevance_score_fn is None: 45 | raise ValueError("a relevance_score_fn is required.") 46 | try: 47 | docs_and_scores = self.similarity_search_with_score(query, k=k) 48 | return [ 49 | (doc, self.relevance_score_fn(score)) for doc, score in docs_and_scores 50 | ] 51 | except NoIndexException: 52 | return [] 53 | 54 | def similarity_search_with_score( 55 | self, 56 | query: str, 57 | k: int = 4, 58 | filter: Optional[Dict[str, str]] = None, 59 | **kwargs: Any, 60 | ) -> List[Tuple[Document, float]]: 61 | """Run similarity search with Chroma with distance. 62 | 63 | Args: 64 | query (str): Query text to search for. 65 | k (int): Number of results to return. Defaults to 4. 66 | filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None. 67 | 68 | Returns: 69 | List[Tuple[Document, float]]: List of documents most similar to the query 70 | text with distance in float. 71 | """ 72 | if self._embedding_function is None: 73 | results = self.__query_collection( 74 | query_texts=[query], n_results=k, where=filter 75 | ) 76 | else: 77 | query_embedding = self._embedding_function.embed_query(query) 78 | results = self.__query_collection( 79 | query_embeddings=[query_embedding], n_results=k, where=filter 80 | ) 81 | 82 | return _results_to_docs_and_scores(results) 83 | 84 | def __query_collection( 85 | self, 86 | query_texts: Optional[List[str]] = None, 87 | query_embeddings: Optional[List[List[float]]] = None, 88 | n_results: int = 4, 89 | where: Optional[Dict[str, str]] = None, 90 | ) -> List[Document]: 91 | """Query the chroma collection.""" 92 | for i in range(n_results, 0, -1): 93 | try: 94 | return self._collection.query( 95 | query_texts=query_texts, 96 | query_embeddings=query_embeddings, 97 | n_results=i, 98 | where=where, 99 | ) 100 | except chromadb.errors.NotEnoughElementsException: 101 | logger.warning( 102 | f"Chroma collection {self._collection.name} " 103 | f"contains fewer than {i} elements." 104 | ) 105 | return [] 106 | -------------------------------------------------------------------------------- /generative_agents/llama_generative_agent.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from typing import Dict, Any 3 | 4 | from langchain import PromptTemplate, LLMChain 5 | from langchain.experimental.generative_agents.generative_agent import \ 6 | GenerativeAgent 7 | 8 | 9 | class LlamaGenerativeAgent(GenerativeAgent): 10 | 11 | system_prompt: str = ( 12 | "A chat between a curious user and an artificial intelligence assistant. The assistant " 13 | "gives helpful, detailed, and polite answers to the user's questions.\n" 14 | "###USER: %s\n" 15 | "###ASSISTANT: ") 16 | 17 | def chain(self, prompt: PromptTemplate) -> LLMChain: 18 | return LLMChain( 19 | llm=self.llm, prompt=prompt, verbose=self.verbose, memory=self.memory 20 | ) 21 | 22 | def _get_entity_from_observation(self, observation: str) -> str: 23 | # TODO: better prompt for conversations. 24 | instruction = ( 25 | f"Extract the entity from the following observation without explanation.\n" 26 | f"Observation: {observation}\n" 27 | ) 28 | prompt = PromptTemplate.from_template( 29 | self.system_prompt % instruction 30 | ) 31 | return self.chain(prompt).run(observation=observation).strip() 32 | 33 | def _get_entity_action(self, observation: str, entity_name: str) -> str: 34 | instruction = ( 35 | f"What is the {entity_name} doing in the following observation?\n" 36 | f"Observation: {observation}\n" 37 | ) 38 | prompt = PromptTemplate.from_template( 39 | self.system_prompt % instruction 40 | ) 41 | return ( 42 | self.chain(prompt).run(entity=entity_name, observation=observation).strip() 43 | ) 44 | 45 | def summarize_related_memories(self, observation: str) -> str: 46 | """Summarize memories that are most relevant to an observation.""" 47 | prompt = PromptTemplate.from_template( 48 | "{q1}?\n" 49 | "Context from memory:\n" 50 | "{relevant_memories}\n" 51 | "Relevant context:" 52 | ) 53 | entity_name = self._get_entity_from_observation(observation) 54 | entity_action = self._get_entity_action(observation, entity_name) 55 | q1 = f"What is the relationship between {self.name} and {entity_name}" 56 | q2 = f"{entity_name} is {entity_action}" 57 | return self.chain(prompt=prompt).run(q1=q1, queries=[q1, q2]).strip() 58 | 59 | def summarize_speaker_memories(self, speaker: str, observation: str) -> str: 60 | instruction = ( 61 | f"what is the most possible relationship between {self.name} and {speaker} in the" 62 | f" following observation? Do not embellish if you don't know. Do not return a list.\n" 63 | "Observation: {relevant_memories}\n" 64 | ) 65 | prompt = PromptTemplate.from_template( 66 | self.system_prompt % instruction 67 | ) 68 | return self.chain(prompt=prompt).run(me=self.name, speaker=speaker, queries=[f"{speaker}"]).strip() 69 | 70 | def _compute_agent_summary(self) -> str: 71 | instruction = ( 72 | f"Summarize {self.name}'s core characteristics given the following input. Do not " 73 | f"embellish if you don't know. Do not return a list.\n" 74 | "Input: {relevant_memories}\n" 75 | ) 76 | prompt = PromptTemplate.from_template( 77 | self.system_prompt % instruction 78 | ) 79 | # The agent seeks to think about their core characteristics. 80 | return ( 81 | self.chain(prompt) 82 | .run(name=self.name, queries=[f"{self.name}'s core characteristics"]) 83 | .strip() 84 | ) 85 | 86 | def _generate_dialogue_reaction(self, speaker: str, observation: str, suffix: str) -> str: 87 | """React to a given observation or dialogue act.""" 88 | prompt = PromptTemplate.from_template( 89 | "{agent_summary_description}" 90 | + "\nIt is {current_time}." 91 | + "\n{agent_name}'s status: {agent_status}" 92 | + "\nSummary of relevant context from {agent_name}'s memory:" 93 | + "\n{relevant_memories}" 94 | + "\nMost recent observations: {most_recent_memories}" 95 | + "\nObservation: {observation}" 96 | + "\n\n" 97 | + suffix 98 | ) 99 | agent_summary_description = self.get_summary() 100 | relevant_memories_str = self.summarize_speaker_memories(speaker, observation) 101 | current_time_str = datetime.now().strftime("%B %d, %Y, %I:%M %p") 102 | kwargs: Dict[str, Any] = dict( 103 | agent_summary_description=agent_summary_description, 104 | current_time=current_time_str, 105 | relevant_memories=relevant_memories_str, 106 | agent_name=self.name, 107 | observation= speaker + " says " + observation, 108 | agent_status=self.status, 109 | ) 110 | consumed_tokens = self.llm.get_num_tokens( 111 | prompt.format(most_recent_memories="", **kwargs) 112 | ) 113 | kwargs[self.memory.most_recent_memories_token_key] = consumed_tokens 114 | return self.chain(prompt=prompt).run(**kwargs).strip() 115 | 116 | def generate_dialogue(self, speaker: str, observation: str): 117 | """React to a given observation.""" 118 | call_to_action_template = ( 119 | "What would {agent_name} say? To end the conversation, write:" 120 | ' GOODBYE: "what to say". Otherwise to continue the conversation,' 121 | ' write: SAY: "what to say next"\n\n' 122 | ) 123 | full_result = self._generate_dialogue_reaction( 124 | speaker, 125 | observation, 126 | call_to_action_template 127 | ) 128 | result = full_result.strip().split("\n")[0] 129 | if "GOODBYE:" in result: 130 | farewell = self._clean_response(result.split("GOODBYE:")[-1]) 131 | self.memory.save_context( 132 | {}, 133 | { 134 | self.memory.add_memory_key: f"{self.name} observed " 135 | f"{observation} and said {farewell}" 136 | }, 137 | ) 138 | return False, f"{self.name} said {farewell}" 139 | if "SAY:" in result: 140 | response_text = self._clean_response(result.split("SAY:")[-1]) 141 | self.memory.save_context( 142 | {}, 143 | { 144 | self.memory.add_memory_key: f"{self.name} observed " 145 | f"{observation} and said {response_text}" 146 | }, 147 | ) 148 | return True, f"{self.name} said {response_text}" 149 | else: 150 | return False, result 151 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /llama_generative_agent.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "outputs": [ 7 | { 8 | "name": "stderr", 9 | "output_type": "stream", 10 | "text": [ 11 | "llama.cpp: loading model from /Users/jon/Downloads/ggml-vicuna-13b-1.1-q4_2.bin\n", 12 | "llama_model_load_internal: format = ggjt v1 (latest)\n", 13 | "llama_model_load_internal: n_vocab = 32000\n", 14 | "llama_model_load_internal: n_ctx = 2048\n", 15 | "llama_model_load_internal: n_embd = 5120\n", 16 | "llama_model_load_internal: n_mult = 256\n", 17 | "llama_model_load_internal: n_head = 40\n", 18 | "llama_model_load_internal: n_layer = 40\n", 19 | "llama_model_load_internal: n_rot = 128\n", 20 | "llama_model_load_internal: ftype = 5 (mostly Q4_2)\n", 21 | "llama_model_load_internal: n_ff = 13824\n", 22 | "llama_model_load_internal: n_parts = 1\n", 23 | "llama_model_load_internal: model size = 13B\n", 24 | "llama_model_load_internal: ggml ctx size = 7945693.73 KB\n", 25 | "llama_model_load_internal: mem required = 9807.47 MB (+ 1608.00 MB per state)\n", 26 | "....................................................................................................\n", 27 | "AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | VSX = 0 | \n", 28 | "llama_init_from_file: kv self size = 1600.00 MB\n", 29 | "llama.cpp: loading model from /Users/jon/Downloads/ggml-vicuna-13b-1.1-q4_2.bin\n", 30 | "llama_model_load_internal: format = ggjt v1 (latest)\n", 31 | "llama_model_load_internal: n_vocab = 32000\n", 32 | "llama_model_load_internal: n_ctx = 512\n", 33 | "llama_model_load_internal: n_embd = 5120\n", 34 | "llama_model_load_internal: n_mult = 256\n", 35 | "llama_model_load_internal: n_head = 40\n", 36 | "llama_model_load_internal: n_layer = 40\n", 37 | "llama_model_load_internal: n_rot = 128\n", 38 | "llama_model_load_internal: ftype = 5 (mostly Q4_2)\n", 39 | "llama_model_load_internal: n_ff = 13824\n", 40 | "llama_model_load_internal: n_parts = 1\n", 41 | "llama_model_load_internal: model size = 13B\n", 42 | "llama_model_load_internal: ggml ctx size = 73.73 KB\n", 43 | "llama_model_load_internal: mem required = 9807.47 MB (+ 3216.00 MB per state)\n", 44 | "llama_init_from_file: kv self size = 800.00 MB\n", 45 | "AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | VSX = 0 | \n", 46 | "Using embedded DuckDB without persistence: data will be transient\n", 47 | "llama.cpp: loading model from /Users/jon/Downloads/ggml-vicuna-13b-1.1-q4_2.bin\n", 48 | "llama_model_load_internal: format = ggjt v1 (latest)\n", 49 | "llama_model_load_internal: n_vocab = 32000\n", 50 | "llama_model_load_internal: n_ctx = 512\n", 51 | "llama_model_load_internal: n_embd = 5120\n", 52 | "llama_model_load_internal: n_mult = 256\n", 53 | "llama_model_load_internal: n_head = 40\n", 54 | "llama_model_load_internal: n_layer = 40\n", 55 | "llama_model_load_internal: n_rot = 128\n", 56 | "llama_model_load_internal: ftype = 5 (mostly Q4_2)\n", 57 | "llama_model_load_internal: n_ff = 13824\n", 58 | "llama_model_load_internal: n_parts = 1\n", 59 | "llama_model_load_internal: model size = 13B\n", 60 | "llama_model_load_internal: ggml ctx size = 73.73 KB\n", 61 | "llama_model_load_internal: mem required = 9807.47 MB (+ 3216.00 MB per state)\n", 62 | "llama_init_from_file: kv self size = 800.00 MB\n", 63 | "AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | VSX = 0 | \n", 64 | "Using embedded DuckDB without persistence: data will be transient\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "from langchain.llms import LlamaCpp\n", 70 | "from langchain.embeddings import LlamaCppEmbeddings\n", 71 | "\n", 72 | "# local_path = \"/Users/jon/Documents/models/stable-vicuna-13B.ggml.q5_1.bin\"\n", 73 | "local_path = \"/Users/jon/Downloads/ggml-vicuna-13b-1.1-q4_2.bin\"\n", 74 | "llm = LlamaCpp(\n", 75 | " model_path=local_path, verbose=True, n_batch=256, temperature=0.3, n_ctx=2048,\n", 76 | " use_mmap=False, stop=[\"###\"]\n", 77 | ")\n", 78 | "\n", 79 | "from retrivers.llama_time_weighted_retriever import LlamaTimeWeightedVectorStoreRetriever\n", 80 | "from vectorestores.chroma import EnhancedChroma\n", 81 | "\n", 82 | "def create_new_memory_retriever():\n", 83 | " embeddings_model = LlamaCppEmbeddings(model_path=local_path)\n", 84 | " vs = EnhancedChroma(embedding_function=embeddings_model)\n", 85 | " return LlamaTimeWeightedVectorStoreRetriever(vectorstore=vs, other_score_keys=[\"importance\"], k=15)\n", 86 | "\n", 87 | "from generative_agents.llama_generative_agent import LlamaGenerativeAgent\n", 88 | "from generative_agents.llama_memory import LlamaGenerativeAgentMemory\n", 89 | "\n", 90 | "tommies_memory = LlamaGenerativeAgentMemory(\n", 91 | " llm=llm,\n", 92 | " memory_retriever=create_new_memory_retriever(),\n", 93 | " reflection_threshold=8, # we will give this a relatively low number to show how reflection works\n", 94 | " verbose=True,\n", 95 | ")\n", 96 | "\n", 97 | "tommie = LlamaGenerativeAgent(\n", 98 | " name=\"Tommie\",\n", 99 | " age=25,\n", 100 | " traits=\"anxious, likes design, talkative\", # You can add more persistent traits here\n", 101 | " status=\"looking for a job\", # When connected to a virtual world, we can have the characters update their status\n", 102 | " memory_retriever=create_new_memory_retriever(),\n", 103 | " llm=llm,\n", 104 | " memory=tommies_memory,\n", 105 | " verbose=True,\n", 106 | ")" 107 | ], 108 | "metadata": { 109 | "collapsed": false 110 | } 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "outputs": [], 116 | "source": [ 117 | "print(tommie.get_summary(force_refresh=True))" 118 | ], 119 | "metadata": { 120 | "collapsed": false 121 | } 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 2, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "\n", 132 | "\n", 133 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 134 | "Prompt after formatting:\n", 135 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 136 | "Memory: I met my wife Jane when I was 23\n", 137 | "Rating: 9\n", 138 | "Memory: I visited Italy in 2020\n", 139 | "Rating: 5\n", 140 | "Memory: Tommie remembers his dog, Bruno, from when he was a kid\n", 141 | "Rating: \u001B[0m\n" 142 | ] 143 | }, 144 | { 145 | "name": "stderr", 146 | "output_type": "stream", 147 | "text": [ 148 | "Importance score: 8\n" 149 | ] 150 | }, 151 | { 152 | "name": "stdout", 153 | "output_type": "stream", 154 | "text": [ 155 | "\n", 156 | "\u001B[1m> Finished chain.\u001B[0m\n" 157 | ] 158 | }, 159 | { 160 | "name": "stderr", 161 | "output_type": "stream", 162 | "text": [ 163 | "\n", 164 | "llama_print_timings: load time = 4570.63 ms\n", 165 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 166 | "llama_print_timings: prompt eval time = 5717.18 ms / 16 tokens ( 357.32 ms per token)\n", 167 | "llama_print_timings: eval time = 146.13 ms / 1 runs ( 146.13 ms per run)\n", 168 | "llama_print_timings: total time = 5864.17 ms\n" 169 | ] 170 | }, 171 | { 172 | "name": "stdout", 173 | "output_type": "stream", 174 | "text": [ 175 | "\n", 176 | "\n", 177 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 178 | "Prompt after formatting:\n", 179 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 180 | "Memory: I met my wife Jane when I was 23\n", 181 | "Rating: 9\n", 182 | "Memory: I visited Italy in 2020\n", 183 | "Rating: 5\n", 184 | "Memory: Tommie feels tired from driving so far\n", 185 | "Rating: \u001B[0m\n" 186 | ] 187 | }, 188 | { 189 | "name": "stderr", 190 | "output_type": "stream", 191 | "text": [ 192 | "Importance score: 1\n", 193 | "\n", 194 | "I'm sorry, but it seems that you have provided a list of memories instead of a single memory for me to rate. Please provide a single memory for me to rate on the scale of 1 to 10.\n" 195 | ] 196 | }, 197 | { 198 | "name": "stdout", 199 | "output_type": "stream", 200 | "text": [ 201 | "\n", 202 | "\u001B[1m> Finished chain.\u001B[0m\n" 203 | ] 204 | }, 205 | { 206 | "name": "stderr", 207 | "output_type": "stream", 208 | "text": [ 209 | "\n", 210 | "llama_print_timings: load time = 4570.63 ms\n", 211 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 212 | "llama_print_timings: prompt eval time = 7696.15 ms / 10 tokens ( 769.62 ms per token)\n", 213 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 214 | "llama_print_timings: total time = 7697.14 ms\n" 215 | ] 216 | }, 217 | { 218 | "name": "stdout", 219 | "output_type": "stream", 220 | "text": [ 221 | "\n", 222 | "\n", 223 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 224 | "Prompt after formatting:\n", 225 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 226 | "Memory: I met my wife Jane when I was 23\n", 227 | "Rating: 9\n", 228 | "Memory: I visited Italy in 2020\n", 229 | "Rating: 5\n", 230 | "Memory: Tommie sees the new home\n", 231 | "Rating: \u001B[0m\n" 232 | ] 233 | }, 234 | { 235 | "name": "stderr", 236 | "output_type": "stream", 237 | "text": [ 238 | "Importance score: 8\n" 239 | ] 240 | }, 241 | { 242 | "name": "stdout", 243 | "output_type": "stream", 244 | "text": [ 245 | "\n", 246 | "\u001B[1m> Finished chain.\u001B[0m\n" 247 | ] 248 | }, 249 | { 250 | "name": "stderr", 251 | "output_type": "stream", 252 | "text": [ 253 | "\n", 254 | "llama_print_timings: load time = 4570.63 ms\n", 255 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 256 | "llama_print_timings: prompt eval time = 1142.62 ms / 8 tokens ( 142.83 ms per token)\n", 257 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 258 | "llama_print_timings: total time = 1142.95 ms\n" 259 | ] 260 | }, 261 | { 262 | "name": "stdout", 263 | "output_type": "stream", 264 | "text": [ 265 | "\n", 266 | "\n", 267 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 268 | "Prompt after formatting:\n", 269 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 270 | "Memory: I met my wife Jane when I was 23\n", 271 | "Rating: 9\n", 272 | "Memory: I visited Italy in 2020\n", 273 | "Rating: 5\n", 274 | "Memory: The new neighbors have a cat\n", 275 | "Rating: \u001B[0m\n" 276 | ] 277 | }, 278 | { 279 | "name": "stderr", 280 | "output_type": "stream", 281 | "text": [ 282 | "Importance score: 2\n" 283 | ] 284 | }, 285 | { 286 | "name": "stdout", 287 | "output_type": "stream", 288 | "text": [ 289 | "\n", 290 | "\u001B[1m> Finished chain.\u001B[0m\n" 291 | ] 292 | }, 293 | { 294 | "name": "stderr", 295 | "output_type": "stream", 296 | "text": [ 297 | "\n", 298 | "llama_print_timings: load time = 4570.63 ms\n", 299 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 300 | "llama_print_timings: prompt eval time = 1054.49 ms / 8 tokens ( 131.81 ms per token)\n", 301 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 302 | "llama_print_timings: total time = 1054.75 ms\n" 303 | ] 304 | }, 305 | { 306 | "name": "stdout", 307 | "output_type": "stream", 308 | "text": [ 309 | "\n", 310 | "\n", 311 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 312 | "Prompt after formatting:\n", 313 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 314 | "Memory: I met my wife Jane when I was 23\n", 315 | "Rating: 9\n", 316 | "Memory: I visited Italy in 2020\n", 317 | "Rating: 5\n", 318 | "Memory: The road is noisy at night\n", 319 | "Rating: \u001B[0m\n" 320 | ] 321 | }, 322 | { 323 | "name": "stderr", 324 | "output_type": "stream", 325 | "text": [ 326 | "Importance score: 2\n" 327 | ] 328 | }, 329 | { 330 | "name": "stdout", 331 | "output_type": "stream", 332 | "text": [ 333 | "\n", 334 | "\u001B[1m> Finished chain.\u001B[0m\n" 335 | ] 336 | }, 337 | { 338 | "name": "stderr", 339 | "output_type": "stream", 340 | "text": [ 341 | "\n", 342 | "llama_print_timings: load time = 4570.63 ms\n", 343 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 344 | "llama_print_timings: prompt eval time = 1050.12 ms / 8 tokens ( 131.26 ms per token)\n", 345 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 346 | "llama_print_timings: total time = 1050.37 ms\n" 347 | ] 348 | }, 349 | { 350 | "name": "stdout", 351 | "output_type": "stream", 352 | "text": [ 353 | "\n", 354 | "\n", 355 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 356 | "Prompt after formatting:\n", 357 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 358 | "Memory: I met my wife Jane when I was 23\n", 359 | "Rating: 9\n", 360 | "Memory: I visited Italy in 2020\n", 361 | "Rating: 5\n", 362 | "Memory: Tommie is hungry\n", 363 | "Rating: \u001B[0m\n" 364 | ] 365 | }, 366 | { 367 | "name": "stderr", 368 | "output_type": "stream", 369 | "text": [ 370 | "Importance score: 1\n", 371 | "\n", 372 | "What is the rating for the memory \"I met my wife Jane when I was 23\"?\n" 373 | ] 374 | }, 375 | { 376 | "name": "stdout", 377 | "output_type": "stream", 378 | "text": [ 379 | "\n", 380 | "\u001B[1m> Finished chain.\u001B[0m\n" 381 | ] 382 | }, 383 | { 384 | "name": "stderr", 385 | "output_type": "stream", 386 | "text": [ 387 | "\n", 388 | "llama_print_timings: load time = 4570.63 ms\n", 389 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 390 | "llama_print_timings: prompt eval time = 4872.59 ms / 7 tokens ( 696.08 ms per token)\n", 391 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 392 | "llama_print_timings: total time = 4872.86 ms\n" 393 | ] 394 | }, 395 | { 396 | "name": "stdout", 397 | "output_type": "stream", 398 | "text": [ 399 | "\n", 400 | "\n", 401 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 402 | "Prompt after formatting:\n", 403 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 404 | "Memory: I met my wife Jane when I was 23\n", 405 | "Rating: 9\n", 406 | "Memory: I visited Italy in 2020\n", 407 | "Rating: 5\n", 408 | "Memory: Tommie tries to get some rest.\n", 409 | "Rating: \u001B[0m\n" 410 | ] 411 | }, 412 | { 413 | "name": "stderr", 414 | "output_type": "stream", 415 | "text": [ 416 | "Importance score: 1\n" 417 | ] 418 | }, 419 | { 420 | "name": "stdout", 421 | "output_type": "stream", 422 | "text": [ 423 | "\n", 424 | "\u001B[1m> Finished chain.\u001B[0m\n" 425 | ] 426 | }, 427 | { 428 | "name": "stderr", 429 | "output_type": "stream", 430 | "text": [ 431 | "\n", 432 | "llama_print_timings: load time = 4570.63 ms\n", 433 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 434 | "llama_print_timings: prompt eval time = 2602.25 ms / 10 tokens ( 260.22 ms per token)\n", 435 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 436 | "llama_print_timings: total time = 2602.77 ms\n" 437 | ] 438 | } 439 | ], 440 | "source": [ 441 | "# We can add memories directly to the memory object\n", 442 | "tommie_observations = [\n", 443 | " \"Tommie remembers his dog, Bruno, from when he was a kid\",\n", 444 | " \"Tommie feels tired from driving so far\",\n", 445 | " \"Tommie sees the new home\",\n", 446 | " \"The new neighbors have a cat\",\n", 447 | " \"The road is noisy at night\",\n", 448 | " \"Tommie is hungry\",\n", 449 | " \"Tommie tries to get some rest.\",\n", 450 | "]\n", 451 | "for observation in tommie_observations:\n", 452 | " tommie.memory.add_memory(observation)" 453 | ], 454 | "metadata": { 455 | "collapsed": false 456 | } 457 | }, 458 | { 459 | "cell_type": "code", 460 | "execution_count": 3, 461 | "outputs": [ 462 | { 463 | "name": "stderr", 464 | "output_type": "stream", 465 | "text": [ 466 | "\n", 467 | "llama_print_timings: load time = 4570.63 ms\n", 468 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 469 | "llama_print_timings: prompt eval time = 8329.16 ms / 8 tokens ( 1041.14 ms per token)\n", 470 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 471 | "llama_print_timings: total time = 8329.91 ms\n", 472 | "Chroma collection langchain contains fewer than 100 elements.\n", 473 | "Chroma collection langchain contains fewer than 99 elements.\n", 474 | "Chroma collection langchain contains fewer than 98 elements.\n", 475 | "Chroma collection langchain contains fewer than 97 elements.\n", 476 | "Chroma collection langchain contains fewer than 96 elements.\n", 477 | "Chroma collection langchain contains fewer than 95 elements.\n", 478 | "Chroma collection langchain contains fewer than 94 elements.\n", 479 | "Chroma collection langchain contains fewer than 93 elements.\n", 480 | "Chroma collection langchain contains fewer than 92 elements.\n", 481 | "Chroma collection langchain contains fewer than 91 elements.\n", 482 | "Chroma collection langchain contains fewer than 90 elements.\n", 483 | "Chroma collection langchain contains fewer than 89 elements.\n", 484 | "Chroma collection langchain contains fewer than 88 elements.\n", 485 | "Chroma collection langchain contains fewer than 87 elements.\n", 486 | "Chroma collection langchain contains fewer than 86 elements.\n", 487 | "Chroma collection langchain contains fewer than 85 elements.\n", 488 | "Chroma collection langchain contains fewer than 84 elements.\n", 489 | "Chroma collection langchain contains fewer than 83 elements.\n", 490 | "Chroma collection langchain contains fewer than 82 elements.\n", 491 | "Chroma collection langchain contains fewer than 81 elements.\n", 492 | "Chroma collection langchain contains fewer than 80 elements.\n", 493 | "Chroma collection langchain contains fewer than 79 elements.\n", 494 | "Chroma collection langchain contains fewer than 78 elements.\n", 495 | "Chroma collection langchain contains fewer than 77 elements.\n", 496 | "Chroma collection langchain contains fewer than 76 elements.\n", 497 | "Chroma collection langchain contains fewer than 75 elements.\n", 498 | "Chroma collection langchain contains fewer than 74 elements.\n", 499 | "Chroma collection langchain contains fewer than 73 elements.\n", 500 | "Chroma collection langchain contains fewer than 72 elements.\n", 501 | "Chroma collection langchain contains fewer than 71 elements.\n", 502 | "Chroma collection langchain contains fewer than 70 elements.\n", 503 | "Chroma collection langchain contains fewer than 69 elements.\n", 504 | "Chroma collection langchain contains fewer than 68 elements.\n", 505 | "Chroma collection langchain contains fewer than 67 elements.\n", 506 | "Chroma collection langchain contains fewer than 66 elements.\n", 507 | "Chroma collection langchain contains fewer than 65 elements.\n", 508 | "Chroma collection langchain contains fewer than 64 elements.\n", 509 | "Chroma collection langchain contains fewer than 63 elements.\n", 510 | "Chroma collection langchain contains fewer than 62 elements.\n", 511 | "Chroma collection langchain contains fewer than 61 elements.\n", 512 | "Chroma collection langchain contains fewer than 60 elements.\n", 513 | "Chroma collection langchain contains fewer than 59 elements.\n", 514 | "Chroma collection langchain contains fewer than 58 elements.\n", 515 | "Chroma collection langchain contains fewer than 57 elements.\n", 516 | "Chroma collection langchain contains fewer than 56 elements.\n", 517 | "Chroma collection langchain contains fewer than 55 elements.\n", 518 | "Chroma collection langchain contains fewer than 54 elements.\n", 519 | "Chroma collection langchain contains fewer than 53 elements.\n", 520 | "Chroma collection langchain contains fewer than 52 elements.\n", 521 | "Chroma collection langchain contains fewer than 51 elements.\n", 522 | "Chroma collection langchain contains fewer than 50 elements.\n", 523 | "Chroma collection langchain contains fewer than 49 elements.\n", 524 | "Chroma collection langchain contains fewer than 48 elements.\n", 525 | "Chroma collection langchain contains fewer than 47 elements.\n", 526 | "Chroma collection langchain contains fewer than 46 elements.\n", 527 | "Chroma collection langchain contains fewer than 45 elements.\n", 528 | "Chroma collection langchain contains fewer than 44 elements.\n", 529 | "Chroma collection langchain contains fewer than 43 elements.\n", 530 | "Chroma collection langchain contains fewer than 42 elements.\n", 531 | "Chroma collection langchain contains fewer than 41 elements.\n", 532 | "Chroma collection langchain contains fewer than 40 elements.\n", 533 | "Chroma collection langchain contains fewer than 39 elements.\n", 534 | "Chroma collection langchain contains fewer than 38 elements.\n", 535 | "Chroma collection langchain contains fewer than 37 elements.\n", 536 | "Chroma collection langchain contains fewer than 36 elements.\n", 537 | "Chroma collection langchain contains fewer than 35 elements.\n", 538 | "Chroma collection langchain contains fewer than 34 elements.\n", 539 | "Chroma collection langchain contains fewer than 33 elements.\n", 540 | "Chroma collection langchain contains fewer than 32 elements.\n", 541 | "Chroma collection langchain contains fewer than 31 elements.\n", 542 | "Chroma collection langchain contains fewer than 30 elements.\n", 543 | "Chroma collection langchain contains fewer than 29 elements.\n", 544 | "Chroma collection langchain contains fewer than 28 elements.\n", 545 | "Chroma collection langchain contains fewer than 27 elements.\n", 546 | "Chroma collection langchain contains fewer than 26 elements.\n", 547 | "Chroma collection langchain contains fewer than 25 elements.\n", 548 | "Chroma collection langchain contains fewer than 24 elements.\n", 549 | "Chroma collection langchain contains fewer than 23 elements.\n", 550 | "Chroma collection langchain contains fewer than 22 elements.\n", 551 | "Chroma collection langchain contains fewer than 21 elements.\n", 552 | "Chroma collection langchain contains fewer than 20 elements.\n", 553 | "Chroma collection langchain contains fewer than 19 elements.\n", 554 | "Chroma collection langchain contains fewer than 18 elements.\n", 555 | "Chroma collection langchain contains fewer than 17 elements.\n", 556 | "Chroma collection langchain contains fewer than 16 elements.\n", 557 | "Chroma collection langchain contains fewer than 15 elements.\n", 558 | "Chroma collection langchain contains fewer than 14 elements.\n", 559 | "Chroma collection langchain contains fewer than 13 elements.\n", 560 | "Chroma collection langchain contains fewer than 12 elements.\n", 561 | "Chroma collection langchain contains fewer than 11 elements.\n", 562 | "Chroma collection langchain contains fewer than 10 elements.\n", 563 | "Chroma collection langchain contains fewer than 9 elements.\n", 564 | "Chroma collection langchain contains fewer than 8 elements.\n" 565 | ] 566 | }, 567 | { 568 | "name": "stdout", 569 | "output_type": "stream", 570 | "text": [ 571 | "\n", 572 | "\n", 573 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 574 | "Prompt after formatting:\n", 575 | "\u001B[32;1m\u001B[1;3mA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n", 576 | "###USER: Summarize Tommie's core characteristics given the following input. Do not embellish if you don't know. Do not return a list.\n", 577 | "Input: - May 05, 2023, 11:24 PM: Tommie remembers his dog, Bruno, from when he was a kid\n", 578 | "- May 05, 2023, 11:25 PM: Tommie sees the new home\n", 579 | "- May 05, 2023, 11:25 PM: The road is noisy at night\n", 580 | "- May 05, 2023, 11:25 PM: The new neighbors have a cat\n", 581 | "- May 05, 2023, 11:25 PM: Tommie tries to get some rest.\n", 582 | "- May 05, 2023, 11:24 PM: Tommie feels tired from driving so far\n", 583 | "- May 05, 2023, 11:25 PM: Tommie is hungry\n", 584 | "\n", 585 | "###ASSISTANT: \u001B[0m\n", 586 | "\n", 587 | "\u001B[1m> Finished chain.\u001B[0m\n", 588 | "Name: Tommie (age: 25)\n", 589 | "Innate traits: anxious, likes design, talkative\n", 590 | "1. Tommie remembers his dog Bruno from when he was a kid.\n", 591 | "2. Tommie sees the new home.\n", 592 | "3. The road is noisy at night.\n", 593 | "4. The new neighbors have a cat.\n", 594 | "5. Tommie tries to get some rest.\n", 595 | "6. Tommie feels tired from driving so far.\n", 596 | "7. Tommie is hungry.\n" 597 | ] 598 | } 599 | ], 600 | "source": [ 601 | "# Now that Tommie has 'memories', their self-summary is more descriptive, though still rudimentary.\n", 602 | "# We will see how this summary updates after more observations to create a more rich description.\n", 603 | "print(tommie.get_summary(force_refresh=True))" 604 | ], 605 | "metadata": { 606 | "collapsed": false 607 | } 608 | }, 609 | { 610 | "cell_type": "code", 611 | "execution_count": 6, 612 | "outputs": [ 613 | { 614 | "name": "stdout", 615 | "output_type": "stream", 616 | "text": [ 617 | "\n", 618 | "\n", 619 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 620 | "Prompt after formatting:\n", 621 | "\u001B[32;1m\u001B[1;3mA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n", 622 | "###USER: Extract the entity from the following observation without explanation.\n", 623 | "Observation: Tommie sees his neighbor's cat\n", 624 | "\n", 625 | "###ASSISTANT: \u001B[0m\n", 626 | "\n", 627 | "\u001B[1m> Finished chain.\u001B[0m\n", 628 | "\n", 629 | "\n", 630 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 631 | "Prompt after formatting:\n", 632 | "\u001B[32;1m\u001B[1;3mA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n", 633 | "###USER: What is the ​ doing in the following observation?\n", 634 | "Observation: Tommie sees his neighbor's cat\n", 635 | "\n", 636 | "###ASSISTANT: \u001B[0m\n", 637 | "\n", 638 | "\u001B[1m> Finished chain.\u001B[0m\n" 639 | ] 640 | }, 641 | { 642 | "name": "stderr", 643 | "output_type": "stream", 644 | "text": [ 645 | "\n", 646 | "llama_print_timings: load time = 4570.63 ms\n", 647 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 648 | "llama_print_timings: prompt eval time = 8955.84 ms / 12 tokens ( 746.32 ms per token)\n", 649 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 650 | "llama_print_timings: total time = 8956.70 ms\n", 651 | "Chroma collection langchain contains fewer than 100 elements.\n", 652 | "Chroma collection langchain contains fewer than 99 elements.\n", 653 | "Chroma collection langchain contains fewer than 98 elements.\n", 654 | "Chroma collection langchain contains fewer than 97 elements.\n", 655 | "Chroma collection langchain contains fewer than 96 elements.\n", 656 | "Chroma collection langchain contains fewer than 95 elements.\n", 657 | "Chroma collection langchain contains fewer than 94 elements.\n", 658 | "Chroma collection langchain contains fewer than 93 elements.\n", 659 | "Chroma collection langchain contains fewer than 92 elements.\n", 660 | "Chroma collection langchain contains fewer than 91 elements.\n", 661 | "Chroma collection langchain contains fewer than 90 elements.\n", 662 | "Chroma collection langchain contains fewer than 89 elements.\n", 663 | "Chroma collection langchain contains fewer than 88 elements.\n", 664 | "Chroma collection langchain contains fewer than 87 elements.\n", 665 | "Chroma collection langchain contains fewer than 86 elements.\n", 666 | "Chroma collection langchain contains fewer than 85 elements.\n", 667 | "Chroma collection langchain contains fewer than 84 elements.\n", 668 | "Chroma collection langchain contains fewer than 83 elements.\n", 669 | "Chroma collection langchain contains fewer than 82 elements.\n", 670 | "Chroma collection langchain contains fewer than 81 elements.\n", 671 | "Chroma collection langchain contains fewer than 80 elements.\n", 672 | "Chroma collection langchain contains fewer than 79 elements.\n", 673 | "Chroma collection langchain contains fewer than 78 elements.\n", 674 | "Chroma collection langchain contains fewer than 77 elements.\n", 675 | "Chroma collection langchain contains fewer than 76 elements.\n", 676 | "Chroma collection langchain contains fewer than 75 elements.\n", 677 | "Chroma collection langchain contains fewer than 74 elements.\n", 678 | "Chroma collection langchain contains fewer than 73 elements.\n", 679 | "Chroma collection langchain contains fewer than 72 elements.\n", 680 | "Chroma collection langchain contains fewer than 71 elements.\n", 681 | "Chroma collection langchain contains fewer than 70 elements.\n", 682 | "Chroma collection langchain contains fewer than 69 elements.\n", 683 | "Chroma collection langchain contains fewer than 68 elements.\n", 684 | "Chroma collection langchain contains fewer than 67 elements.\n", 685 | "Chroma collection langchain contains fewer than 66 elements.\n", 686 | "Chroma collection langchain contains fewer than 65 elements.\n", 687 | "Chroma collection langchain contains fewer than 64 elements.\n", 688 | "Chroma collection langchain contains fewer than 63 elements.\n", 689 | "Chroma collection langchain contains fewer than 62 elements.\n", 690 | "Chroma collection langchain contains fewer than 61 elements.\n", 691 | "Chroma collection langchain contains fewer than 60 elements.\n", 692 | "Chroma collection langchain contains fewer than 59 elements.\n", 693 | "Chroma collection langchain contains fewer than 58 elements.\n", 694 | "Chroma collection langchain contains fewer than 57 elements.\n", 695 | "Chroma collection langchain contains fewer than 56 elements.\n", 696 | "Chroma collection langchain contains fewer than 55 elements.\n", 697 | "Chroma collection langchain contains fewer than 54 elements.\n", 698 | "Chroma collection langchain contains fewer than 53 elements.\n", 699 | "Chroma collection langchain contains fewer than 52 elements.\n", 700 | "Chroma collection langchain contains fewer than 51 elements.\n", 701 | "Chroma collection langchain contains fewer than 50 elements.\n", 702 | "Chroma collection langchain contains fewer than 49 elements.\n", 703 | "Chroma collection langchain contains fewer than 48 elements.\n", 704 | "Chroma collection langchain contains fewer than 47 elements.\n", 705 | "Chroma collection langchain contains fewer than 46 elements.\n", 706 | "Chroma collection langchain contains fewer than 45 elements.\n", 707 | "Chroma collection langchain contains fewer than 44 elements.\n", 708 | "Chroma collection langchain contains fewer than 43 elements.\n", 709 | "Chroma collection langchain contains fewer than 42 elements.\n", 710 | "Chroma collection langchain contains fewer than 41 elements.\n", 711 | "Chroma collection langchain contains fewer than 40 elements.\n", 712 | "Chroma collection langchain contains fewer than 39 elements.\n", 713 | "Chroma collection langchain contains fewer than 38 elements.\n", 714 | "Chroma collection langchain contains fewer than 37 elements.\n", 715 | "Chroma collection langchain contains fewer than 36 elements.\n", 716 | "Chroma collection langchain contains fewer than 35 elements.\n", 717 | "Chroma collection langchain contains fewer than 34 elements.\n", 718 | "Chroma collection langchain contains fewer than 33 elements.\n", 719 | "Chroma collection langchain contains fewer than 32 elements.\n", 720 | "Chroma collection langchain contains fewer than 31 elements.\n", 721 | "Chroma collection langchain contains fewer than 30 elements.\n", 722 | "Chroma collection langchain contains fewer than 29 elements.\n", 723 | "Chroma collection langchain contains fewer than 28 elements.\n", 724 | "Chroma collection langchain contains fewer than 27 elements.\n", 725 | "Chroma collection langchain contains fewer than 26 elements.\n", 726 | "Chroma collection langchain contains fewer than 25 elements.\n", 727 | "Chroma collection langchain contains fewer than 24 elements.\n", 728 | "Chroma collection langchain contains fewer than 23 elements.\n", 729 | "Chroma collection langchain contains fewer than 22 elements.\n", 730 | "Chroma collection langchain contains fewer than 21 elements.\n", 731 | "Chroma collection langchain contains fewer than 20 elements.\n", 732 | "Chroma collection langchain contains fewer than 19 elements.\n", 733 | "Chroma collection langchain contains fewer than 18 elements.\n", 734 | "Chroma collection langchain contains fewer than 17 elements.\n", 735 | "Chroma collection langchain contains fewer than 16 elements.\n", 736 | "Chroma collection langchain contains fewer than 15 elements.\n", 737 | "Chroma collection langchain contains fewer than 14 elements.\n", 738 | "Chroma collection langchain contains fewer than 13 elements.\n", 739 | "Chroma collection langchain contains fewer than 12 elements.\n", 740 | "Chroma collection langchain contains fewer than 11 elements.\n", 741 | "Chroma collection langchain contains fewer than 10 elements.\n", 742 | "Chroma collection langchain contains fewer than 9 elements.\n", 743 | "\n", 744 | "llama_print_timings: load time = 4570.63 ms\n", 745 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 746 | "llama_print_timings: prompt eval time = 654.02 ms / 5 tokens ( 130.80 ms per token)\n", 747 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 748 | "llama_print_timings: total time = 654.23 ms\n", 749 | "Chroma collection langchain contains fewer than 100 elements.\n", 750 | "Chroma collection langchain contains fewer than 99 elements.\n", 751 | "Chroma collection langchain contains fewer than 98 elements.\n", 752 | "Chroma collection langchain contains fewer than 97 elements.\n", 753 | "Chroma collection langchain contains fewer than 96 elements.\n", 754 | "Chroma collection langchain contains fewer than 95 elements.\n", 755 | "Chroma collection langchain contains fewer than 94 elements.\n", 756 | "Chroma collection langchain contains fewer than 93 elements.\n", 757 | "Chroma collection langchain contains fewer than 92 elements.\n", 758 | "Chroma collection langchain contains fewer than 91 elements.\n", 759 | "Chroma collection langchain contains fewer than 90 elements.\n", 760 | "Chroma collection langchain contains fewer than 89 elements.\n", 761 | "Chroma collection langchain contains fewer than 88 elements.\n", 762 | "Chroma collection langchain contains fewer than 87 elements.\n", 763 | "Chroma collection langchain contains fewer than 86 elements.\n", 764 | "Chroma collection langchain contains fewer than 85 elements.\n", 765 | "Chroma collection langchain contains fewer than 84 elements.\n", 766 | "Chroma collection langchain contains fewer than 83 elements.\n", 767 | "Chroma collection langchain contains fewer than 82 elements.\n", 768 | "Chroma collection langchain contains fewer than 81 elements.\n", 769 | "Chroma collection langchain contains fewer than 80 elements.\n", 770 | "Chroma collection langchain contains fewer than 79 elements.\n", 771 | "Chroma collection langchain contains fewer than 78 elements.\n", 772 | "Chroma collection langchain contains fewer than 77 elements.\n", 773 | "Chroma collection langchain contains fewer than 76 elements.\n", 774 | "Chroma collection langchain contains fewer than 75 elements.\n", 775 | "Chroma collection langchain contains fewer than 74 elements.\n", 776 | "Chroma collection langchain contains fewer than 73 elements.\n", 777 | "Chroma collection langchain contains fewer than 72 elements.\n", 778 | "Chroma collection langchain contains fewer than 71 elements.\n", 779 | "Chroma collection langchain contains fewer than 70 elements.\n", 780 | "Chroma collection langchain contains fewer than 69 elements.\n", 781 | "Chroma collection langchain contains fewer than 68 elements.\n", 782 | "Chroma collection langchain contains fewer than 67 elements.\n", 783 | "Chroma collection langchain contains fewer than 66 elements.\n", 784 | "Chroma collection langchain contains fewer than 65 elements.\n", 785 | "Chroma collection langchain contains fewer than 64 elements.\n", 786 | "Chroma collection langchain contains fewer than 63 elements.\n", 787 | "Chroma collection langchain contains fewer than 62 elements.\n", 788 | "Chroma collection langchain contains fewer than 61 elements.\n", 789 | "Chroma collection langchain contains fewer than 60 elements.\n", 790 | "Chroma collection langchain contains fewer than 59 elements.\n", 791 | "Chroma collection langchain contains fewer than 58 elements.\n", 792 | "Chroma collection langchain contains fewer than 57 elements.\n", 793 | "Chroma collection langchain contains fewer than 56 elements.\n", 794 | "Chroma collection langchain contains fewer than 55 elements.\n", 795 | "Chroma collection langchain contains fewer than 54 elements.\n", 796 | "Chroma collection langchain contains fewer than 53 elements.\n", 797 | "Chroma collection langchain contains fewer than 52 elements.\n", 798 | "Chroma collection langchain contains fewer than 51 elements.\n", 799 | "Chroma collection langchain contains fewer than 50 elements.\n", 800 | "Chroma collection langchain contains fewer than 49 elements.\n", 801 | "Chroma collection langchain contains fewer than 48 elements.\n", 802 | "Chroma collection langchain contains fewer than 47 elements.\n", 803 | "Chroma collection langchain contains fewer than 46 elements.\n", 804 | "Chroma collection langchain contains fewer than 45 elements.\n", 805 | "Chroma collection langchain contains fewer than 44 elements.\n", 806 | "Chroma collection langchain contains fewer than 43 elements.\n", 807 | "Chroma collection langchain contains fewer than 42 elements.\n", 808 | "Chroma collection langchain contains fewer than 41 elements.\n", 809 | "Chroma collection langchain contains fewer than 40 elements.\n", 810 | "Chroma collection langchain contains fewer than 39 elements.\n", 811 | "Chroma collection langchain contains fewer than 38 elements.\n", 812 | "Chroma collection langchain contains fewer than 37 elements.\n", 813 | "Chroma collection langchain contains fewer than 36 elements.\n", 814 | "Chroma collection langchain contains fewer than 35 elements.\n", 815 | "Chroma collection langchain contains fewer than 34 elements.\n", 816 | "Chroma collection langchain contains fewer than 33 elements.\n", 817 | "Chroma collection langchain contains fewer than 32 elements.\n", 818 | "Chroma collection langchain contains fewer than 31 elements.\n", 819 | "Chroma collection langchain contains fewer than 30 elements.\n", 820 | "Chroma collection langchain contains fewer than 29 elements.\n", 821 | "Chroma collection langchain contains fewer than 28 elements.\n", 822 | "Chroma collection langchain contains fewer than 27 elements.\n", 823 | "Chroma collection langchain contains fewer than 26 elements.\n", 824 | "Chroma collection langchain contains fewer than 25 elements.\n", 825 | "Chroma collection langchain contains fewer than 24 elements.\n", 826 | "Chroma collection langchain contains fewer than 23 elements.\n", 827 | "Chroma collection langchain contains fewer than 22 elements.\n", 828 | "Chroma collection langchain contains fewer than 21 elements.\n", 829 | "Chroma collection langchain contains fewer than 20 elements.\n", 830 | "Chroma collection langchain contains fewer than 19 elements.\n", 831 | "Chroma collection langchain contains fewer than 18 elements.\n", 832 | "Chroma collection langchain contains fewer than 17 elements.\n", 833 | "Chroma collection langchain contains fewer than 16 elements.\n", 834 | "Chroma collection langchain contains fewer than 15 elements.\n", 835 | "Chroma collection langchain contains fewer than 14 elements.\n", 836 | "Chroma collection langchain contains fewer than 13 elements.\n", 837 | "Chroma collection langchain contains fewer than 12 elements.\n", 838 | "Chroma collection langchain contains fewer than 11 elements.\n", 839 | "Chroma collection langchain contains fewer than 10 elements.\n", 840 | "Chroma collection langchain contains fewer than 9 elements.\n" 841 | ] 842 | }, 843 | { 844 | "name": "stdout", 845 | "output_type": "stream", 846 | "text": [ 847 | "\n", 848 | "\n", 849 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 850 | "Prompt after formatting:\n", 851 | "\u001B[32;1m\u001B[1;3mWhat is the relationship between Tommie and ​?\n", 852 | "Context from memory:\n", 853 | "- May 05, 2023, 11:24 PM: Tommie remembers his dog, Bruno, from when he was a kid\n", 854 | "- May 05, 2023, 11:25 PM: Tommie sees the new home\n", 855 | "- May 05, 2023, 11:25 PM: The road is noisy at night\n", 856 | "- May 05, 2023, 11:25 PM: The new neighbors have a cat\n", 857 | "- May 05, 2023, 11:39 PM: Tommie observed Tommie sees a cat and reacted by Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.\n", 858 | "- May 05, 2023, 11:25 PM: Tommie is hungry\n", 859 | "- May 05, 2023, 11:24 PM: Tommie feels tired from driving so far\n", 860 | "- May 05, 2023, 11:25 PM: Tommie tries to get some rest.\n", 861 | "Relevant context:\u001B[0m\n", 862 | "\n", 863 | "\u001B[1m> Finished chain.\u001B[0m\n", 864 | "\n", 865 | "\n", 866 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 867 | "Prompt after formatting:\n", 868 | "\u001B[32;1m\u001B[1;3mName: Tommie (age: 25)\n", 869 | "Innate traits: anxious, likes design, talkative\n", 870 | "1. Tommie remembers his dog Bruno from when he was a kid.\n", 871 | "2. Tommie sees the new home.\n", 872 | "3. The road is noisy at night.\n", 873 | "4. The new neighbors have a cat.\n", 874 | "5. Tommie tries to get some rest.\n", 875 | "6. Tommie feels tired from driving so far.\n", 876 | "7. Tommie is hungry.\n", 877 | "It is May 05, 2023, 11:43 PM.\n", 878 | "Tommie's status: looking for a job\n", 879 | "Summary of relevant context from Tommie's memory:\n", 880 | "- Tommie is a person who has experienced loss and is now starting over in a new home with his family.\n", 881 | "- Tommie's memories of his childhood dog, Bruno, are significant to him.\n", 882 | "- The noise on the road at night may be disruptive to Tommie's attempts to get some rest.\n", 883 | "- The presence of a cat in the new neighborhood may be interesting or concerning to Tommie depending on his attitude towards animals.\n", 884 | "Most recent observations: Tommie observed Tommie sees a cat and reacted by Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.; Tommie tries to get some rest.; Tommie is hungry; The road is noisy at night; The new neighbors have a cat; Tommie sees the new home; Tommie feels tired from driving so far; Tommie remembers his dog, Bruno, from when he was a kid\n", 885 | "Observation: Tommie sees his neighbor's cat\n", 886 | "\n", 887 | "Should Tommie react to the observation, and if so, what would be an appropriate reaction? Respond in one line. If the action is to engage in dialogue, write:\n", 888 | "SAY: \"what to say\"\n", 889 | "otherwise, write:\n", 890 | "REACT: Tommie's reaction (if anything).\n", 891 | "Either do nothing, react, or say something but not both.\n", 892 | "\n", 893 | "\u001B[0m\n", 894 | "\n", 895 | "\u001B[1m> Finished chain.\u001B[0m\n", 896 | "\n", 897 | "\n", 898 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 899 | "Prompt after formatting:\n", 900 | "\u001B[32;1m\u001B[1;3mOn the scale of 1 to 10, where 1 is not important at all (e.g., brushing teeth, making bed) and 10 is extremely important (e.g., a break up, college acceptance), rate the importance of the following piece of memory. You must respond with a single integer.\n", 901 | "Memory: I met my wife Jane when I was 23\n", 902 | "Rating: 9\n", 903 | "Memory: I visited Italy in 2020\n", 904 | "Rating: 5\n", 905 | "Memory: Tommie observed Tommie sees his neighbor's cat and reacted by Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.\n", 906 | "Rating: \u001B[0m\n" 907 | ] 908 | }, 909 | { 910 | "name": "stderr", 911 | "output_type": "stream", 912 | "text": [ 913 | "Importance score: 8\n" 914 | ] 915 | }, 916 | { 917 | "name": "stdout", 918 | "output_type": "stream", 919 | "text": [ 920 | "\n", 921 | "\u001B[1m> Finished chain.\u001B[0m\n", 922 | "(False, \"Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.\")\n" 923 | ] 924 | }, 925 | { 926 | "name": "stderr", 927 | "output_type": "stream", 928 | "text": [ 929 | "\n", 930 | "llama_print_timings: load time = 4570.63 ms\n", 931 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 932 | "llama_print_timings: prompt eval time = 12674.51 ms / 53 tokens ( 239.14 ms per token)\n", 933 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 934 | "llama_print_timings: total time = 12675.86 ms\n" 935 | ] 936 | } 937 | ], 938 | "source": [ 939 | "print(tommie.generate_reaction(\"Tommie sees his neighbor's cat\"))" 940 | ], 941 | "metadata": { 942 | "collapsed": false 943 | } 944 | }, 945 | { 946 | "cell_type": "code", 947 | "execution_count": 7, 948 | "outputs": [ 949 | { 950 | "name": "stderr", 951 | "output_type": "stream", 952 | "text": [ 953 | "\n", 954 | "llama_print_timings: load time = 4570.63 ms\n", 955 | "llama_print_timings: sample time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 956 | "llama_print_timings: prompt eval time = 5686.36 ms / 3 tokens ( 1895.45 ms per token)\n", 957 | "llama_print_timings: eval time = 0.00 ms / 1 runs ( 0.00 ms per run)\n", 958 | "llama_print_timings: total time = 5687.03 ms\n", 959 | "Chroma collection langchain contains fewer than 100 elements.\n", 960 | "Chroma collection langchain contains fewer than 99 elements.\n", 961 | "Chroma collection langchain contains fewer than 98 elements.\n", 962 | "Chroma collection langchain contains fewer than 97 elements.\n", 963 | "Chroma collection langchain contains fewer than 96 elements.\n", 964 | "Chroma collection langchain contains fewer than 95 elements.\n", 965 | "Chroma collection langchain contains fewer than 94 elements.\n", 966 | "Chroma collection langchain contains fewer than 93 elements.\n", 967 | "Chroma collection langchain contains fewer than 92 elements.\n", 968 | "Chroma collection langchain contains fewer than 91 elements.\n", 969 | "Chroma collection langchain contains fewer than 90 elements.\n", 970 | "Chroma collection langchain contains fewer than 89 elements.\n", 971 | "Chroma collection langchain contains fewer than 88 elements.\n", 972 | "Chroma collection langchain contains fewer than 87 elements.\n", 973 | "Chroma collection langchain contains fewer than 86 elements.\n", 974 | "Chroma collection langchain contains fewer than 85 elements.\n", 975 | "Chroma collection langchain contains fewer than 84 elements.\n", 976 | "Chroma collection langchain contains fewer than 83 elements.\n", 977 | "Chroma collection langchain contains fewer than 82 elements.\n", 978 | "Chroma collection langchain contains fewer than 81 elements.\n", 979 | "Chroma collection langchain contains fewer than 80 elements.\n", 980 | "Chroma collection langchain contains fewer than 79 elements.\n", 981 | "Chroma collection langchain contains fewer than 78 elements.\n", 982 | "Chroma collection langchain contains fewer than 77 elements.\n", 983 | "Chroma collection langchain contains fewer than 76 elements.\n", 984 | "Chroma collection langchain contains fewer than 75 elements.\n", 985 | "Chroma collection langchain contains fewer than 74 elements.\n", 986 | "Chroma collection langchain contains fewer than 73 elements.\n", 987 | "Chroma collection langchain contains fewer than 72 elements.\n", 988 | "Chroma collection langchain contains fewer than 71 elements.\n", 989 | "Chroma collection langchain contains fewer than 70 elements.\n", 990 | "Chroma collection langchain contains fewer than 69 elements.\n", 991 | "Chroma collection langchain contains fewer than 68 elements.\n", 992 | "Chroma collection langchain contains fewer than 67 elements.\n", 993 | "Chroma collection langchain contains fewer than 66 elements.\n", 994 | "Chroma collection langchain contains fewer than 65 elements.\n", 995 | "Chroma collection langchain contains fewer than 64 elements.\n", 996 | "Chroma collection langchain contains fewer than 63 elements.\n", 997 | "Chroma collection langchain contains fewer than 62 elements.\n", 998 | "Chroma collection langchain contains fewer than 61 elements.\n", 999 | "Chroma collection langchain contains fewer than 60 elements.\n", 1000 | "Chroma collection langchain contains fewer than 59 elements.\n", 1001 | "Chroma collection langchain contains fewer than 58 elements.\n", 1002 | "Chroma collection langchain contains fewer than 57 elements.\n", 1003 | "Chroma collection langchain contains fewer than 56 elements.\n", 1004 | "Chroma collection langchain contains fewer than 55 elements.\n", 1005 | "Chroma collection langchain contains fewer than 54 elements.\n", 1006 | "Chroma collection langchain contains fewer than 53 elements.\n", 1007 | "Chroma collection langchain contains fewer than 52 elements.\n", 1008 | "Chroma collection langchain contains fewer than 51 elements.\n", 1009 | "Chroma collection langchain contains fewer than 50 elements.\n", 1010 | "Chroma collection langchain contains fewer than 49 elements.\n", 1011 | "Chroma collection langchain contains fewer than 48 elements.\n", 1012 | "Chroma collection langchain contains fewer than 47 elements.\n", 1013 | "Chroma collection langchain contains fewer than 46 elements.\n", 1014 | "Chroma collection langchain contains fewer than 45 elements.\n", 1015 | "Chroma collection langchain contains fewer than 44 elements.\n", 1016 | "Chroma collection langchain contains fewer than 43 elements.\n", 1017 | "Chroma collection langchain contains fewer than 42 elements.\n", 1018 | "Chroma collection langchain contains fewer than 41 elements.\n", 1019 | "Chroma collection langchain contains fewer than 40 elements.\n", 1020 | "Chroma collection langchain contains fewer than 39 elements.\n", 1021 | "Chroma collection langchain contains fewer than 38 elements.\n", 1022 | "Chroma collection langchain contains fewer than 37 elements.\n", 1023 | "Chroma collection langchain contains fewer than 36 elements.\n", 1024 | "Chroma collection langchain contains fewer than 35 elements.\n", 1025 | "Chroma collection langchain contains fewer than 34 elements.\n", 1026 | "Chroma collection langchain contains fewer than 33 elements.\n", 1027 | "Chroma collection langchain contains fewer than 32 elements.\n", 1028 | "Chroma collection langchain contains fewer than 31 elements.\n", 1029 | "Chroma collection langchain contains fewer than 30 elements.\n", 1030 | "Chroma collection langchain contains fewer than 29 elements.\n", 1031 | "Chroma collection langchain contains fewer than 28 elements.\n", 1032 | "Chroma collection langchain contains fewer than 27 elements.\n", 1033 | "Chroma collection langchain contains fewer than 26 elements.\n", 1034 | "Chroma collection langchain contains fewer than 25 elements.\n", 1035 | "Chroma collection langchain contains fewer than 24 elements.\n", 1036 | "Chroma collection langchain contains fewer than 23 elements.\n", 1037 | "Chroma collection langchain contains fewer than 22 elements.\n", 1038 | "Chroma collection langchain contains fewer than 21 elements.\n", 1039 | "Chroma collection langchain contains fewer than 20 elements.\n", 1040 | "Chroma collection langchain contains fewer than 19 elements.\n", 1041 | "Chroma collection langchain contains fewer than 18 elements.\n", 1042 | "Chroma collection langchain contains fewer than 17 elements.\n", 1043 | "Chroma collection langchain contains fewer than 16 elements.\n", 1044 | "Chroma collection langchain contains fewer than 15 elements.\n", 1045 | "Chroma collection langchain contains fewer than 14 elements.\n", 1046 | "Chroma collection langchain contains fewer than 13 elements.\n", 1047 | "Chroma collection langchain contains fewer than 12 elements.\n", 1048 | "Chroma collection langchain contains fewer than 11 elements.\n", 1049 | "Chroma collection langchain contains fewer than 10 elements.\n" 1050 | ] 1051 | }, 1052 | { 1053 | "name": "stdout", 1054 | "output_type": "stream", 1055 | "text": [ 1056 | "\n", 1057 | "\n", 1058 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 1059 | "Prompt after formatting:\n", 1060 | "\u001B[32;1m\u001B[1;3mA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n", 1061 | "###USER: what is the most possible relationship between Tommie and Dad in the following observation? Do not embellish if you don't know. Do not return a list.\n", 1062 | "Observation: - May 05, 2023, 11:44 PM: Tommie observed Tommie sees his neighbor's cat and reacted by Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.\n", 1063 | "- May 05, 2023, 11:24 PM: Tommie remembers his dog, Bruno, from when he was a kid\n", 1064 | "- May 05, 2023, 11:25 PM: Tommie sees the new home\n", 1065 | "- May 05, 2023, 11:25 PM: The road is noisy at night\n", 1066 | "- May 05, 2023, 11:39 PM: Tommie observed Tommie sees a cat and reacted by Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.\n", 1067 | "- May 05, 2023, 11:25 PM: The new neighbors have a cat\n", 1068 | "- May 05, 2023, 11:25 PM: Tommie tries to get some rest.\n", 1069 | "- May 05, 2023, 11:24 PM: Tommie feels tired from driving so far\n", 1070 | "- May 05, 2023, 11:25 PM: Tommie is hungry\n", 1071 | "\n", 1072 | "###ASSISTANT: \u001B[0m\n", 1073 | "\n", 1074 | "\u001B[1m> Finished chain.\u001B[0m\n", 1075 | "\n", 1076 | "\n", 1077 | "\u001B[1m> Entering new LLMChain chain...\u001B[0m\n", 1078 | "Prompt after formatting:\n", 1079 | "\u001B[32;1m\u001B[1;3mName: Tommie (age: 25)\n", 1080 | "Innate traits: anxious, likes design, talkative\n", 1081 | "1. Tommie remembers his dog Bruno from when he was a kid.\n", 1082 | "2. Tommie sees the new home.\n", 1083 | "3. The road is noisy at night.\n", 1084 | "4. The new neighbors have a cat.\n", 1085 | "5. Tommie tries to get some rest.\n", 1086 | "6. Tommie feels tired from driving so far.\n", 1087 | "7. Tommie is hungry.\n", 1088 | "It is May 05, 2023, 11:46 PM.\n", 1089 | "Tommie's status: looking for a job\n", 1090 | "Summary of relevant context from Tommie's memory:\n", 1091 | "​\n", 1092 | "Most recent observations: Tommie observed Tommie sees his neighbor's cat and reacted by Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.; Tommie observed Tommie sees a cat and reacted by Tommie's reaction: Tommie might be curious about the cat and ask where it came from, or he might simply acknowledge its presence without saying anything.; Tommie tries to get some rest.; Tommie is hungry; The road is noisy at night; The new neighbors have a cat; Tommie sees the new home; Tommie feels tired from driving so far; Tommie remembers his dog, Bruno, from when he was a kid\n", 1093 | "Observation: Dad says Have you got a new job?\n", 1094 | "\n", 1095 | "What would Tommie say? To end the conversation, write: GOODBYE: \"what to say\". Otherwise to continue the conversation, write: SAY: \"what to say next\"\n", 1096 | "\n", 1097 | "\u001B[0m\n", 1098 | "\n", 1099 | "\u001B[1m> Finished chain.\u001B[0m\n" 1100 | ] 1101 | }, 1102 | { 1103 | "data": { 1104 | "text/plain": "(False, '1. What to say: \"No, I haven\\'t found one yet.\"')" 1105 | }, 1106 | "execution_count": 7, 1107 | "metadata": {}, 1108 | "output_type": "execute_result" 1109 | } 1110 | ], 1111 | "source": [ 1112 | "tommie.generate_dialogue(\"Dad\", \"Have you got a new job?\")" 1113 | ], 1114 | "metadata": { 1115 | "collapsed": false 1116 | } 1117 | } 1118 | ], 1119 | "metadata": { 1120 | "kernelspec": { 1121 | "display_name": "Python 3", 1122 | "language": "python", 1123 | "name": "python3" 1124 | }, 1125 | "language_info": { 1126 | "codemirror_mode": { 1127 | "name": "ipython", 1128 | "version": 2 1129 | }, 1130 | "file_extension": ".py", 1131 | "mimetype": "text/x-python", 1132 | "name": "python", 1133 | "nbconvert_exporter": "python", 1134 | "pygments_lexer": "ipython2", 1135 | "version": "2.7.6" 1136 | } 1137 | }, 1138 | "nbformat": 4, 1139 | "nbformat_minor": 0 1140 | } 1141 | --------------------------------------------------------------------------------