MWilinski commited on
Commit
561db8a
1 Parent(s): 6f24bb3
api/__main__.py CHANGED
@@ -26,7 +26,7 @@ def get_answer(question: str, messgages_context: str):
26
  f"Received request with question: {question}" \
27
  f"and context: {messgages_context}"
28
  )
29
- response = qa_model.get_answer(
30
  question=question,
31
  messages_context=messgages_context
32
  )
 
26
  f"Received request with question: {question}" \
27
  f"and context: {messgages_context}"
28
  )
29
+ response = qa_model.get_response(
30
  question=question,
31
  messages_context=messgages_context
32
  )
api/question_answering/qa_model.py CHANGED
@@ -17,13 +17,15 @@ from langchain.vectorstores import FAISS
17
  from api.logger import logger
18
  from api.question_answering.response import Response
19
 
20
- """
21
  class LocalBinaryModel(LLM):
22
  model_id: str = None
23
- llm: Llama = None
24
 
25
  def __init__(self, model_id: str = None):
26
  super().__init__()
 
 
27
  model_path = f'api/question_answering/{model_id}'
28
  if not os.path.exists(model_path):
29
  raise ValueError(f'{model_path} does not exist')
@@ -48,7 +50,7 @@ class LocalBinaryModel(LLM):
48
  @property
49
  def _llm_type(self) -> str:
50
  return self.model_id
51
- """
52
 
53
  class TransformersPipelineModel(LLM):
54
  model_id: str = None
@@ -169,9 +171,9 @@ class QAModel():
169
 
170
  if 'local_models/' in llm_model_id:
171
  logger.info('using local binary model')
172
- #self.llm_model = LocalBinaryModel(
173
- # model_id=llm_model_id
174
- #)
175
  elif 'api_models/' in llm_model_id:
176
  logger.info('using api served model')
177
  self.llm_model = APIServedModel(
@@ -216,7 +218,7 @@ class QAModel():
216
  self.knowledge_index = FAISS.load_local(f"./indexes/run/", embedding_model)
217
 
218
 
219
- def get_answer(self, question: str, messages_context: str = '') -> Response:
220
  """
221
  Generate an answer to the specified question.
222
 
 
17
  from api.logger import logger
18
  from api.question_answering.response import Response
19
 
20
+
21
  class LocalBinaryModel(LLM):
22
  model_id: str = None
23
+ llm: None = None
24
 
25
  def __init__(self, model_id: str = None):
26
  super().__init__()
27
+ from llama_cpp import Llama
28
+
29
  model_path = f'api/question_answering/{model_id}'
30
  if not os.path.exists(model_path):
31
  raise ValueError(f'{model_path} does not exist')
 
50
  @property
51
  def _llm_type(self) -> str:
52
  return self.model_id
53
+
54
 
55
  class TransformersPipelineModel(LLM):
56
  model_id: str = None
 
171
 
172
  if 'local_models/' in llm_model_id:
173
  logger.info('using local binary model')
174
+ self.llm_model = LocalBinaryModel(
175
+ model_id=llm_model_id
176
+ )
177
  elif 'api_models/' in llm_model_id:
178
  logger.info('using api served model')
179
  self.llm_model = APIServedModel(
 
218
  self.knowledge_index = FAISS.load_local(f"./indexes/run/", embedding_model)
219
 
220
 
221
+ def get_response(self, question: str, messages_context: str = '') -> Response:
222
  """
223
  Generate an answer to the specified question.
224
 
app.py CHANGED
@@ -23,11 +23,11 @@ with gr.Blocks() as demo:
23
  def respond(message, chat_history):
24
  context = "".join(f"User: {msg} \nBot:{bot_msg}\n" for msg, bot_msg in chat_history)
25
  logger.info(f"Context: {context}")
26
- answer = model.get_answer(message, context)
27
- bot_message = answer.get_response() + answer.get_sources_as_text() + "\n"
28
  chat_history.append((message, bot_message))
29
  return "", chat_history
30
 
31
  msg.submit(respond, [msg, chatbot], [msg, chatbot])
32
 
33
- demo.launch(share=False, debug=True)
 
23
  def respond(message, chat_history):
24
  context = "".join(f"User: {msg} \nBot:{bot_msg}\n" for msg, bot_msg in chat_history)
25
  logger.info(f"Context: {context}")
26
+ response = model.get_response(message, context)
27
+ bot_message = response.get_answer() + response.get_sources_as_text() + "\n"
28
  chat_history.append((message, bot_message))
29
  return "", chat_history
30
 
31
  msg.submit(respond, [msg, chatbot], [msg, chatbot])
32
 
33
+ demo.launch(share=True, debug=True)
config/.DS_Store DELETED
Binary file (6.15 kB)
 
requirements.txt CHANGED
@@ -2,11 +2,13 @@ transformers
2
  accelerate
3
  einops
4
  huggingface_hub
 
5
  beautifulsoup4==4.12.0
6
  discord.py==2.2.2
7
  evaluate==0.4.0
8
  fastapi==0.98.0
9
  langchain==0.0.154
 
10
  nltk==3.8.1
11
  nbconvert==7.6.0
12
  nbformat==5.9.0
 
2
  accelerate
3
  einops
4
  huggingface_hub
5
+ gradio
6
  beautifulsoup4==4.12.0
7
  discord.py==2.2.2
8
  evaluate==0.4.0
9
  fastapi==0.98.0
10
  langchain==0.0.154
11
+ llama_cpp_python==0.1.39
12
  nltk==3.8.1
13
  nbconvert==7.6.0
14
  nbformat==5.9.0