global variable
Browse files- .gitignore +8 -0
- app.py +3 -4
- prompts/qa_sys_prompt.txt +1 -1
- prompts/summary_prompt.txt +1 -1
.gitignore
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
data/*
|
2 |
+
./idea
|
3 |
+
.DS_Store
|
4 |
+
*/.DS_Store
|
5 |
+
.idea/
|
6 |
+
*/__pycache__/*
|
7 |
+
*/*/__pycache__/*
|
8 |
+
__pycache__/
|
app.py
CHANGED
@@ -25,7 +25,7 @@ from langchain.chains.combine_documents.stuff import StuffDocumentsChain
|
|
25 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
26 |
cohere_key = '5IRbILAbjTI0VcqTsktBfKsr13Lych9iBAFbLpkj'
|
27 |
faiss_store = './output/'
|
28 |
-
|
29 |
|
30 |
|
31 |
def process(files, openai_api_key, max_tokens, n_sample):
|
@@ -64,8 +64,6 @@ def get_question(docs, openai_api_key, max_tokens, n_sample=5):
|
|
64 |
|
65 |
def get_summary(docs, openai_api_key, max_tokens, n_sample=5, verbose=None):
|
66 |
llm = ChatOpenAI(openai_api_key=openai_api_key, max_tokens=max_tokens)
|
67 |
-
# chain = load_summarize_chain(llm, chain_type="map_reduce")
|
68 |
-
# summary = chain.run(docs[:n_sample])
|
69 |
print('Generating Summary from template')
|
70 |
map_prompt = PromptTemplate(template=MyTemplate['summary_template'], input_variables=["text"])
|
71 |
combine_prompt = PromptTemplate(template=MyTemplate['summary_template'], input_variables=["text"])
|
@@ -89,12 +87,13 @@ def get_summary(docs, openai_api_key, max_tokens, n_sample=5, verbose=None):
|
|
89 |
|
90 |
|
91 |
def predict(inputs, openai_api_key, max_tokens, chat_counter, chatbot=[], history=[]):
|
|
|
92 |
print(f"chat_counter - {chat_counter}")
|
93 |
print(f'Histroy - {history}') # History: Original Input and Output in flatten list
|
94 |
print(f'chatbot - {chatbot}') # Chat Bot: 上一轮回复的[[user, AI]]
|
95 |
|
96 |
history.append(inputs)
|
97 |
-
if
|
98 |
print(f'loading faiss store from {faiss_store}')
|
99 |
docsearch = FAISS.load_local(faiss_store, OpenAIEmbeddings(openai_api_key=openai_api_key))
|
100 |
else:
|
|
|
25 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
26 |
cohere_key = '5IRbILAbjTI0VcqTsktBfKsr13Lych9iBAFbLpkj'
|
27 |
faiss_store = './output/'
|
28 |
+
docsearch = None
|
29 |
|
30 |
|
31 |
def process(files, openai_api_key, max_tokens, n_sample):
|
|
|
64 |
|
65 |
def get_summary(docs, openai_api_key, max_tokens, n_sample=5, verbose=None):
|
66 |
llm = ChatOpenAI(openai_api_key=openai_api_key, max_tokens=max_tokens)
|
|
|
|
|
67 |
print('Generating Summary from template')
|
68 |
map_prompt = PromptTemplate(template=MyTemplate['summary_template'], input_variables=["text"])
|
69 |
combine_prompt = PromptTemplate(template=MyTemplate['summary_template'], input_variables=["text"])
|
|
|
87 |
|
88 |
|
89 |
def predict(inputs, openai_api_key, max_tokens, chat_counter, chatbot=[], history=[]):
|
90 |
+
global docsearch
|
91 |
print(f"chat_counter - {chat_counter}")
|
92 |
print(f'Histroy - {history}') # History: Original Input and Output in flatten list
|
93 |
print(f'chatbot - {chatbot}') # Chat Bot: 上一轮回复的[[user, AI]]
|
94 |
|
95 |
history.append(inputs)
|
96 |
+
if docsearch is None:
|
97 |
print(f'loading faiss store from {faiss_store}')
|
98 |
docsearch = FAISS.load_local(faiss_store, OpenAIEmbeddings(openai_api_key=openai_api_key))
|
99 |
else:
|
prompts/qa_sys_prompt.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
You are a smart assistant designed to help high school teachers come up with reading comprehension questions.
|
2 |
-
Given a piece of text, you must come up with a question and answer in finance area,
|
3 |
When coming up with this question/answer pair, you must respond in the following format, and always respond in chinese:
|
4 |
```
|
5 |
{{
|
|
|
1 |
You are a smart assistant designed to help high school teachers come up with reading comprehension questions.
|
2 |
+
Given a piece of text, you must come up with a question and answer in finance-related area, including but not limited to economics, politics, financial markets, corporate finance, etc.
|
3 |
When coming up with this question/answer pair, you must respond in the following format, and always respond in chinese:
|
4 |
```
|
5 |
{{
|
prompts/summary_prompt.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
Write a concise summary of the following in chinese
|
2 |
|
3 |
|
4 |
"{text}"
|
|
|
1 |
+
Write a concise summary of the following in chinese:
|
2 |
|
3 |
|
4 |
"{text}"
|