File size: 1,180 Bytes
409707a
 
f2b70d2
409707a
49fa2ad
409707a
 
 
 
 
 
07c36bf
 
90a3e87
07c36bf
409707a
 
 
 
07c36bf
4f9d026
 
409707a
 
 
 
a4bb528
409707a
 
4f9d026
409707a
 
 
218a8bf
409707a
 
 
1b63121
409707a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st
from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex
#from langchain import OpenAI
import os
#import shutil

def ingest(docs_dir):
    documents = SimpleDirectoryReader(docs_dir).load_data()
    index = GPTVectorStoreIndex.from_documents(documents)
    return index

def get_answer(index, message):
    response = query(index, message)
    return [('Chatbot FCI', ''.join(response.response))]
    
def query(index, query_text):
    query_engine = index.as_query_engine()
    response = query_engine.query(query_text)
    return response
   
os.environ['OPENAI_API_KEY'] = "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"

if os.environ['OPENAI_API_KEY']:
    # Initialize chatbot history
    chatbot = []

    index = ingest('temp_docs')

    # Display message input component
    message = st.text_input('Ingrese su consulta')

    # If message is entered, ingest documents and get chatbot response
    if message:
        chatbot.append(('Tú', message))
        chatbot += get_answer(index, message)

    # Display chat history
    st.text_area('Respuesta:', value='\n'.join(
        [f'{x[0]}: {x[1]}' for x in chatbot]), height=250)