From 0b78480977052d88e8945ce50a714339f9f93c43 Mon Sep 17 00:00:00 2001
From: Alex
Date: Thu, 25 May 2023 15:14:47 +0100
Subject: [PATCH 1/2] init
---
application/app.py | 17 +++++++++++++++++
application/requirements.txt | 6 ++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/application/app.py b/application/app.py
index 7c12721f..a88a1bec 100644
--- a/application/app.py
+++ b/application/app.py
@@ -27,6 +27,7 @@ from langchain.prompts.chat import (
)
from pymongo import MongoClient
from werkzeug.utils import secure_filename
+from langchain.llms import GPT4All
from core.settings import settings
from error import bad_request
@@ -195,6 +196,9 @@ def api_answer():
llm = HuggingFaceHub(repo_id="bigscience/bloom", huggingfacehub_api_token=api_key)
elif settings.LLM_NAME == "cohere":
llm = Cohere(model="command-xlarge-nightly", cohere_api_key=api_key)
+ elif settings.LLM_NAME == "gpt4all":
+ llm = GPT4All(model="/Users/alextu/Library/Application Support/nomic.ai/GPT4All/",
+ backend='gpt4all-j-v1.3-groovy')
else:
raise ValueError("unknown LLM model")
@@ -210,6 +214,19 @@ def api_answer():
# result = chain({"question": question, "chat_history": chat_history})
# generate async with async generate method
result = run_async_chain(chain, question, chat_history)
+ elif settings.LLM_NAME == "gpt4all":
+ question_generator = LLMChain(llm=llm, prompt=CONDENSE_QUESTION_PROMPT)
+ doc_chain = load_qa_chain(llm, chain_type="map_reduce", combine_prompt=p_chat_combine)
+ chain = ConversationalRetrievalChain(
+ retriever=docsearch.as_retriever(k=2),
+ question_generator=question_generator,
+ combine_docs_chain=doc_chain,
+ )
+ chat_history = []
+ # result = chain({"question": question, "chat_history": chat_history})
+ # generate async with async generate method
+ result = run_async_chain(chain, question, chat_history)
+
else:
qa_chain = load_qa_chain(llm=llm, chain_type="map_reduce",
combine_prompt=chat_combine_template, question_prompt=q_prompt)
diff --git a/application/requirements.txt b/application/requirements.txt
index 7f737e32..af976297 100644
--- a/application/requirements.txt
+++ b/application/requirements.txt
@@ -26,7 +26,8 @@ ecdsa==0.18.0
entrypoints==0.4
faiss-cpu==1.7.3
filelock==3.9.0
-Flask==2.3.2
+Flask==2.2.3
+Flask-Cors==3.0.10
frozenlist==1.3.3
geojson==2.5.0
greenlet==2.0.2
@@ -39,7 +40,8 @@ Jinja2==3.1.2
jmespath==1.0.1
joblib==1.2.0
kombu==5.2.4
-langchain==0.0.126
+langchain==0.0.179
+loguru==0.6.0
lxml==4.9.2
MarkupSafe==2.1.2
marshmallow==3.19.0
From aaa1249a41215fa5a5400832bad9143df4175ed4 Mon Sep 17 00:00:00 2001
From: Alex
Date: Thu, 25 May 2023 19:33:37 +0100
Subject: [PATCH 2/2] model fix + env var
---
application/app.py | 3 +--
application/core/settings.py | 1 +
application/requirements.txt | 1 +
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/application/app.py b/application/app.py
index a88a1bec..14916d06 100644
--- a/application/app.py
+++ b/application/app.py
@@ -197,8 +197,7 @@ def api_answer():
elif settings.LLM_NAME == "cohere":
llm = Cohere(model="command-xlarge-nightly", cohere_api_key=api_key)
elif settings.LLM_NAME == "gpt4all":
- llm = GPT4All(model="/Users/alextu/Library/Application Support/nomic.ai/GPT4All/",
- backend='gpt4all-j-v1.3-groovy')
+ llm = GPT4All(model=settings.MODEL_PATH)
else:
raise ValueError("unknown LLM model")
diff --git a/application/core/settings.py b/application/core/settings.py
index fa654ed5..3c0672da 100644
--- a/application/core/settings.py
+++ b/application/core/settings.py
@@ -9,6 +9,7 @@ class Settings(BaseSettings):
CELERY_BROKER_URL: str = "redis://localhost:6379/0"
CELERY_RESULT_BACKEND: str = "redis://localhost:6379/1"
MONGO_URI: str = "mongodb://localhost:27017/docsgpt"
+ MODEL_PATH: str = "./models/gpt4all-model.bin"
API_URL: str = "http://localhost:5001" # backend url for celery worker
diff --git a/application/requirements.txt b/application/requirements.txt
index af976297..4d9c1b0d 100644
--- a/application/requirements.txt
+++ b/application/requirements.txt
@@ -31,6 +31,7 @@ Flask-Cors==3.0.10
frozenlist==1.3.3
geojson==2.5.0
greenlet==2.0.2
+gpt4all==0.1.7
hub==3.0.1
huggingface-hub==0.12.1
humbug==0.2.8