forked from opea-project/GenAIComps
-
Notifications
You must be signed in to change notification settings - Fork 0
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
ArangoDB Integration #3
Draft
aMahanna
wants to merge
15
commits into
main
Choose a base branch
from
arangodb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
20e906a
arangodb prep | initial commit
aMahanna 388d802
ArangoDB: Feedback management (#11)
ajaykallepalli 6973d91
remove: `PROTOCOL` env
aMahanna 5e9742c
ArangoDB: PromptRegistry (#8)
SLasyaN 0e9ed3b
arangodb prep | initial commit
aMahanna 7bd5aaa
ArangoDB: Feedback management (#11)
ajaykallepalli b6ded9f
remove: `PROTOCOL` env
aMahanna 1746749
ArangoDB: PromptRegistry (#8)
SLasyaN bf41327
ArangoDB: Chathistory (#10)
ajaykallepalli 9d46b27
update ChatHistory README
aMahanna 029c1fd
new: tests
aMahanna 3a80607
update: docker compose workflows
aMahanna 28a5030
Merge branch 'arangodb' of https://github.com/arangoml/GenAIComps int…
ajaykallepalli fabd85c
fix: `arango`
aMahanna 0c21ff5
fix: python path
aMahanna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__pycache__ | ||
*.egg-info/ | ||
.DS_Store | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Instructions | ||
|
||
0. Create a virtual environment: | ||
|
||
```bash | ||
python -m venv .venv | ||
|
||
source .venv/bin/activate | ||
``` | ||
|
||
1. Install the required packages: | ||
|
||
```bash | ||
pip install python-arango | ||
pip install langchain_openai | ||
pip install git+https://github.com/arangoml/langchain.git@arangodb#subdirectory=libs/community | ||
``` | ||
|
||
2. Provision the ArangoDB with Vector Index image: | ||
|
||
```bash | ||
docker create --name arango-vector -p 8529:8529 -e ARANGO_ROOT_PASSWORD=test jbajic/arangodb-arm:vector-index-preview | ||
|
||
docker start arango-vector | ||
``` | ||
|
||
3. Set your `OPENAI_API_KEY` environment variable (contact Anthony for access) | ||
|
||
4. Run the test script to confirm LangChain is working: | ||
|
||
```bash | ||
python langchain_test.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
FROM python:3.11-slim | ||
|
||
ENV LANG=C.UTF-8 | ||
|
||
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \ | ||
build-essential \ | ||
libjemalloc-dev \ | ||
libgl1-mesa-glx | ||
|
||
RUN useradd -m -s /bin/bash user && \ | ||
mkdir -p /home/user && \ | ||
chown -R user /home/user/ | ||
|
||
USER user | ||
|
||
COPY comps /home/user/comps | ||
COPY requirements.txt /home/user/ | ||
|
||
RUN pip install --no-cache-dir --upgrade pip setuptools && \ | ||
pip install --no-cache-dir -r /home/user/comps/chathistory/arango/requirements.txt && \ | ||
pip install --no-cache-dir -r /home/user/requirements.txt | ||
|
||
ENV PYTHONPATH=$PYTHONPATH:/home/user | ||
|
||
WORKDIR /home/user/comps/chathistory/arango | ||
|
||
ENTRYPOINT ["python", "chat.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# 📝 Chat History Microservice with ArangoDB | ||
|
||
This README provides setup guides and all the necessary information about the Chat History microservice with ArangoDB database. | ||
|
||
--- | ||
|
||
## Setup Environment Variables | ||
|
||
See `config.py` for default values. | ||
|
||
```bash | ||
export ARANGO_HOST=${ARANGO_HOST} | ||
export ARANGO_PORT=${ARANGO_PORT} | ||
export ARANGO_PROTOCOL=${ARANGO_PROTOCOL} | ||
export ARANGO_USERNAME=${ARANGO_USERNAME} | ||
export ARANGO_PASSWORD=${ARANGO_PASSWORD} | ||
export DB_NAME=${DB_NAME} | ||
export COLLECTION_NAME=${COLLECTION_NAME} | ||
``` | ||
|
||
--- | ||
|
||
## 🚀Start Microservice with Docker | ||
|
||
### Build Docker Image | ||
|
||
```bash | ||
cd ../../../../ | ||
docker build -t opea/chathistory-arango-server:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/arango/Dockerfile . | ||
``` | ||
|
||
### Run Docker with CLI | ||
|
||
- Run ArangoDB image container | ||
|
||
```bash | ||
docker run -d -p 8529:8529 --name=arango arangodb/arangodb:latest | ||
``` | ||
|
||
- Run the Chat History microservice | ||
|
||
```bash | ||
docker run -p 6012:6012 \ | ||
-e http_proxy=$http_proxy \ | ||
-e https_proxy=$https_proxy \ | ||
-e no_proxy=$no_proxy \ | ||
-e ARANGO_HOST=${ARANGO_HOST} \ | ||
-e ARANGO_PORT=${ARANGO_PORT} \ | ||
-e ARANGO_PROTOCOL=${ARANGO_PROTOCOL} \ | ||
-e ARANGO_USERNAME=${ARANGO_USERNAME} \ | ||
-e ARANGO_PASSWORD=${ARANGO_PASSWORD} \ | ||
-e DB_NAME=${DB_NAME} \ | ||
-e COLLECTION_NAME=${COLLECTION_NAME} \ | ||
opea/chathistory-arango-server:latest | ||
``` | ||
|
||
--- | ||
|
||
## ✅ Invoke Microservice | ||
|
||
The Chat History microservice exposes the following API endpoints: | ||
|
||
- Create new chat conversation | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://${host_ip}:6012/v1/chathistory/create \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"data": { | ||
"messages": "test Messages", "user": "test" | ||
} | ||
}' | ||
``` | ||
|
||
- Get all the Conversations for a user | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://${host_ip}:6012/v1/chathistory/get \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"user": "test"}' | ||
``` | ||
|
||
- Get a specific conversation by id. | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://${host_ip}:6012/v1/chathistory/get \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"user": "test", "id":"48918"}' | ||
``` | ||
|
||
- Update the conversation by id. | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://${host_ip}:6012/v1/chathistory/create \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"data": { | ||
"messages": "test Messages Update", "user": "test" | ||
}, | ||
"id":"48918" | ||
}' | ||
``` | ||
|
||
- Delete a stored conversation. | ||
|
||
```bash | ||
curl -X 'POST' \ | ||
http://${host_ip}:6012/v1/chathistory/delete \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"user": "test", "id":"48918"}' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from arango import ArangoClient as PythonArangoClient | ||
from arango.database import StandardDatabase | ||
from config import ARANGO_HOST, ARANGO_PASSWORD, ARANGO_PORT, ARANGO_PROTOCOL, ARANGO_USERNAME, DB_NAME | ||
|
||
|
||
class ArangoClient: | ||
conn_url = f"{ARANGO_PROTOCOL}://{ARANGO_HOST}:{ARANGO_PORT}/" | ||
|
||
@staticmethod | ||
def get_db_client() -> StandardDatabase: | ||
try: | ||
# Create client | ||
client = PythonArangoClient(hosts=ArangoClient.conn_url) | ||
|
||
# First connect to _system database | ||
sys_db = client.db("_system", username=ARANGO_USERNAME, password=ARANGO_PASSWORD, verify=True) | ||
|
||
# Create target database if it doesn't exist | ||
if not sys_db.has_database(DB_NAME): | ||
sys_db.create_database(DB_NAME) | ||
|
||
# Now connect to the target database | ||
db = client.db(DB_NAME, username=ARANGO_USERNAME, password=ARANGO_PASSWORD, verify=True) | ||
|
||
return db | ||
|
||
except Exception as e: | ||
print(e) | ||
raise e |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to double check w/ the OPEA team if it's okay to add
-mongo-server
tofeedbackmanagement