ben-wang commited on
Commit
f9fcbde
·
verified ·
1 Parent(s): ad7a7ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -5,8 +5,20 @@ handling the Gradio/Streamlit UI and orchestrating the RAG pipeline
5
  to answer queries based on the game's mechanics and manual.
6
  """
7
  import gradio as gr
8
- from helpers import create_prompt, find_similar_documents, load_vector_store
9
- from model import CHAT_MODEL_ID, generate_answer, load_chat_model
 
 
 
 
 
 
 
 
 
 
 
 
10
  import pytest
11
  import sys
12
 
@@ -20,7 +32,11 @@ else:
20
  # Initialiations and globals
21
  print(f"Loading {CHAT_MODEL_ID} model...")
22
  chat_model, tokenizer = load_chat_model()
23
- print("Model loaded!")
 
 
 
 
24
 
25
  MANUAL_PATH = "emerald_manual.txt"
26
  print(f"Loading vector store from {MANUAL_PATH}...")
@@ -29,7 +45,8 @@ print("Vector store loaded!")
29
 
30
  def respond(message, history):
31
  print("Enter app.respond...")
32
- context = find_similar_documents(vector_store, message)
 
33
  prompt = create_prompt(message, history, context)
34
  response = generate_answer(chat_model, tokenizer, prompt)
35
  if not response:
 
5
  to answer queries based on the game's mechanics and manual.
6
  """
7
  import gradio as gr
8
+ from helpers import (
9
+ create_prompt,
10
+ find_similar_documents,
11
+ load_vector_store,
12
+ CHROMA_PATH,
13
+ COLLECTION_NAME,
14
+ )
15
+ from model import (
16
+ CHAT_MODEL_ID,
17
+ EMBEDDING_MODEL_ID,
18
+ generate_answer,
19
+ load_chat_model,
20
+ load_embedding_model,
21
+ )
22
  import pytest
23
  import sys
24
 
 
32
  # Initialiations and globals
33
  print(f"Loading {CHAT_MODEL_ID} model...")
34
  chat_model, tokenizer = load_chat_model()
35
+ print("Chat model loaded!")
36
+
37
+ print(f"Loading {EMBEDDING_MODEL_ID} model...")
38
+ embedding_model = load_embedding_model()
39
+ print("Embedding model loaded!"
40
 
41
  MANUAL_PATH = "emerald_manual.txt"
42
  print(f"Loading vector store from {MANUAL_PATH}...")
 
45
 
46
  def respond(message, history):
47
  print("Enter app.respond...")
48
+ context = find_similar_documents(
49
+ CHROMA_PATH, COLLECTION_NAME, embedding_model, message, k=5)
50
  prompt = create_prompt(message, history, context)
51
  response = generate_answer(chat_model, tokenizer, prompt)
52
  if not response: