Merge branch 'awel-flow2.0' into chore/update-api

This commit is contained in:
谨欣
2024-08-15 12:19:13 +08:00
4 changed files with 124 additions and 28 deletions

View File

@@ -11,6 +11,7 @@ _UI_TYPE = Literal[
"select", "select",
"cascader", "cascader",
"checkbox", "checkbox",
"radio",
"date_picker", "date_picker",
"input", "input",
"text_area", "text_area",
@@ -175,6 +176,12 @@ class UICheckbox(UIComponent):
self._check_options(parameter_dict.get("options", {})) self._check_options(parameter_dict.get("options", {}))
class UIRadio(UICheckbox):
"""Radio component."""
ui_type: Literal["radio"] = Field("radio", frozen=True) # type: ignore
class UIDatePicker(UIComponent): class UIDatePicker(UIComponent):
"""Date picker component.""" """Date picker component."""
@@ -232,23 +239,31 @@ class UIInput(UIComponent):
class UITextArea(PanelEditorMixin, UIInput): class UITextArea(PanelEditorMixin, UIInput):
"""Text area component.""" """Text area component."""
class AutoSize(BaseModel): class UIAttribute(UIInput.UIAttribute):
"""Auto size configuration.""" """Text area attribute."""
min_rows: Optional[int] = Field( class AutoSize(BaseModel):
"""Auto size configuration."""
min_rows: Optional[int] = Field(
None,
description="The minimum number of rows",
)
max_rows: Optional[int] = Field(
None,
description="The maximum number of rows",
)
auto_size: Optional[Union[bool, AutoSize]] = Field(
None, None,
description="The minimum number of rows", description="Whether the height of the textarea automatically adjusts "
) "based on the content",
max_rows: Optional[int] = Field(
None,
description="The maximum number of rows",
) )
ui_type: Literal["text_area"] = Field("text_area", frozen=True) # type: ignore ui_type: Literal["text_area"] = Field("text_area", frozen=True) # type: ignore
autosize: Optional[Union[bool, AutoSize]] = Field( attr: Optional[UIAttribute] = Field(
None, None,
description="Whether the height of the textarea automatically adjusts based " description="The attributes of the component",
"on the content",
) )
@@ -430,8 +445,9 @@ class UICodeEditor(UITextArea):
class DefaultUITextArea(UITextArea): class DefaultUITextArea(UITextArea):
"""Default text area component.""" """Default text area component."""
autosize: Union[bool, UITextArea.AutoSize] = Field( attr: Optional[UITextArea.UIAttribute] = Field(
default_factory=lambda: UITextArea.AutoSize(min_rows=2, max_rows=40), default_factory=lambda: UITextArea.UIAttribute(
description="Whether the height of the textarea automatically adjusts based " auto_size=UITextArea.UIAttribute.AutoSize(min_rows=2, max_rows=40)
"on the content", ),
description="The attributes of the component",
) )

View File

@@ -1,20 +1,12 @@
import json import json
from functools import cache from functools import cache
from typing import Dict, List, Literal, Optional, Union from typing import Dict, List, Optional, Union
from fastapi import APIRouter, Depends, HTTPException, Query, Request from fastapi import APIRouter, Depends, HTTPException, Query, Request
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer
from dbgpt.component import SystemApp from dbgpt.component import SystemApp
from dbgpt.core.awel.flow import ResourceMetadata, ViewMetadata from dbgpt.core.awel.flow import ResourceMetadata, ViewMetadata
from dbgpt.core.interface.variables import (
BUILTIN_VARIABLES_CORE_FLOW_NODES,
BUILTIN_VARIABLES_CORE_FLOWS,
BUILTIN_VARIABLES_CORE_SECRETS,
BUILTIN_VARIABLES_CORE_VARIABLES,
BuiltinVariablesProvider,
StorageVariables,
)
from dbgpt.serve.core import Result, blocking_func_to_async from dbgpt.serve.core import Result, blocking_func_to_async
from dbgpt.util import PaginationResult from dbgpt.util import PaginationResult
@@ -330,6 +322,12 @@ async def update_variables(
return Result.succ(res) return Result.succ(res)
@router.post("/flow/debug")
async def debug():
"""Debug the flow."""
# TODO: Implement the debug endpoint
def init_endpoints(system_app: SystemApp) -> None: def init_endpoints(system_app: SystemApp) -> None:
"""Initialize the endpoints""" """Initialize the endpoints"""
from .variables_provider import ( from .variables_provider import (

View File

@@ -1,6 +1,7 @@
from typing import Any, List, Literal, Optional from typing import Any, Dict, List, Literal, Optional, Union
from dbgpt._private.pydantic import BaseModel, ConfigDict, Field from dbgpt._private.pydantic import BaseModel, ConfigDict, Field
from dbgpt.core.awel import CommonLLMHttpRequestBody
from dbgpt.core.awel.flow.flow_factory import FlowPanel from dbgpt.core.awel.flow.flow_factory import FlowPanel
from dbgpt.core.awel.util.parameter_util import RefreshOptionRequest from dbgpt.core.awel.util.parameter_util import RefreshOptionRequest
@@ -113,3 +114,26 @@ class RefreshNodeRequest(BaseModel):
title="The refresh options", title="The refresh options",
description="The refresh options", description="The refresh options",
) )
class FlowDebugRequest(BaseModel):
"""Flow response model"""
model_config = ConfigDict(title=f"FlowDebugRequest")
flow: ServeRequest = Field(
...,
title="The flow to debug",
description="The flow to debug",
)
request: Union[CommonLLMHttpRequestBody, Dict[str, Any]] = Field(
...,
title="The request to debug",
description="The request to debug",
)
variables: Optional[Dict[str, Any]] = Field(
None,
title="The variables to debug",
description="The variables to debug",
)
user_name: Optional[str] = Field(None, description="User name")
sys_code: Optional[str] = Field(None, description="System code")

View File

@@ -206,7 +206,7 @@ class ExampleFlowCheckboxOperator(MapOperator[str, str]):
OptionValue(label="Orange", name="orange", value="orange"), OptionValue(label="Orange", name="orange", value="orange"),
OptionValue(label="Pear", name="pear", value="pear"), OptionValue(label="Pear", name="pear", value="pear"),
], ],
ui=ui.UICheckbox(attr=ui.UICheckbox.UIAttribute(show_search=True)), ui=ui.UICheckbox(),
) )
], ],
inputs=[ inputs=[
@@ -236,6 +236,59 @@ class ExampleFlowCheckboxOperator(MapOperator[str, str]):
return "Your name is %s, and you like %s." % (user_name, ", ".join(self.fruits)) return "Your name is %s, and you like %s." % (user_name, ", ".join(self.fruits))
class ExampleFlowRadioOperator(MapOperator[str, str]):
"""An example flow operator that includes a radio as parameter."""
metadata = ViewMetadata(
label="Example Flow Radio",
name="example_flow_radio",
category=OperatorCategory.EXAMPLE,
description="An example flow operator that includes a radio as parameter.",
parameters=[
Parameter.build_from(
"Fruits Selector",
"fruits",
type=str,
optional=True,
default=None,
placeholder="Select the fruits",
description="The fruits you like.",
options=[
OptionValue(label="Apple", name="apple", value="apple"),
OptionValue(label="Banana", name="banana", value="banana"),
OptionValue(label="Orange", name="orange", value="orange"),
OptionValue(label="Pear", name="pear", value="pear"),
],
ui=ui.UIRadio(),
)
],
inputs=[
IOField.build_from(
"User Name",
"user_name",
str,
description="The name of the user.",
)
],
outputs=[
IOField.build_from(
"Fruits",
"fruits",
str,
description="User's favorite fruits.",
)
],
)
def __init__(self, fruits: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
self.fruits = fruits
async def map(self, user_name: str) -> str:
"""Map the user name to the fruits."""
return "Your name is %s, and you like %s." % (user_name, self.fruits)
class ExampleFlowDatePickerOperator(MapOperator[str, str]): class ExampleFlowDatePickerOperator(MapOperator[str, str]):
"""An example flow operator that includes a date picker as parameter.""" """An example flow operator that includes a date picker as parameter."""
@@ -348,8 +401,13 @@ class ExampleFlowTextAreaOperator(MapOperator[str, str]):
placeholder="Please input your comment", placeholder="Please input your comment",
description="The comment you want to say.", description="The comment you want to say.",
ui=ui.UITextArea( ui=ui.UITextArea(
attr=ui.UITextArea.UIAttribute(show_count=True, maxlength=1000), attr=ui.UITextArea.UIAttribute(
autosize=ui.UITextArea.AutoSize(min_rows=2, max_rows=6), show_count=True,
maxlength=1000,
auto_size=ui.UITextArea.UIAttribute.AutoSize(
min_rows=2, max_rows=6
),
),
), ),
) )
], ],