peichao.dong
commited on
Commit
•
0040b8b
1
Parent(s):
1d2148a
update OpenAI into ChatOpenAI
Browse files- agents/code_generate_agent.py +1 -0
- agents/tools/python_code_tool.py +6 -3
- embedding.py +2 -3
agents/code_generate_agent.py
CHANGED
@@ -2,6 +2,7 @@ import re
|
|
2 |
from typing import List, Union
|
3 |
from langchain.chains import LLMChain
|
4 |
from langchain.chat_models import ChatOpenAI
|
|
|
5 |
from langchain.agents import Tool, LLMSingleActionAgent, AgentExecutor, AgentOutputParser
|
6 |
from langchain.schema import AgentAction, AgentFinish
|
7 |
from langchain.agents import initialize_agent
|
|
|
2 |
from typing import List, Union
|
3 |
from langchain.chains import LLMChain
|
4 |
from langchain.chat_models import ChatOpenAI
|
5 |
+
from langchain.llms import OpenAI
|
6 |
from langchain.agents import Tool, LLMSingleActionAgent, AgentExecutor, AgentOutputParser
|
7 |
from langchain.schema import AgentAction, AgentFinish
|
8 |
from langchain.agents import initialize_agent
|
agents/tools/python_code_tool.py
CHANGED
@@ -1,21 +1,24 @@
|
|
1 |
import re
|
2 |
-
from langchain import LLMChain,
|
3 |
from langchain.chat_models import ChatOpenAI
|
|
|
4 |
from langchain.agents import tool
|
5 |
from langchain.utilities import PythonREPL
|
6 |
|
7 |
|
8 |
generate_python_code = """
|
9 |
-
|
10 |
|
11 |
---
|
12 |
{input}
|
13 |
---
|
|
|
|
|
14 |
"""
|
15 |
|
16 |
generate_python_code_promopt = PromptTemplate(input_variables=["input"], template=generate_python_code,)
|
17 |
|
18 |
-
generate_code_chain = LLMChain(llm =
|
19 |
|
20 |
|
21 |
@tool("Generate and Excute Python Code ", return_direct=True)
|
|
|
1 |
import re
|
2 |
+
from langchain import LLMChain, PromptTemplate
|
3 |
from langchain.chat_models import ChatOpenAI
|
4 |
+
from langchain.llms import OpenAI
|
5 |
from langchain.agents import tool
|
6 |
from langchain.utilities import PythonREPL
|
7 |
|
8 |
|
9 |
generate_python_code = """
|
10 |
+
Please write Python script to fulfill the following requirement:
|
11 |
|
12 |
---
|
13 |
{input}
|
14 |
---
|
15 |
+
|
16 |
+
Only output the code section without including code block symbols.
|
17 |
"""
|
18 |
|
19 |
generate_python_code_promopt = PromptTemplate(input_variables=["input"], template=generate_python_code,)
|
20 |
|
21 |
+
generate_code_chain = LLMChain(llm = ChatOpenAI(temperature=0.1), prompt=generate_python_code_promopt, output_key="code")
|
22 |
|
23 |
|
24 |
@tool("Generate and Excute Python Code ", return_direct=True)
|
embedding.py
CHANGED
@@ -7,7 +7,7 @@ from langchain.chains import RetrievalQA
|
|
7 |
from langchain.chains.question_answering import load_qa_chain
|
8 |
|
9 |
from langchain.document_loaders import NotionDirectoryLoader
|
10 |
-
from langchain.
|
11 |
from langchain.memory import ConversationBufferMemory
|
12 |
from langchain.chains import ConversationalRetrievalChain
|
13 |
|
@@ -32,12 +32,11 @@ class CustomEmbedding:
|
|
32 |
|
33 |
|
34 |
|
35 |
-
def getFAQChain(self, llm=
|
36 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
37 |
docsearch = FAISS.load_local(
|
38 |
"./documents/business_context.faiss", self.embeddings)
|
39 |
# retriever = VectorStoreRetriever(vectorstore=docsearch)
|
40 |
-
llm = OpenAI(temperature=0)
|
41 |
_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question in chinese.
|
42 |
|
43 |
Chat History:
|
|
|
7 |
from langchain.chains.question_answering import load_qa_chain
|
8 |
|
9 |
from langchain.document_loaders import NotionDirectoryLoader
|
10 |
+
from langchain.chat_models import ChatOpenAI
|
11 |
from langchain.memory import ConversationBufferMemory
|
12 |
from langchain.chains import ConversationalRetrievalChain
|
13 |
|
|
|
32 |
|
33 |
|
34 |
|
35 |
+
def getFAQChain(self, llm=ChatOpenAI(temperature=0.7)):
|
36 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
37 |
docsearch = FAISS.load_local(
|
38 |
"./documents/business_context.faiss", self.embeddings)
|
39 |
# retriever = VectorStoreRetriever(vectorstore=docsearch)
|
|
|
40 |
_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question in chinese.
|
41 |
|
42 |
Chat History:
|