Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
userpj committed Aug 7, 2024
1 parent ee6de56 commit cfd6c89
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
35 changes: 35 additions & 0 deletions go/appbuilder/app_builder_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,38 @@ func (t *AppBuilderClient) Run(conversationID string, query string, fileIDS []st
}
return &AppBuilderClientOnceIterator{body: resp.Body}, nil
}

func (t *AppBuilderClient) RunWithFunction(req AppBuilderClientRunRequest) (AppBuilderClientIterator, error) {
if len(req.ConversationID) == 0 {
return nil, errors.New("conversationID mustn't be empty")
}

request := http.Request{}

serviceURL, err := t.sdkConfig.ServiceURLV2("/app/conversation/runs")
if err != nil {
return nil, err
}

header := t.sdkConfig.AuthHeaderV2()
request.URL = serviceURL
request.Method = "POST"
header.Set("Content-Type", "application/json")
request.Header = header
data, _ := json.Marshal(req)
request.Body = io.NopCloser(bytes.NewReader(data))
t.sdkConfig.BuildCurlCommand(&request)
resp, err := t.client.Do(&request)
if err != nil {
return nil, err
}
requestID, err := checkHTTPResponse(resp)
if err != nil {
return nil, fmt.Errorf("requestID=%s, err=%v", requestID, err)
}
r := NewSSEReader(1024*1024, bufio.NewReader(resp.Body))
if req.Stream {
return &AppBuilderClientStreamIterator{requestID: requestID, r: r, body: resp.Body}, nil
}
return &AppBuilderClientOnceIterator{body: resp.Body}, nil
}
25 changes: 25 additions & 0 deletions go/appbuilder/app_builder_client_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ var TypeToStruct = map[string]reflect.Type{
StatusContentType: reflect.TypeOf(StatusDetail{}),
}

type AppBuilderClientRunRequest struct {
AppID string `json:"app_id"`
Query string `json:"query"`
Stream bool `json:"stream"`
ConversationID string `json:"conversation_id"`
Tools []Tool `json:"tools"`
ToolOutputs []ToolOutput `json:"tool_outputs"`
}

type Tool struct {
Type string `json:"type"`
Function Function `json:"function"`
}

type Function struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]interface{} `json:"parameters"`
}

type ToolOutput struct {
ToolCallID string `json:"tool_call_id" description:"工具调用ID"`
Output string `json:"output" description:"工具输出"`
}

type AgentBuilderRawResponse struct {
RequestID string `json:"request_id"`
Date string `json:"date"`
Expand Down

0 comments on commit cfd6c89

Please sign in to comment.