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: fix rag-langchain app #47

Merged
merged 3 commits into from
Feb 19, 2024
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
2 changes: 1 addition & 1 deletion rag-langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ snapshot_download(repo_id="BAAI/bge-base-en-v1.5",
Follow the instructions below to build you container image and run it locally.

* `podman build -t ragapp rag-langchain -f rag-langchain/builds/Containerfile`
* `podman run --rm -it -p 8501:8501 -v Local/path/to/locallm/models/:/rag/models:Z -v Local/path/to/locallm/data:/rag/data:Z ragapp -- -H 10.88.0.1 -m http://10.88.0.1:8001/v1`
* `podman run --rm -it -p 8501:8501 -v Local/path/to/locallm/models/:/rag/models:Z -v Local/path/to/locallm/data:/rag/data:Z -e MODEL_SERVICE_ENDPOINT=http://10.88.0.1:8001/v1 ragapp -- -H 10.88.0.1 `

2 changes: 1 addition & 1 deletion rag-langchain/ai-studio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ application:
- arm64
- amd64
- name: chromadb-server
contextdir:: builds/chromadb
contextdir: builds/chromadb
containerfile: Containerfile
vectordb: true
arch:
Expand Down
17 changes: 10 additions & 7 deletions rag-langchain/rag_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
import argparse
import pathlib

model_service = os.getenv("MODEL_SERVICE_ENDPOINT",
"http://0.0.0.0:8001/v1")

parser = argparse.ArgumentParser()
parser.add_argument("-c", "--chunk_size", default=150)
parser.add_argument("-e", "--embedding_model", default="BAAI/bge-base-en-v1.5")
parser.add_argument("-H", "--vdb_host", default="0.0.0.0")
parser.add_argument("-p", "--vdb_port", default="8000")
parser.add_argument("-n", "--name", default="test_collection")
parser.add_argument("-m", "--model_url", default="http://0.0.0.0:8001/v1")
args = parser.parse_args()

vectorDB_client = HttpClient(host=args.vdb_host,
port=args.vdb_port,
settings=Settings(allow_reset=True,))

def clear_vdb():
global client
client.delete_collection(args.name)
Expand Down Expand Up @@ -56,10 +62,7 @@ def get_files():
embedding_func = embedding_functions.SentenceTransformerEmbeddingFunction(model_name=args.embedding_model)
e = SentenceTransformerEmbeddings(model_name=args.embedding_model)

client = HttpClient(host=args.vdb_host,
port=args.vdb_port,
settings=Settings(allow_reset=True,))
collection = client.get_or_create_collection(args.name,
collection = vectorDB_client.get_or_create_collection(args.name,
embedding_function=embedding_func)
if collection.count() < 1 and data != None:
print("populating db")
Expand Down Expand Up @@ -87,13 +90,13 @@ def get_files():
for msg in st.session_state.messages:
st.chat_message(msg["role"]).write(msg["content"])

db = Chroma(client=client,
db = Chroma(client=vectorDB_client,
collection_name=args.name,
embedding_function=e
)
retriever = db.as_retriever(threshold=0.75)

llm = ChatOpenAI(base_url=args.model_url,
llm = ChatOpenAI(base_url=model_service,
api_key="EMPTY",
streaming=True,
callbacks=[StreamlitCallbackHandler(st.container(),
Expand Down