@namespace AntSK.Pages.ApiPage
@using AntSK.Domain.Repositories
@using AntSK.Models
@using AntSK.Domain.Domain.Model.Enum
@page "/plugins/api/add"
@page "/plugins/api/add/{ApiId}"
@using AntSK.Services.Auth
@inherits AuthComponentBase

<PageContainer Title="新增API">
    <ChildContent>
        <Card>
            <Form Model="@_apiModel"
                  Style="margin-top: 8px;"
                  OnFinish="HandleSubmit">
                <FormItem Label="注意" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <h3>API插件需要使用Function Call能力，建议使用GPT4，国产模型可能不太行</h3>
                </FormItem>
                <FormItem Label="Api名称" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <Input Placeholder="请输入Api名称" @bind-Value="@context.Name" />
                </FormItem>
                <FormItem Label="Api描述" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <Input Placeholder="请输入Api描述" @bind-Value="@context.Describe" />
                </FormItem>
                <FormItem Label="Url地址" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <Input Placeholder="请输入Url地址" @bind-Value="@context.Url" />
                </FormItem>
                <FormItem Label="HttpHeader" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <TextArea Placeholder="一个一行，以冒号分割。例如:Content-Type:application/json" @bind-Value="@context.Header" MinRows="3" />
                </FormItem>
                <FormItem Label="Method类型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <EnumRadioGroup ButtonStyle="@RadioButtonStyle.Outline" @bind-Value="context.Method"></EnumRadioGroup>
                 </FormItem>

                 @if (context.Method == HttpMethodType.Get)
                {
                    <FormItem Label="Query" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <TextArea Placeholder="把query构造成json格式，便于大模型识别" @bind-Value="@context.Query" MinRows="5" />
                    </FormItem>
                }
                else if (context.Method == HttpMethodType.Post)
                {
                    <FormItem Label="JsonBody" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                        <TextArea Placeholder="请输入JsonBody" @bind-Value="@context.JsonBody" MinRows="5" />
                    </FormItem>
                }

                <FormItem Label="入参提示词" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <TextArea Placeholder="请输入入参提示词" @bind-Value="@context.InputPrompt" MinRows="5" />
                </FormItem>
                <FormItem Label="返回提示词" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
                    <TextArea Placeholder="请输入返回提示词" @bind-Value="@context.OutputPrompt" MinRows="5" />
                </FormItem>
                <FormItem Label=" " Style="margin-top:32px" WrapperCol="LayoutModel._submitFormLayout.WrapperCol">
                    <Button Type="primary" HtmlType="submit">
                        保存
                    </Button>
                    <Button OnClick="Back">
                        返回
                    </Button>
                </FormItem>
            </Form>
        </Card>
    </ChildContent>
</PageContainer>


<style>
    .avatar-uploader > .ant-upload {
        width: 128px;
        height: 128px;
    }
</style>