From 94cc18bd71777217ed5f74fb2881cdfa4cf10ffd Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 15 Jun 2023 11:35:21 +0100 Subject: [PATCH] fix for sending sources + azure embeddings issue --- .env-template | 2 +- application/app.py | 3 --- application/core/settings.py | 6 +++--- application/requirements.txt | 4 ++-- docker-compose.yaml | 21 ++++++-------------- frontend/src/conversation/conversationApi.ts | 8 ++++++++ 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.env-template b/.env-template index 375e04df..09c738fb 100644 --- a/.env-template +++ b/.env-template @@ -1,7 +1,7 @@ OPENAI_API_KEY= EMBEDDINGS_KEY= -# Azure +#For Azure OPENAI_API_BASE= OPENAI_API_VERSION= AZURE_DEPLOYMENT_NAME= diff --git a/application/app.py b/application/app.py index 3acf4555..d66d420d 100644 --- a/application/app.py +++ b/application/app.py @@ -266,9 +266,6 @@ def api_answer(): messages_combine.append(HumanMessagePromptTemplate.from_template(i["prompt"])) messages_combine.append(AIMessagePromptTemplate.from_template(i["response"])) messages_combine.append(HumanMessagePromptTemplate.from_template("{question}")) - import sys - - print(messages_combine, file=sys.stderr) p_chat_combine = ChatPromptTemplate.from_messages(messages_combine) elif settings.LLM_NAME == "openai": llm = OpenAI(openai_api_key=api_key, temperature=0) diff --git a/application/core/settings.py b/application/core/settings.py index 4294ce9f..ed621bb8 100644 --- a/application/core/settings.py +++ b/application/core/settings.py @@ -16,9 +16,9 @@ class Settings(BaseSettings): API_KEY: str = None # LLM api key EMBEDDINGS_KEY: str = None # api key for embeddings (if using openai, just copy API_KEY - OPENAI_API_BASE: str = "" # azure openai api base url - OPENAI_API_VERSION: str = "" # azure openai api version - AZURE_DEPLOYMENT_NAME: str = "" # azure deployment name + OPENAI_API_BASE: str = None # azure openai api base url + OPENAI_API_VERSION: str = None # azure openai api version + AZURE_DEPLOYMENT_NAME: str = None # azure deployment name path = Path(__file__).parent.parent.absolute() diff --git a/application/requirements.txt b/application/requirements.txt index 4d9c1b0d..f6ff97b5 100644 --- a/application/requirements.txt +++ b/application/requirements.txt @@ -41,7 +41,7 @@ Jinja2==3.1.2 jmespath==1.0.1 joblib==1.2.0 kombu==5.2.4 -langchain==0.0.179 +langchain==0.0.200 loguru==0.6.0 lxml==4.9.2 MarkupSafe==2.1.2 @@ -55,7 +55,7 @@ networkx==3.0 nltk==3.8.1 numcodecs==0.11.0 numpy==1.24.2 -openai==0.27.0 +openai==0.27.8 packaging==23.0 pathos==0.3.0 Pillow==9.4.0 diff --git a/docker-compose.yaml b/docker-compose.yaml index 071184a7..f36fd101 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,15 +1,6 @@ version: "3.9" services: - frontend: - build: ./frontend - environment: - - VITE_API_HOST=http://localhost:5001 - - VITE_API_STREAMING=$VITE_API_STREAMING - ports: - - "5173:5173" - depends_on: - - backend backend: build: ./application @@ -19,9 +10,9 @@ services: - CELERY_BROKER_URL=redis://redis:6379/0 - CELERY_RESULT_BACKEND=redis://redis:6379/1 - MONGO_URI=mongodb://mongo:27017/docsgpt - - OPENAI_API_BASE=$OPENAI_API_BASE - - OPENAI_API_VERSION=$OPENAI_API_VERSION - - AZURE_DEPLOYMENT_NAME=$AZURE_DEPLOYMENT_NAME + #- OPENAI_API_BASE=$OPENAI_API_BASE + #- OPENAI_API_VERSION=$OPENAI_API_VERSION + #- AZURE_DEPLOYMENT_NAME=$AZURE_DEPLOYMENT_NAME ports: - "5001:5001" volumes: @@ -42,9 +33,9 @@ services: - CELERY_RESULT_BACKEND=redis://redis:6379/1 - MONGO_URI=mongodb://mongo:27017/docsgpt - API_URL=http://backend:5001 - - OPENAI_API_BASE=$OPENAI_API_BASE - - OPENAI_API_VERSION=$OPENAI_API_VERSION - - AZURE_DEPLOYMENT_NAME=$AZURE_DEPLOYMENT_NAME + #- OPENAI_API_BASE=$OPENAI_API_BASE + #- OPENAI_API_VERSION=$OPENAI_API_VERSION + #- AZURE_DEPLOYMENT_NAME=$AZURE_DEPLOYMENT_NAME depends_on: - redis - mongo diff --git a/frontend/src/conversation/conversationApi.ts b/frontend/src/conversation/conversationApi.ts index c1e9c822..4bcbe05a 100644 --- a/frontend/src/conversation/conversationApi.ts +++ b/frontend/src/conversation/conversationApi.ts @@ -28,6 +28,10 @@ export function fetchAnswerApi( selectedDocs.model + '/'; } + //in history array remove all keys except prompt and response + history = history.map((item) => { + return { prompt: item.prompt, response: item.response }; + }); return fetch(apiHost + '/api/answer', { method: 'POST', @@ -82,6 +86,10 @@ export function fetchAnswerSteaming( '/'; } + history = history.map((item) => { + return { prompt: item.prompt, response: item.response }; + }); + return new Promise((resolve, reject) => { const url = new URL(apiHost + '/stream'); url.searchParams.append('question', question);