jouch commited on
Commit
396aabc
1 Parent(s): 12874c1

Upload 4 files

Browse files
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from langchain.embeddings import AzureOpenAIEmbeddings
4
+ from langchain.vectorstores import FAISS
5
+ from langchain.chains import RetrievalQA
6
+ from langchain.chat_models import AzureChatOpenAI
7
+ import os
8
+
9
+ def initialize_data(vector_store_dir: str="data/IRM-help-reviews-faiss"):
10
+ db = FAISS.load_local(vector_store_dir, AzureOpenAIEmbeddings())
11
+ llm = AzureChatOpenAI(model_name="gpt-35-turbo", temperature=0.5)
12
+
13
+ global IRM_REVIEW_BOT
14
+ IRM_REVIEW_BOT = RetrievalQA.from_chain_type(llm,
15
+ retriever=db.as_retriever(search_type="similarity_score_threshold",
16
+ search_kwargs={"score_threshold": 0.7}))
17
+ IRM_REVIEW_BOT.return_source_documents = True
18
+
19
+ return IRM_REVIEW_BOT
20
+
21
+ def chat(message, history):
22
+ print(f"[message]{message}")
23
+ print(f"[history]{history}")
24
+ enable_chat = True
25
+
26
+ ans = IRM_REVIEW_BOT({"query": message})
27
+ if ans["source_documents"] or enable_chat:
28
+ print(f"[result]{ans['result']}")
29
+ print(f"[source_documents]{ans['source_documents']}")
30
+ return ans["result"]
31
+ else:
32
+ return "I don't know."
33
+
34
+
35
+ def launch_ui():
36
+ demo = gr.ChatInterface(
37
+ fn=chat,
38
+ title="IRM Help Review",
39
+ chatbot=gr.Chatbot(height=600),
40
+ )
41
+
42
+ demo.launch(share=True)
43
+
44
+ if __name__ == "__main__":
45
+ os.environ["OPENAI_API_TYPE"] = "azure"
46
+ os.environ["OPENAI_API_VERSION"] = "2023-05-15"
47
+ os.environ["OPENAI_API_BASE"] = "https://pvg-azure-openai-uk-south.openai.azure.com/openai"
48
+ initialize_data()
49
+ launch_ui()
data/IRM-help-reviews-faiss/index.faiss ADDED
Binary file (123 kB). View file
 
data/IRM-help-reviews-faiss/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74eb59363e4f6933b4af82eed9ee0e9e9079c7916ac0a9ad41ee63902084eb58
3
+ size 32019
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ faiss-cpu==1.7.4
2
+ langchain==0.1.7
3
+ langchain-community==0.0.20
4
+ langchain-core==0.1.23
5
+ openai==1.12.0
6
+ tiktoken==0.6.0