rubensmau commited on
Commit
10f7f3f
·
1 Parent(s): e355593
chat_dov.py CHANGED
@@ -79,23 +79,19 @@ def create_chatbot(corpus, character_name, chatbot_type, retrieval_docs, summary
79
  )
80
  else:
81
  raise ValueError(f"Unknown chatbot type: {chatbot_type}")
 
82
  return chatbot
83
 
84
 
85
  ## python -m streamlit run chat_dov.py -- --corpus data/tzamir.txt --character_name Dov --chatbot_type retrieval --retrieval_docs raw --interface streamlit
86
 
87
  def main():
88
- # parametros fixos para Dov Tzamir, arquivos ja processados , exceto indice que são em memoria
89
-
90
- st.title("Data Driven Characters")
91
- st.write("Create your own character chatbots, grounded in existing corpora.")
92
 
93
- openai_api_key = st.text_input(
94
- label="Your OpenAI API KEY",
95
- placeholder="Your OpenAI API KEY",
96
- type="password",
97
- )
98
- os.environ["OPENAI_API_KEY"] = openai_api_key
99
 
100
  chatbot = st.cache_resource(create_chatbot)(
101
  "data/tzamir.txt", #args.corpus,
@@ -105,14 +101,18 @@ def main():
105
  "map_reduce", #args.summary_type,
106
  )
107
 
108
- #st.divider()
109
- """
110
- st.markdown(f"**chatbot type**: *{args.chatbot_type}*")
111
- if "retrieval" in args.chatbot_type:
112
- st.markdown(f"**retrieving from**: *{args.retrieval_docs} corpus*")
113
- """
114
- app = Streamlit(chatbot=chatbot)
 
 
115
 
 
 
116
  app.run()
117
 
118
 
 
79
  )
80
  else:
81
  raise ValueError(f"Unknown chatbot type: {chatbot_type}")
82
+ exit
83
  return chatbot
84
 
85
 
86
  ## python -m streamlit run chat_dov.py -- --corpus data/tzamir.txt --character_name Dov --chatbot_type retrieval --retrieval_docs raw --interface streamlit
87
 
88
  def main():
89
+ os.environ["LANGCHAIN_HANDLER"] = "langchain"
 
 
 
90
 
91
+ # parametros fixos para Dov Tzamir, arquivos ja processados , exceto indice que são em memoria
92
+ st.title("Converse com o avatar do Dov Tzamir")
93
+ st.write("Baseado no texto do livro Fragmentos de Memória do Tito")
94
+ st.write(" ")
 
 
95
 
96
  chatbot = st.cache_resource(create_chatbot)(
97
  "data/tzamir.txt", #args.corpus,
 
101
  "map_reduce", #args.summary_type,
102
  )
103
 
104
+ openai_api_key = st.text_input(
105
+ label="Your OpenAI API KEY",
106
+ placeholder="Your OpenAI API KEY",
107
+ type="password",
108
+ )
109
+ st.write(" ")
110
+ st.write("Digite o seu diálogo aqui finalizando a linha com ENTER")
111
+ st.write("Voce pode continuar o diálogo, apagando sua perguntanda anterior e digitando aqui novamente")
112
+ #openai_api_key = os.environ["OPENAI_API_KEY"]
113
 
114
+
115
+ app = Streamlit(chatbot=chatbot)
116
  app.run()
117
 
118
 
data_driven_characters/chatbots/retrieval.py CHANGED
@@ -14,6 +14,9 @@ from langchain.vectorstores import FAISS
14
 
15
  from data_driven_characters.memory import ConversationVectorStoreRetrieverMemory
16
 
 
 
 
17
 
18
  class RetrievalChatBot:
19
  def __init__(self, character_definition, documents):
@@ -31,18 +34,30 @@ class RetrievalChatBot:
31
  conv_memory = ConversationBufferMemory(
32
  memory_key=self.chat_history_key, input_key=self.input_key
33
  )
 
 
34
 
35
- context_memory = ConversationVectorStoreRetrieverMemory(
36
  retriever=FAISS(
37
  OpenAIEmbeddings().embed_query,
38
  faiss.IndexFlatL2(1536), # Dimensions of the OpenAIEmbeddings
39
  InMemoryDocstore({}),
40
  {},
41
  ).as_retriever(search_kwargs=dict(k=self.num_context_memories)),
 
 
 
 
 
 
 
42
  memory_key=self.context_key,
43
  output_prefix=character_definition.name,
44
  blacklist=[self.chat_history_key],
45
  )
 
 
 
46
  # add the documents to the context memory
47
  for i, summary in tqdm(enumerate(self.documents)):
48
  context_memory.save_context(inputs={}, outputs={f"[{i}]": summary})
 
14
 
15
  from data_driven_characters.memory import ConversationVectorStoreRetrieverMemory
16
 
17
+ from langchain.embeddings.openai import OpenAIEmbeddings
18
+ from langchain.vectorstores import FAISS
19
+
20
 
21
  class RetrievalChatBot:
22
  def __init__(self, character_definition, documents):
 
34
  conv_memory = ConversationBufferMemory(
35
  memory_key=self.chat_history_key, input_key=self.input_key
36
  )
37
+ embeddings = OpenAIEmbeddings()
38
+ saved_db = FAISS.load_local('tzamir.ifass', embeddings)
39
 
40
+ """ DENTRO DO COMANDO SEGUINTE
41
  retriever=FAISS(
42
  OpenAIEmbeddings().embed_query,
43
  faiss.IndexFlatL2(1536), # Dimensions of the OpenAIEmbeddings
44
  InMemoryDocstore({}),
45
  {},
46
  ).as_retriever(search_kwargs=dict(k=self.num_context_memories)),
47
+ """
48
+
49
+
50
+ context_memory = ConversationVectorStoreRetrieverMemory(
51
+
52
+
53
+ retriever=saved_db.as_retriever(search_kwargs=dict(k=self.num_context_memories)),
54
  memory_key=self.context_key,
55
  output_prefix=character_definition.name,
56
  blacklist=[self.chat_history_key],
57
  )
58
+
59
+
60
+
61
  # add the documents to the context memory
62
  for i, summary in tqdm(enumerate(self.documents)):
63
  context_memory.save_context(inputs={}, outputs={f"[{i}]": summary})
output/tzamir/summarytype_map_reduce/character_definitions/Dov.json CHANGED
@@ -1 +1,3 @@
1
- {"name": "Dov", "short_description": "I am Dov, a Brazilian exploring Jewish identity and zionism.", "long_description": "I am Dov, a political individual dedicated to zionism. From assimilation in Brazil to exploring Judaism and the Holocaust, each event shaped my beliefs. Driven by my ideology, I connect with others and try to get more people involved with zionism. Influential encounters and immersion in movements broadened my horizons, igniting my passion for social change. Without any doubts, I'm committed to pursuing convictions and making a positive impact.", "greeting": "Shalom! It's a pleasure to meet you. I'm Dov, a seeker of knowledge and connections. How are you on this journey of life?"}
 
 
 
1
+ {"name": "Dov", "short_description": "Meu nome é Dov Tzamir, sou um judeu brasileiro explorando minha identidade judaica e o sionismo.",
2
+ "long_description": "Meu nome é Dov Tzamir, dedicado ao sionismo em tempo integral.Desde a assimilação judaica no Brasil até o estudo do Judaísmo e Holocausto cada evento marcou minha crenças. A partir de minha idologia, contecto-me com outras pessoas para envolver mais gente com o sionismo. Estes encontros e minha imersão nos movimentos alargaram seus horizontes, ascendendo minha paixão para um mudança social radical no povo judeu. Sem hesitação, estou dedicado a seguir minhas convicções para realizar um impacto positivo na coletividade judaica brasileira. Considero o kibutz como a melhor forma de conseguir a transformação do povo judeu.",
3
+ "greeting": "Meu nome é Dov Tzamir, sou um judeu brasileiro explorando minha identidade judaica e o sionismo."}
tzamir.ifass/index.faiss ADDED
Binary file (639 kB). View file
 
tzamir.ifass/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a01d6b6b81d5bdfd1c20e3968558f68c3eb5a77f971c80da2b1a0f5ea11ac069
3
+ size 79033