xl2533 commited on
Commit
8f2a5dc
·
1 Parent(s): dc3e78d

add max_tokens

Browse files
Files changed (4) hide show
  1. app.py +7 -5
  2. indexer/index.faiss +0 -0
  3. indexer/index.pkl +2 -2
  4. requirements.txt +1 -2
app.py CHANGED
@@ -32,7 +32,7 @@ def gen_conversation(conversations):
32
  return messages
33
 
34
 
35
- def predict(inputs, top_p, temperature, openai_api_key, enable_index,
36
  chat_counter, chatbot=[], history=[]): # repetition_penalty, top_k
37
  headers = {
38
  "Content-Type": "application/json",
@@ -44,7 +44,7 @@ def predict(inputs, top_p, temperature, openai_api_key, enable_index,
44
  if enable_index:
45
  # Faiss 检索最近的embedding
46
  docsearch = FAISS.load_local(faiss_store, CohereEmbeddings(cohere_api_key=embeddings_key))
47
- llm = ChatOpenAI(openai_api_key=openai_api_key)
48
  messages_combine = [
49
  SystemMessagePromptTemplate.from_template(MyTemplate['chat_combine_template']),
50
  HumanMessagePromptTemplate.from_template("{question}")
@@ -141,9 +141,11 @@ with gr.Blocks(css="""#col_container {width: 1000px; margin-left: auto; margin-r
141
  run = gr.Button("Run")
142
 
143
  # inputs, top_p, temperature, top_k, repetition_penalty
144
- with gr.Accordion("Parameters", open=False):
145
  top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True,
146
  label="Top-p (nucleus sampling)", )
 
 
147
  temperature = gr.Slider(minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True,
148
  label="Temperature", )
149
  # top_k = gr.Slider( minimum=1, maximum=50, value=4, step=1, interactive=True, label="Top-k",)
@@ -153,9 +155,9 @@ with gr.Blocks(css="""#col_container {width: 1000px; margin-left: auto; margin-r
153
  # 后续考虑加入搜索结果
154
  enable_search = gr.Checkbox(label='是', info='是否使用搜索结果')
155
 
156
- inputs.submit(predict, [inputs, top_p, temperature, openai_api_key, enable_index, chat_counter, chatbot, state],
157
  [chatbot, state, chat_counter], )
158
- run.click(predict, [inputs, top_p, temperature, openai_api_key, enable_index, chat_counter, chatbot, state],
159
  [chatbot, state, chat_counter], )
160
 
161
  # 每次对话结束都重置对话
 
32
  return messages
33
 
34
 
35
+ def predict(inputs, top_p, temperature, openai_api_key, enable_index, max_tokens,
36
  chat_counter, chatbot=[], history=[]): # repetition_penalty, top_k
37
  headers = {
38
  "Content-Type": "application/json",
 
44
  if enable_index:
45
  # Faiss 检索最近的embedding
46
  docsearch = FAISS.load_local(faiss_store, CohereEmbeddings(cohere_api_key=embeddings_key))
47
+ llm = ChatOpenAI(openai_api_key=openai_api_key, max_tokens=max_tokens)
48
  messages_combine = [
49
  SystemMessagePromptTemplate.from_template(MyTemplate['chat_combine_template']),
50
  HumanMessagePromptTemplate.from_template("{question}")
 
141
  run = gr.Button("Run")
142
 
143
  # inputs, top_p, temperature, top_k, repetition_penalty
144
+ with gr.Accordion("Parameters", open=True):
145
  top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True,
146
  label="Top-p (nucleus sampling)", )
147
+ max_tokens = gr.Slider(minimum=512, maximum=3000, value=3000, step=100, interactive=True,
148
+ label="Max Tokens", )
149
  temperature = gr.Slider(minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True,
150
  label="Temperature", )
151
  # top_k = gr.Slider( minimum=1, maximum=50, value=4, step=1, interactive=True, label="Top-k",)
 
155
  # 后续考虑加入搜索结果
156
  enable_search = gr.Checkbox(label='是', info='是否使用搜索结果')
157
 
158
+ inputs.submit(predict, [inputs, top_p, temperature, openai_api_key, enable_index, max_tokens, chat_counter, chatbot, state],
159
  [chatbot, state, chat_counter], )
160
+ run.click(predict, [inputs, top_p, temperature, openai_api_key, enable_index, max_tokens, chat_counter, chatbot, state],
161
  [chatbot, state, chat_counter], )
162
 
163
  # 每次对话结束都重置对话
indexer/index.faiss CHANGED
Binary files a/indexer/index.faiss and b/indexer/index.faiss differ
 
indexer/index.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0e6006bd06e30b017ce77e5859f1c7b0abcad6c69ac81c9067e1adeb448ac273
3
- size 17619
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e1dfd6979bc9bf972281e3ec2a29aa93731dc16dcf84f9777c20b58d942983c
3
+ size 245756
requirements.txt CHANGED
@@ -2,5 +2,4 @@ openai==0.27.2
2
  gradio==3.21.0
3
  langchain==0.0.113
4
  cohere==3.4.0
5
- faiss-cpu==1.7.3
6
- sentence-transformers==2.2.2
 
2
  gradio==3.21.0
3
  langchain==0.0.113
4
  cohere==3.4.0
5
+ faiss-cpu==1.7.3