Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed mulit-round chat memory problem & change the vectordb to #31

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions repo_agent/chat_with_repo/chat_with_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,46 @@ def parse_documents(self, document):
self.leaf_nodes = get_leaf_nodes(self.nodes)
self.nodes_by_id = {node.node_id: node for node in self.nodes}

def create_index(self):
# Create and persist index

def save_storedb(self):
# save the index to chromadb
db = chromadb.PersistentClient(path="./chroma_db")
chroma_collection = db.get_or_create_collection("quickstart")
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)

storage_context = StorageContext.from_defaults(vector_store=vector_store)
storage_context.docstore.add_documents(self.nodes)

self.automerging_index = VectorStoreIndex(
self.leaf_nodes, storage_context=self.storage_context, service_context=self.service_context
self.leaf_nodes, storage_context=storage_context, service_context=self.service_context
)

def load_storedb(self):
# load the index from chromadb
db2 = chromadb.PersistentClient(path="./chroma_db")
chroma_collection = db2.get_or_create_collection("quickstart")
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
self.automerging_index = VectorStoreIndex.from_vector_store(
vector_store,
service_context=self.service_context,
)
self.automerging_index.storage_context.persist(persist_dir="./merging_index")



class ChatbotResponder:
def __init__(self, automerging_engine):
self.automerging_engine = automerging_engine

def format_chat_prompt(self,message, chat_history, instruction):
prompt = f"System:{instruction}"
for turn in chat_history:
user_message, bot_message = turn
prompt = f"{prompt}\nUser: {user_message}\nAssistant: {bot_message}"
prompt = f"{prompt}\nUser: {message}\nAssistant:"
return prompt

def respond(self, message, chat_history, instruction):
prompt = message + instruction
prompt = self.format_chat_prompt(message, chat_history, instruction)
chat_history = chat_history + [[message, ""]]
auto_merging_response = self.automerging_engine.query(prompt)
bot_message = str(auto_merging_response)
Expand All @@ -73,7 +100,8 @@ def respond(self, message, chat_history, instruction):
indexer = DocumentIndexer("../../Markdown_Docs/", [".md", ".py"])
document = indexer.load_documents()
indexer.parse_documents(document)
indexer.create_index()
indexer.save_storedb()
indexer.load_storedb()
automerging_index = indexer.automerging_index
automerging_retriever = automerging_index.as_retriever(similarity_top_k=12)
retriever = AutoMergingRetriever(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

1 change: 0 additions & 1 deletion repo_agent/chat_with_repo/merging_index/docstore.json

This file was deleted.

1 change: 0 additions & 1 deletion repo_agent/chat_with_repo/merging_index/graph_store.json

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion repo_agent/chat_with_repo/merging_index/index_store.json

This file was deleted.

49 changes: 0 additions & 49 deletions repo_agent/chat_with_repo/requirements .txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,59 @@ aiofiles==23.2.1
aiohttp==3.9.1
aiosignal==1.3.1
altair==5.2.0
annotated-types==0.6.0
anyio==3.7.1
appnope==0.1.3
asgiref==3.7.2
asttokens==2.4.1
attrs==23.1.0
backoff==2.2.1
bcrypt==4.1.2
beautifulsoup4==4.12.2
cachetools==5.3.2
certifi==2023.11.17
cfgv==3.4.0
charset-normalizer==3.3.2
chroma-hnswlib==0.7.3
chromadb==0.4.21
click==8.1.7
colorama==0.4.6
coloredlogs==15.0.1
comm==0.1.4
contourpy==1.2.0
cycler==0.12.1
dataclasses-json==0.6.3
debugpy==1.8.0
decorator==5.1.1
deprecated==1.2.14
distlib==0.3.8
distro==1.8.0
exceptiongroup==1.2.0
executing==2.0.1
fastapi==0.108.0
ffmpy==0.3.1
filelock==3.13.1
flatbuffers==23.5.26
fonttools==4.47.0
frozenlist==1.4.1
fsspec==2023.12.2
gitdb==4.0.11
gitpython==3.1.40
google-auth==2.25.2
googleapis-common-protos==1.62.0
gradio==4.12.0
gradio-client==0.8.0
greenlet==3.0.3
grpcio==1.60.0
h11==0.14.0
httpcore==1.0.2
httptools==0.6.1
httpx==0.25.1
huggingface-hub==0.20.1
humanfriendly==10.0
identify==2.5.33
idna==3.4
importlib-metadata==6.8.0
importlib-resources==6.1.1
ipykernel==6.26.0
ipython==8.17.2
jedi==0.19.1
jinja2==3.1.2
joblib==1.3.2
jsonschema==4.20.0
jsonschema-specifications==2023.12.1
jupyter-client==8.6.0
jupyter-core==5.5.0
kiwisolver==1.4.5
kubernetes==28.1.0
llama-index==0.9.23
loguru==0.7.2
markdown-it-py==3.0.0
markupsafe==2.1.3
marshmallow==3.20.1
matplotlib==3.8.2
matplotlib-inline==0.1.6
mdurl==0.1.2
mmh3==4.0.1
monotonic==1.6
mpmath==1.3.0
multidict==6.0.4
mypy-extensions==1.0.0
nest-asyncio==1.5.8
networkx==3.0
nltk==3.8.1
nodeenv==1.8.0
Expand All @@ -100,21 +74,12 @@ opentelemetry-semantic-conventions==0.43b0
opentelemetry-util-http==0.43b0
orjson==3.9.10
overrides==7.4.0
packaging==23.2
pandas==2.1.4
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
pillow==9.3.0
platformdirs==4.0.0
posthog==3.1.0
pre-commit==3.6.0
prompt-toolkit==3.0.41
protobuf==4.25.1
psutil==5.9.5
ptyprocess==0.7.0
pulsar-client==3.3.0
pure-eval==0.2.2
pyasn1==0.5.1
pyasn1-modules==0.3.0
pydantic==2.5.3
Expand All @@ -124,16 +89,12 @@ pygments==2.17.2
pyparsing==3.1.1
pypika==0.48.9
pyreadline3==3.4.1
python-dateutil==2.8.2
python-dotenv==1.0.0
python-multipart==0.0.6
pytz==2023.3.post1
pywin32==306
pyyaml==6.0.1
pyzmq==25.1.1
referencing==0.32.0
regex==2023.10.3
requests==2.31.0
requests-oauthlib==1.3.1
rich==13.7.0
rpds-py==0.16.2
Expand All @@ -145,26 +106,18 @@ semantic-version==2.10.0
sentence-transformers==2.2.2
sentencepiece==0.1.99
shellingham==1.5.4
six==1.16.0
smmap==5.0.1
sniffio==1.3.0
soupsieve==2.5
sqlalchemy==2.0.24
stack-data==0.6.2
starlette==0.32.0.post1
sympy==1.12
tenacity==8.2.3
threadpoolctl==3.2.0
tiktoken==0.5.2
tokenizers==0.15.0
tomlkit==0.12.0
toolz==0.12.0
torch==2.1.2+cu118
torchaudio==2.1.2+cu118
torchvision==0.16.2+cu118
tornado==6.3.3
tqdm==4.66.1
traitlets==5.13.0
transformers==4.36.2
typer==0.9.0
typing-extensions==4.8.0
Expand All @@ -174,10 +127,8 @@ urllib3==1.26.18
uvicorn==0.25.0
virtualenv==20.25.0
watchfiles==0.21.0
wcwidth==0.2.12
websocket-client==1.7.0
websockets==11.0.3
wheel==0.41.3
win32-setctime==1.1.0
wrapt==1.16.0
yarl==1.9.4
Expand Down