H
commited on
Commit
·
1fa0527
1
Parent(s):
69a7c76
Fix web search and template max tokens (#1564)
Browse files### What problem does this PR solve?
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- graph/canvas.py +1 -0
- graph/component/baidu.py +5 -3
- graph/component/duckduckgo.py +5 -2
- graph/component/generate.py +2 -2
- graph/component/wikipedia.py +3 -3
- graph/templates/websearch_assistant.json +3 -6
graph/canvas.py
CHANGED
@@ -188,6 +188,7 @@ class Canvas(ABC):
|
|
188 |
def prepare2run(cpns):
|
189 |
nonlocal ran, ans
|
190 |
for c in cpns:
|
|
|
191 |
cpn = self.components[c]["obj"]
|
192 |
if cpn.component_name == "Answer":
|
193 |
self.answer.append(c)
|
|
|
188 |
def prepare2run(cpns):
|
189 |
nonlocal ran, ans
|
190 |
for c in cpns:
|
191 |
+
if self.path[-1] and c == self.path[-1][-1]: continue
|
192 |
cpn = self.components[c]["obj"]
|
193 |
if cpn.component_name == "Answer":
|
194 |
self.answer.append(c)
|
graph/component/baidu.py
CHANGED
@@ -43,7 +43,7 @@ class Baidu(ComponentBase, ABC):
|
|
43 |
ans = self.get_input()
|
44 |
ans = " - ".join(ans["content"]) if "content" in ans else ""
|
45 |
if not ans:
|
46 |
-
return Baidu.be_output(
|
47 |
|
48 |
url = 'https://www.baidu.com/s?wd=' + ans + '&rn=' + str(self._param.top_n)
|
49 |
headers = {
|
@@ -56,8 +56,10 @@ class Baidu(ComponentBase, ABC):
|
|
56 |
baidu_res = [{"content": re.sub('<em>|</em>', '', '<a href="' + url + '">' + title + '</a> ' + body)} for url, title, body in zip(url_res, title_res, body_res)]
|
57 |
del body_res, url_res, title_res
|
58 |
|
59 |
-
|
60 |
-
|
61 |
|
|
|
|
|
62 |
return df
|
63 |
|
|
|
43 |
ans = self.get_input()
|
44 |
ans = " - ".join(ans["content"]) if "content" in ans else ""
|
45 |
if not ans:
|
46 |
+
return Baidu.be_output("")
|
47 |
|
48 |
url = 'https://www.baidu.com/s?wd=' + ans + '&rn=' + str(self._param.top_n)
|
49 |
headers = {
|
|
|
56 |
baidu_res = [{"content": re.sub('<em>|</em>', '', '<a href="' + url + '">' + title + '</a> ' + body)} for url, title, body in zip(url_res, title_res, body_res)]
|
57 |
del body_res, url_res, title_res
|
58 |
|
59 |
+
if not baidu_res:
|
60 |
+
return Baidu.be_output("")
|
61 |
|
62 |
+
df = pd.DataFrame(baidu_res)
|
63 |
+
if DEBUG: print(df, ":::::::::::::::::::::::::::::::::")
|
64 |
return df
|
65 |
|
graph/component/duckduckgo.py
CHANGED
@@ -44,7 +44,7 @@ class DuckDuckGo(ComponentBase, ABC):
|
|
44 |
ans = self.get_input()
|
45 |
ans = " - ".join(ans["content"]) if "content" in ans else ""
|
46 |
if not ans:
|
47 |
-
return DuckDuckGo.be_output(
|
48 |
|
49 |
if self._param.channel == "text":
|
50 |
with DDGS() as ddgs:
|
@@ -57,6 +57,9 @@ class DuckDuckGo(ComponentBase, ABC):
|
|
57 |
duck_res = [{"content": '<a href="' + i["url"] + '">' + i["title"] + '</a> ' + i["body"]} for i in
|
58 |
ddgs.news(ans, max_results=self._param.top_n)]
|
59 |
|
|
|
|
|
|
|
60 |
df = pd.DataFrame(duck_res)
|
61 |
-
print(df, ":::::::::::::::::::::::::::::::::")
|
62 |
return df
|
|
|
44 |
ans = self.get_input()
|
45 |
ans = " - ".join(ans["content"]) if "content" in ans else ""
|
46 |
if not ans:
|
47 |
+
return DuckDuckGo.be_output("")
|
48 |
|
49 |
if self._param.channel == "text":
|
50 |
with DDGS() as ddgs:
|
|
|
57 |
duck_res = [{"content": '<a href="' + i["url"] + '">' + i["title"] + '</a> ' + i["body"]} for i in
|
58 |
ddgs.news(ans, max_results=self._param.top_n)]
|
59 |
|
60 |
+
if not duck_res:
|
61 |
+
return DuckDuckGo.be_output("")
|
62 |
+
|
63 |
df = pd.DataFrame(duck_res)
|
64 |
+
if DEBUG: print(df, ":::::::::::::::::::::::::::::::::")
|
65 |
return df
|
graph/component/generate.py
CHANGED
@@ -72,14 +72,14 @@ class Generate(ComponentBase):
|
|
72 |
prompt = self._param.prompt
|
73 |
|
74 |
retrieval_res = self.get_input()
|
75 |
-
input = "\n- ".join(retrieval_res["content"]) if "content" in retrieval_res else ""
|
76 |
for para in self._param.parameters:
|
77 |
cpn = self._canvas.get_component(para["component_id"])["obj"]
|
78 |
_, out = cpn.output(allow_partial=False)
|
79 |
if "content" not in out.columns:
|
80 |
kwargs[para["key"]] = "Nothing"
|
81 |
else:
|
82 |
-
kwargs[para["key"]] = "\n
|
83 |
|
84 |
kwargs["input"] = input
|
85 |
for n, v in kwargs.items():
|
|
|
72 |
prompt = self._param.prompt
|
73 |
|
74 |
retrieval_res = self.get_input()
|
75 |
+
input = (" - " + "\n - ".join(retrieval_res["content"])) if "content" in retrieval_res else ""
|
76 |
for para in self._param.parameters:
|
77 |
cpn = self._canvas.get_component(para["component_id"])["obj"]
|
78 |
_, out = cpn.output(allow_partial=False)
|
79 |
if "content" not in out.columns:
|
80 |
kwargs[para["key"]] = "Nothing"
|
81 |
else:
|
82 |
+
kwargs[para["key"]] = " - " + "\n - ".join(out["content"])
|
83 |
|
84 |
kwargs["input"] = input
|
85 |
for n, v in kwargs.items():
|
graph/component/wikipedia.py
CHANGED
@@ -30,7 +30,7 @@ class WikipediaParam(ComponentParamBase):
|
|
30 |
def __init__(self):
|
31 |
super().__init__()
|
32 |
self.top_n = 10
|
33 |
-
self.language =
|
34 |
|
35 |
def check(self):
|
36 |
self.check_positive_integer(self.top_n, "Top N")
|
@@ -49,7 +49,7 @@ class Wikipedia(ComponentBase, ABC):
|
|
49 |
ans = self.get_input()
|
50 |
ans = " - ".join(ans["content"]) if "content" in ans else ""
|
51 |
if not ans:
|
52 |
-
return Wikipedia.be_output(
|
53 |
|
54 |
wiki_res = []
|
55 |
wikipedia.set_lang(self._param.language)
|
@@ -63,7 +63,7 @@ class Wikipedia(ComponentBase, ABC):
|
|
63 |
pass
|
64 |
|
65 |
if not wiki_res:
|
66 |
-
return Wikipedia.be_output(
|
67 |
|
68 |
df = pd.DataFrame(wiki_res)
|
69 |
if DEBUG: print(df, ":::::::::::::::::::::::::::::::::")
|
|
|
30 |
def __init__(self):
|
31 |
super().__init__()
|
32 |
self.top_n = 10
|
33 |
+
self.language = "en"
|
34 |
|
35 |
def check(self):
|
36 |
self.check_positive_integer(self.top_n, "Top N")
|
|
|
49 |
ans = self.get_input()
|
50 |
ans = " - ".join(ans["content"]) if "content" in ans else ""
|
51 |
if not ans:
|
52 |
+
return Wikipedia.be_output("")
|
53 |
|
54 |
wiki_res = []
|
55 |
wikipedia.set_lang(self._param.language)
|
|
|
63 |
pass
|
64 |
|
65 |
if not wiki_res:
|
66 |
+
return Wikipedia.be_output("")
|
67 |
|
68 |
df = pd.DataFrame(wiki_res)
|
69 |
if DEBUG: print(df, ":::::::::::::::::::::::::::::::::")
|
graph/templates/websearch_assistant.json
CHANGED
@@ -59,7 +59,6 @@
|
|
59 |
"cite": true,
|
60 |
"frequency_penalty": 0.7,
|
61 |
"llm_id": "deepseek-chat",
|
62 |
-
"max_tokens": 2048,
|
63 |
"message_history_window_size": 12,
|
64 |
"parameters": [
|
65 |
{
|
@@ -108,7 +107,7 @@
|
|
108 |
"frequencyPenaltyEnabled": true,
|
109 |
"frequency_penalty": 0.7,
|
110 |
"llm_id": "deepseek-chat",
|
111 |
-
"maxTokensEnabled":
|
112 |
"max_tokens": 256,
|
113 |
"parameter": "Precise",
|
114 |
"presencePenaltyEnabled": true,
|
@@ -366,7 +365,7 @@
|
|
366 |
"frequencyPenaltyEnabled": true,
|
367 |
"frequency_penalty": 0.7,
|
368 |
"llm_id": "deepseek-chat",
|
369 |
-
"maxTokensEnabled":
|
370 |
"max_tokens": 256,
|
371 |
"parameter": "Precise",
|
372 |
"presencePenaltyEnabled": true,
|
@@ -510,8 +509,6 @@
|
|
510 |
"frequencyPenaltyEnabled": true,
|
511 |
"frequency_penalty": 0.7,
|
512 |
"llm_id": "deepseek-chat",
|
513 |
-
"maxTokensEnabled": true,
|
514 |
-
"max_tokens": 2048,
|
515 |
"message_history_window_size": 12,
|
516 |
"parameter": "Precise",
|
517 |
"parameters": [
|
@@ -538,7 +535,7 @@
|
|
538 |
],
|
539 |
"presencePenaltyEnabled": true,
|
540 |
"presence_penalty": 0.4,
|
541 |
-
"prompt": "Role: You are an intelligent assistant. \nTask: Chat with user. Answer the question based on the provided content from: Knowledge Base, Wikipedia, Duckduckgo, Baidu.\nRequirements:\n - Answer should be in markdown format.\n -
|
542 |
"temperature": 0.1,
|
543 |
"temperatureEnabled": true,
|
544 |
"topPEnabled": true,
|
|
|
59 |
"cite": true,
|
60 |
"frequency_penalty": 0.7,
|
61 |
"llm_id": "deepseek-chat",
|
|
|
62 |
"message_history_window_size": 12,
|
63 |
"parameters": [
|
64 |
{
|
|
|
107 |
"frequencyPenaltyEnabled": true,
|
108 |
"frequency_penalty": 0.7,
|
109 |
"llm_id": "deepseek-chat",
|
110 |
+
"maxTokensEnabled": true,
|
111 |
"max_tokens": 256,
|
112 |
"parameter": "Precise",
|
113 |
"presencePenaltyEnabled": true,
|
|
|
365 |
"frequencyPenaltyEnabled": true,
|
366 |
"frequency_penalty": 0.7,
|
367 |
"llm_id": "deepseek-chat",
|
368 |
+
"maxTokensEnabled": true,
|
369 |
"max_tokens": 256,
|
370 |
"parameter": "Precise",
|
371 |
"presencePenaltyEnabled": true,
|
|
|
509 |
"frequencyPenaltyEnabled": true,
|
510 |
"frequency_penalty": 0.7,
|
511 |
"llm_id": "deepseek-chat",
|
|
|
|
|
512 |
"message_history_window_size": 12,
|
513 |
"parameter": "Precise",
|
514 |
"parameters": [
|
|
|
535 |
],
|
536 |
"presencePenaltyEnabled": true,
|
537 |
"presence_penalty": 0.4,
|
538 |
+
"prompt": "Role: You are an intelligent assistant. \nTask: Chat with user. Answer the question based on the provided content from: Knowledge Base, Wikipedia, Duckduckgo, Baidu.\nRequirements:\n - Answer should be in markdown format.\n - Answer should include all sources(Knowledge Base, Wikipedia, Duckduckgo, Baidu) as long as they are relevant, and label the sources of the cited content separately.\n - Attach URL links to the content which is quoted from Wikipedia, DuckDuckGo or Baidu.\n - Do not make thing up when there's no relevant information to user's question. \n\n## Knowledge base content\n {kb_input}\n\n\n## Wikipedia content\n{wikipedia}\n\n\n## Duckduckgo content\n{duckduckgo}\n\n\n## Baidu content\n{baidu}",
|
539 |
"temperature": 0.1,
|
540 |
"temperatureEnabled": true,
|
541 |
"topPEnabled": true,
|