Skip to content

Commit

Permalink
Add support to iframe chatbot (#3929)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

#3909

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
KevinHuSh authored Dec 9, 2024
1 parent dcedfc5 commit 3d735dc
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 280 deletions.
11 changes: 11 additions & 0 deletions agent/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from agent.component import component_class
from agent.component.base import ComponentBase


class Canvas(ABC):
"""
dsl = {
Expand Down Expand Up @@ -320,3 +321,13 @@ def _find_loop(self, max_loops=6):

def get_prologue(self):
return self.components["begin"]["obj"]._param.prologue

def set_global_param(self, **kwargs):
for k, v in kwargs.items():
for q in self.components["begin"]["obj"]._param.query:
if k != q["key"]:
continue
q["value"] = v

def get_preset_param(self):
return self.components["begin"]["obj"]._param.query
7 changes: 2 additions & 5 deletions agent/component/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,14 @@ def __str__(self):
"params": {}
}
"""
out = json.loads(str(self._param)).get("output", {})
if isinstance(out, dict) and "vector" in out:
del out["vector"]
return """{{
"component_name": "{}",
"params": {},
"output": {},
"inputs": {}
}}""".format(self.component_name,
self._param,
json.dumps(out, ensure_ascii=False),
json.dumps(json.loads(str(self._param)).get("output", {}), ensure_ascii=False),
json.dumps(json.loads(str(self._param)).get("inputs", []), ensure_ascii=False)
)

Expand Down Expand Up @@ -462,7 +459,7 @@ def get_input(self):
self._param.inputs = []
outs = []
for q in self._param.query:
if q["component_id"]:
if q.get("component_id"):
if q["component_id"].split("@")[0].lower().find("begin") >= 0:
cpn_id, key = q["component_id"].split("@")
for p in self._canvas.get_component(cpn_id)["obj"]._param.query:
Expand Down
1 change: 1 addition & 0 deletions agent/component/begin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BeginParam(ComponentParamBase):
def __init__(self):
super().__init__()
self.prologue = "Hi! I'm your smart assistant. What can I do for you?"
self.query = []

def check(self):
return True
Expand Down
6 changes: 3 additions & 3 deletions agent/templates/customer_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
"parameters": [],
"presencePenaltyEnabled": true,
"presence_penalty": 0.4,
"prompt": "Role: You are a customer support. \n\nTask: Please answer the question based on content of knowledge base. \n\nRequirements & restrictions:\n - DO NOT make things up when all knowledge base content is irrelevant to the question. \n - Answers need to consider chat history.\n - Request about customer's contact information like, Wechat number, LINE number, twitter, discord, etc,. , when knowledge base content can't answer his question. So, product expert could contact him soon to solve his problem.\n\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.",
"prompt": "Role: You are a customer support. \n\nTask: Please answer the question based on content of knowledge base. \n\nReuirements & restrictions:\n - DO NOT make things up when all knowledge base content is irrelevant to the question. \n - Answers need to consider chat history.\n - Request about customer's contact information like, Wechat number, LINE number, twitter, discord, etc,. , when knowlegebase content can't answer his question. So, product expert could contact him soon to solve his problem.\n\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.",
"temperature": 0.1,
"temperatureEnabled": true,
"topPEnabled": true,
Expand Down Expand Up @@ -603,7 +603,7 @@
{
"data": {
"form": {
"text": "Static messages.\nDefine response after receive user's contact information."
"text": "Static messages.\nDefine replys after recieve user's contact information."
},
"label": "Note",
"name": "N: What else?"
Expand Down Expand Up @@ -691,7 +691,7 @@
{
"data": {
"form": {
"text": "Complete questions by conversation history.\nUser: What's RAGFlow?\nAssistant: RAGFlow is xxx.\nUser: How to deploy it?\n\nRefine it: How to deploy RAGFlow?"
"text": "Complete questions by conversation history.\nUser: What's RAGFlow?\nAssistant: RAGFlow is xxx.\nUser: How to deloy it?\n\nRefine it: How to deploy RAGFlow?"
},
"label": "Note",
"name": "N: Refine Question"
Expand Down
4 changes: 3 additions & 1 deletion api/apps/conversation_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import re
import traceback
from copy import deepcopy

from api.db.services.conversation_service import ConversationService
from api.db.services.user_service import UserTenantService
from flask import request, Response
from flask_login import login_required, current_user

from api.db import LLMType
from api.db.services.dialog_service import DialogService, ConversationService, chat, ask
from api.db.services.dialog_service import DialogService, chat, ask
from api.db.services.knowledgebase_service import KnowledgebaseService
from api.db.services.llm_service import LLMBundle, TenantService, TenantLLMService
from api import settings
Expand Down
Loading

0 comments on commit 3d735dc

Please sign in to comment.