From cfd6c89272166d17ec95584931c9d0b4c82c2511 Mon Sep 17 00:00:00 2001
From: userpj <sudo_su@163.com>
Date: Wed, 7 Aug 2024 16:09:05 +0800
Subject: [PATCH] update

---
 go/appbuilder/app_builder_client.go      | 35 ++++++++++++++++++++++++
 go/appbuilder/app_builder_client_data.go | 25 +++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/go/appbuilder/app_builder_client.go b/go/appbuilder/app_builder_client.go
index a4fca1454..ea9ae8e2b 100644
--- a/go/appbuilder/app_builder_client.go
+++ b/go/appbuilder/app_builder_client.go
@@ -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
+}
diff --git a/go/appbuilder/app_builder_client_data.go b/go/appbuilder/app_builder_client_data.go
index 66350e5df..7d931ffbe 100644
--- a/go/appbuilder/app_builder_client_data.go
+++ b/go/appbuilder/app_builder_client_data.go
@@ -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"`