Update gif for readme and add input param to every components (#3145)

### What problem does this PR solve?


### Type of change

- [x] New Feature (non-breaking change which adds functionality)
- [x] Documentation Update
This commit is contained in:
Kevin Hu
2024-11-01 13:31:34 +08:00
committed by GitHub
parent 039cde7893
commit 33e5e5db5b
8 changed files with 47 additions and 10 deletions

View File

@ -36,6 +36,7 @@ class ComponentParamBase(ABC):
def __init__(self):
self.output_var_name = "output"
self.message_history_window_size = 22
self.query = []
def set_name(self, name: str):
self._name = name
@ -436,6 +437,16 @@ class ComponentBase(ABC):
setattr(self._param, self._param.output_var_name, v)
def get_input(self):
if self._param.query:
outs = []
for q in self._param.query:
if q["value"]: outs.append(pd.DataFrame([{"content": q["value"]}]))
if q["component_id"]: outs.append(self._canvas.get_component(q["component_id"])["obj"].output(allow_partial=False)[1])
if outs:
df = pd.concat(outs, ignore_index=True)
if "content" in df: df = df.drop_duplicates(subset=['content']).reset_index(drop=True)
return df
upstream_outs = []
reversed_cpnts = []
if len(self._canvas.path) > 1:

View File

@ -130,6 +130,7 @@ class Generate(ComponentBase):
msg = self._canvas.get_history(self._param.message_history_window_size)
_, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(chat_mdl.max_length * 0.97))
if len(msg) < 2: msg.append({"role": "user", "content": ""})
ans = chat_mdl.chat(msg[0]["content"], msg[1:], self._param.gen_conf())
if self._param.cite and "content_ltks" in retrieval_res.columns and "vector" in retrieval_res.columns:
@ -149,6 +150,7 @@ class Generate(ComponentBase):
msg = self._canvas.get_history(self._param.message_history_window_size)
_, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(chat_mdl.max_length * 0.97))
if len(msg) < 2: msg.append({"role": "user", "content": ""})
answer = ""
for ans in chat_mdl.chat_streamly(msg[0]["content"], msg[1:], self._param.gen_conf()):
res = {"content": ans, "reference": []}

View File

@ -51,6 +51,9 @@ class Invoke(ComponentBase, ABC):
for para in self._param.variables:
if para.get("component_id"):
cpn = self._canvas.get_component(para["component_id"])["obj"]
if cpn.component_name.lower() == "answer":
args[para["key"]] = self._canvas.get_history(1)[0]["content"]
continue
_, out = cpn.output(allow_partial=False)
args[para["key"]] = "\n".join(out["content"])
else:

View File

@ -152,7 +152,8 @@
"Generate:ToughLawsCheat",
"Generate:KindCarrotsSit",
"Generate:DirtyToolsTrain",
"Generate:FluffyPillowsGrow"
"Generate:FluffyPillowsGrow",
"Generate:ProudEarsWorry"
]
},
"Retrieval:ShaggyRadiosRetire": {
@ -212,7 +213,9 @@
"top_p": 0.3
}
},
"downstream": [],
"downstream": [
"Answer:TwentyMugsDeny"
],
"upstream": [
"categorize:0"
]
@ -331,9 +334,9 @@
"message_history_window_size": 12,
"parameters": [
{
"component_id": "Retrieval:ColdEelsArrive",
"id": "5166a107-e859-4c71-99a2-3a216c775347",
"key": "jd",
"component_id": "Retrieval:ColdEelsArrive"
"key": "jd"
}
],
"presence_penalty": 0.4,
@ -1266,9 +1269,9 @@
"parameter": "Precise",
"parameters": [
{
"component_id": "Retrieval:ColdEelsArrive",
"id": "5166a107-e859-4c71-99a2-3a216c775347",
"key": "jd",
"component_id": "Retrieval:ColdEelsArrive"
"key": "jd"
}
],
"presencePenaltyEnabled": true,
@ -1541,6 +1544,19 @@
"target": "Answer:TwentyMugsDeny",
"targetHandle": "c",
"type": "buttonEdge"
},
{
"type": "buttonEdge",
"markerEnd": "logo",
"style": {
"strokeWidth": 2,
"stroke": "rgb(202 197 245)"
},
"source": "Generate:ProudEarsWorry",
"sourceHandle": "b",
"target": "Answer:TwentyMugsDeny",
"targetHandle": "c",
"id": "reactflow__edge-Generate:ProudEarsWorryb-Answer:TwentyMugsDenyc"
}
]
},