* validate python formatting on every build with Ruff
* fix lint warnings
This commit is contained in:
Anton Larin
2023-05-13 10:36:17 +02:00
committed by GitHub
parent 168648e789
commit 962becb9a5
35 changed files with 277 additions and 252 deletions

View File

@@ -1,8 +1,9 @@
import asyncio
import datetime
import http.client
import json
import os
import traceback
import asyncio
import dotenv
import requests
@@ -26,10 +27,9 @@ from langchain.prompts.chat import (
from pymongo import MongoClient
from werkzeug.utils import secure_filename
from core.settings import settings
from error import bad_request
from worker import ingest_worker
from core.settings import settings
import celeryconfig
# os.environ["LANGCHAIN_HANDLER"] = "langchain"
@@ -177,18 +177,12 @@ def api_answer():
q_prompt = PromptTemplate(input_variables=["context", "question"], template=template_quest,
template_format="jinja2")
if settings.LLM_NAME == "openai_chat":
# llm = ChatOpenAI(openai_api_key=api_key, model_name="gpt-4")
llm = ChatOpenAI(openai_api_key=api_key)
llm = ChatOpenAI(openai_api_key=api_key) # optional parameter: model_name="gpt-4"
messages_combine = [
SystemMessagePromptTemplate.from_template(chat_combine_template),
HumanMessagePromptTemplate.from_template("{question}")
]
p_chat_combine = ChatPromptTemplate.from_messages(messages_combine)
messages_reduce = [
SystemMessagePromptTemplate.from_template(chat_reduce_template),
HumanMessagePromptTemplate.from_template("{question}")
]
p_chat_reduce = ChatPromptTemplate.from_messages(messages_reduce)
elif settings.LLM_NAME == "openai":
llm = OpenAI(openai_api_key=api_key, temperature=0)
elif settings.LLM_NAME == "manifest":
@@ -226,7 +220,7 @@ def api_answer():
result['answer'] = result['answer'].replace("\\n", "\n")
try:
result['answer'] = result['answer'].split("SOURCES:")[0]
except:
except Exception:
pass
# mock result
@@ -295,7 +289,7 @@ def api_feedback():
"feedback": feedback
})
)
return {"status": 'ok'}
return {"status": http.client.responses.get(response.status_code, 'ok')}
@app.route('/api/combine', methods=['GET'])