Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ def doc_index_llama(open_ai_key, txt): # 建立索引
|
|
48 |
"{context_str}"
|
49 |
"\n---------------------\n"
|
50 |
"{query_str}\n"
|
51 |
-
"
|
52 |
) # 定义模板
|
53 |
qa_template = Prompt(template) # 将模板转换成Prompt对象
|
54 |
query_engine = index.as_query_engine(text_qa_template=qa_template) # 建立查询引擎
|
@@ -125,11 +125,11 @@ def get_response_by_llama_index(open_ai_key, msg, bot, query_engine): # 获取
|
|
125 |
query_str = "历史对话如下:\n"
|
126 |
for his in bot: # 遍历历史记录
|
127 |
query_str += "用户:" + his[0] + "\n" # 加入用户的历史记录
|
128 |
-
query_str += "
|
129 |
query_str += "用户:" + msg + "\n" # 加入用户的当前输入
|
130 |
res = query_engine.query(msg) # 获取回答
|
131 |
print(res) # 显示回答
|
132 |
-
bot.append([msg, res]) # 加入历史记录
|
133 |
return bot[max(0, len(bot) - 3):] # 返回最近3轮的历史记录
|
134 |
|
135 |
|
|
|
48 |
"{context_str}"
|
49 |
"\n---------------------\n"
|
50 |
"{query_str}\n"
|
51 |
+
"请你回复用户。\n"
|
52 |
) # 定义模板
|
53 |
qa_template = Prompt(template) # 将模板转换成Prompt对象
|
54 |
query_engine = index.as_query_engine(text_qa_template=qa_template) # 建立查询引擎
|
|
|
125 |
query_str = "历史对话如下:\n"
|
126 |
for his in bot: # 遍历历史记录
|
127 |
query_str += "用户:" + his[0] + "\n" # 加入用户的历史记录
|
128 |
+
query_str += "助手:" + his[1] + "\n" # 加入机器人的历史记录
|
129 |
query_str += "用户:" + msg + "\n" # 加入用户的当前输入
|
130 |
res = query_engine.query(msg) # 获取回答
|
131 |
print(res) # 显示回答
|
132 |
+
bot.append([msg, str(res)]) # 加入历史记录
|
133 |
return bot[max(0, len(bot) - 3):] # 返回最近3轮的历史记录
|
134 |
|
135 |
|