Your Name commited on
Commit
8b05d75
·
1 Parent(s): 6a6849a
Files changed (3) hide show
  1. app.py +71 -0
  2. github +1 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from langchain import OpenAI, ConversationChain
5
+ from langchain.prompts import PromptTemplate
6
+ from langchain.embeddings.openai import OpenAIEmbeddings
7
+ from langchain.text_splitter import CharacterTextSplitter
8
+ from langchain.vectorstores.faiss import FAISS
9
+ from langchain.docstore.document import Document
10
+ from langchain.agents import Tool
11
+ from langchain.chains.conversation.memory import ConversationBufferMemory
12
+ from langchain.utilities import GoogleSearchAPIWrapper
13
+ from langchain.agents import initialize_agent
14
+
15
+ from langchain.chains.conversation.memory import ConversationEntityMemory
16
+ from langchain.chains.conversation.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
17
+
18
+ from langchain.agents import ZeroShotAgent, Tool, AgentExecutor
19
+ from langchain import SerpAPIWrapper, LLMChain
20
+
21
+ # ツールの準備
22
+ search = GoogleSearchAPIWrapper()
23
+ tools = [
24
+ Tool(
25
+ name = "Current Search",
26
+ func=search.run,
27
+ description="Use this allways",
28
+ ),
29
+ ]
30
+
31
+ # メモリの準備
32
+ memory = ConversationBufferMemory(memory_key="chat_history")
33
+
34
+ # エージェントの準備
35
+ llm=OpenAI(model_name = "text-davinci-003",temperature=0)
36
+ agent_chain = initialize_agent(
37
+ tools,
38
+ llm,
39
+ agent="zero-shot-react-description",
40
+ verbose=True,
41
+ memory=memory
42
+ )
43
+
44
+ def chat(message, site,history):
45
+ history = history or []
46
+ #siteの//以前を削除
47
+ site = site.replace("https://","")
48
+ response = ""
49
+ try:
50
+ response = agent_chain.run(input=message+" site:"+site)
51
+ except KeyError:
52
+ if not response:
53
+ response = "not found in the site"
54
+ history.append((message, response))
55
+
56
+ return history, history
57
+
58
+
59
+ with gr.Blocks() as demo:
60
+ gr.Markdown("<h3><center>WebSiteChatBotAI</center></h3>")
61
+ gr.Markdown("<p><center>paste web site URL and input question and push Run</center></p>")
62
+ site = gr.Textbox(placeholder="paste URL",label="WebSite")
63
+ chatbot = gr.Chatbot()
64
+ with gr.Row():
65
+ inp = gr.Textbox(placeholder="Question",label =None)
66
+ btn = gr.Button("Run").style(full_width=False)
67
+ state = gr.State()
68
+ agent_state = gr.State()
69
+ btn.click(chat, [inp,site,state],[chatbot, state])
70
+ if __name__ == '__main__':
71
+ demo.launch()
github ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit f9b4d012cf772c42a52ca4c1395fd75bbbbf5437
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ gradio
4
+ requests
5
+ google-api-python-client