浏览代码

add assistant to canvas chat history (#3201)

### What problem does this PR solve?

#3185

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.14.0
Kevin Hu 1年前
父节点
当前提交
339639a9db
没有帐户链接到提交者的电子邮件
共有 4 个文件被更改,包括 7 次插入7 次删除
  1. 4
    6
      agent/canvas.py
  2. 1
    0
      api/apps/api_app.py
  3. 1
    0
      api/apps/canvas_app.py
  4. 1
    1
      api/db/services/dialog_service.py

+ 4
- 6
agent/canvas.py 查看文件

# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
import importlib
import json import json
import traceback import traceback
from abc import ABC from abc import ABC
from copy import deepcopy from copy import deepcopy
from functools import partial from functools import partial

import pandas as pd

from agent.component import component_class from agent.component import component_class
from agent.component.base import ComponentBase from agent.component.base import ComponentBase
from agent.settings import flow_logger, DEBUG from agent.settings import flow_logger, DEBUG
def get_history(self, window_size): def get_history(self, window_size):
convs = [] convs = []
for role, obj in self.history[window_size * -1:]: for role, obj in self.history[window_size * -1:]:
convs.append({"role": role, "content": (obj if role == "user" else
'\n'.join([str(s) for s in pd.DataFrame(obj)['content']]))})
if isinstance(obj, list) and obj and all([isinstance(o, dict) for o in obj]):
convs.append({"role": role, "content": '\n'.join([str(s.get("content", "")) for s in obj])})
else:
convs.append({"role": role, "content": str(obj)})
return convs return convs


def add_user_input(self, question): def add_user_input(self, question):

+ 1
- 0
api/apps/api_app.py 查看文件

ensure_ascii=False) + "\n\n" ensure_ascii=False) + "\n\n"


canvas.messages.append({"role": "assistant", "content": final_ans["content"], "id": message_id}) canvas.messages.append({"role": "assistant", "content": final_ans["content"], "id": message_id})
canvas.history.append(("assistant", final_ans["content"]))
if final_ans.get("reference"): if final_ans.get("reference"):
canvas.reference.append(final_ans["reference"]) canvas.reference.append(final_ans["reference"])
cvs.dsl = json.loads(str(canvas)) cvs.dsl = json.loads(str(canvas))

+ 1
- 0
api/apps/canvas_app.py 查看文件

yield "data:" + json.dumps({"retcode": 0, "retmsg": "", "data": ans}, ensure_ascii=False) + "\n\n" yield "data:" + json.dumps({"retcode": 0, "retmsg": "", "data": ans}, ensure_ascii=False) + "\n\n"


canvas.messages.append({"role": "assistant", "content": final_ans["content"], "id": message_id}) canvas.messages.append({"role": "assistant", "content": final_ans["content"], "id": message_id})
canvas.history.append(("assistant", final_ans["content"]))
if final_ans.get("reference"): if final_ans.get("reference"):
canvas.reference.append(final_ans["reference"]) canvas.reference.append(final_ans["reference"])
cvs.dsl = json.loads(str(canvas)) cvs.dsl = json.loads(str(canvas))

+ 1
- 1
api/db/services/dialog_service.py 查看文件

embd_mdl = LLMBundle(dialog.tenant_id, LLMType.EMBEDDING, embd_nms[0]) embd_mdl = LLMBundle(dialog.tenant_id, LLMType.EMBEDDING, embd_nms[0])
if not embd_mdl: if not embd_mdl:
raise LookupError("Embedding model(%s) not found" % embd_nms[0]) raise LookupError("Embedding model(%s) not found" % embd_nms[0])
if llm_id2llm_type(dialog.llm_id) == "image2text": if llm_id2llm_type(dialog.llm_id) == "image2text":
chat_mdl = LLMBundle(dialog.tenant_id, LLMType.IMAGE2TEXT, dialog.llm_id) chat_mdl = LLMBundle(dialog.tenant_id, LLMType.IMAGE2TEXT, dialog.llm_id)
else: else:

正在加载...
取消
保存