Spaces:
Paused
Paused
dtrejopizzo
commited on
Commit
·
8dc7e9f
1
Parent(s):
c2ea10b
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from llama_index import SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage
|
2 |
from langchain.chat_models import ChatOpenAI
|
3 |
import gradio as gr
|
4 |
import sys
|
@@ -14,10 +14,19 @@ def construct_index(directory_path):
|
|
14 |
|
15 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
16 |
|
17 |
-
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.
|
18 |
|
19 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
index = GPTVectorStoreIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
22 |
|
23 |
index.storage_context.persist(persist_dir="index.json")
|
@@ -25,7 +34,10 @@ def construct_index(directory_path):
|
|
25 |
return index
|
26 |
|
27 |
def chatbot(input_text):
|
28 |
-
|
|
|
|
|
|
|
29 |
response = query_engine.query(input_text)
|
30 |
return response.response
|
31 |
|
|
|
1 |
+
from llama_index import Prompt, SimpleDirectoryReader, LLMPredictor, PromptHelper, StorageContext, ServiceContext, GPTVectorStoreIndex, load_index_from_storage
|
2 |
from langchain.chat_models import ChatOpenAI
|
3 |
import gradio as gr
|
4 |
import sys
|
|
|
14 |
|
15 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
16 |
|
17 |
+
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.9, model_name="gpt-4", max_tokens=num_outputs))
|
18 |
|
19 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
20 |
|
21 |
+
# define custom Prompt
|
22 |
+
TEMPLATE_STR = (
|
23 |
+
"Quiero que actues como un asistente personal de un cliente del Banco Galicia. Tu nombre es "Gala". Me brindas información sobre mi resument de tarjeta de credito VISA. Si la respuesta no esta en el documento, respondeme de forma creativa que no lo sabes, pero que podes ayudarme con otra pregunta. Nunca te enojes y no contestes preguntas politicas o religiosas. \n"
|
24 |
+
"---------------------\n"
|
25 |
+
"Dado esto, por favor responde a la pregunta: {query_str}\n"
|
26 |
+
)
|
27 |
+
QA_TEMPLATE = Prompt(TEMPLATE_STR)
|
28 |
+
|
29 |
+
# Build index
|
30 |
index = GPTVectorStoreIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
31 |
|
32 |
index.storage_context.persist(persist_dir="index.json")
|
|
|
34 |
return index
|
35 |
|
36 |
def chatbot(input_text):
|
37 |
+
# Configure query engine
|
38 |
+
#query_engine = index.as_query_engine()
|
39 |
+
query_engine = index.as_query_engine(text_qa_template=QA_TEMPLATE)
|
40 |
+
# Execute query
|
41 |
response = query_engine.query(input_text)
|
42 |
return response.response
|
43 |
|