Skip to content

Commit e9cee4f

Browse files
committed
feat: regenerate go api modules after removing go_api templates
1 parent cf8669e commit e9cee4f

10 files changed

Lines changed: 372 additions & 182 deletions

apps.go

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,78 @@ import (
55
"net/http"
66
)
77

8-
// List 查看应用列表
9-
func (r *apps) List(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10-
if req == nil {
11-
req = &SwaggerOperationRequest{}
8+
func (r *apps) List(ctx context.Context, req *ListAppReq) (NumberPaged[SimpleApp], error) {
9+
if req.PageSize == 0 {
10+
req.PageSize = 20
1211
}
13-
request := &RawRequestReq{
14-
Method: http.MethodGet,
15-
URL: buildSwaggerOperationURL("/v1/apps", req.PathParams, req.QueryParams),
16-
Body: req.Body,
12+
if req.PageNum == 0 {
13+
req.PageNum = 1
14+
}
15+
return NewNumberPaged(
16+
func(request *pageRequest) (*pageResponse[SimpleApp], error) {
17+
resp := new(listAppResp)
18+
err := r.core.rawRequest(ctx, &RawRequestReq{
19+
Method: http.MethodGet,
20+
URL: "/v1/apps",
21+
Body: req.toReq(request),
22+
}, resp)
23+
if err != nil {
24+
return nil, err
25+
}
26+
return &pageResponse[SimpleApp]{
27+
response: resp.HTTPResponse,
28+
HasMore: len(resp.Data.Items) >= request.PageSize,
29+
Data: resp.Data.Items,
30+
LogID: resp.HTTPResponse.LogID(),
31+
}, nil
32+
}, req.PageSize, req.PageNum)
33+
}
34+
35+
type ListAppReq struct {
36+
WorkspaceID string `query:"workspace_id" json:"-"`
37+
PublishStatus *PublishStatus `query:"publish_status" json:"-"`
38+
ConnectorID *string `query:"connector_id" json:"-"`
39+
PageNum int `query:"page_num" json:"-"`
40+
PageSize int `query:"page_size" json:"-"`
41+
}
42+
43+
type SimpleApp struct {
44+
ID string `json:"id,omitempty"`
45+
Name string `json:"name,omitempty"`
46+
Description string `json:"description,omitempty"`
47+
IconURL string `json:"icon_url,omitempty"`
48+
IsPublished bool `json:"is_published,omitempty"`
49+
OwnerUserID string `json:"owner_user_id,omitempty"`
50+
UpdatedAt int `json:"updated_at,omitempty"`
51+
PublishedAt *int `json:"published_at,omitempty"`
52+
}
53+
54+
type ListAppResp struct {
55+
Total int `json:"total"`
56+
Items []*SimpleApp `json:"items"`
57+
}
58+
59+
type listAppResp struct {
60+
baseResponse
61+
Data *ListAppResp `json:"data"`
62+
}
63+
64+
func (r ListAppReq) toReq(request *pageRequest) *ListAppReq {
65+
return &ListAppReq{
66+
WorkspaceID: r.WorkspaceID,
67+
PublishStatus: r.PublishStatus,
68+
ConnectorID: r.ConnectorID,
69+
PageNum: request.PageNum,
70+
PageSize: request.PageSize,
1771
}
18-
response := new(SwaggerOperationResponse)
19-
err := r.core.rawRequest(ctx, request, response)
20-
return response, err
2172
}
2273

2374
type apps struct {
2475
core *core
2576
}
2677

2778
func newApps(core *core) *apps {
28-
return &apps{core: core}
79+
return &apps{
80+
core: core,
81+
}
2982
}

audio_live.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,59 @@ import (
55
"net/http"
66
)
77

8-
func (r *audioLive) Retrieve(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
9-
if req == nil {
10-
req = &SwaggerOperationRequest{}
11-
}
8+
// Retrieve retrieves live stream information
9+
func (r *audioLive) Retrieve(ctx context.Context, req *RetrieveAudioLiveReq) (*LiveInfo, error) {
1210
request := &RawRequestReq{
1311
Method: http.MethodGet,
14-
URL: buildSwaggerOperationURL("/v1/audio/live/{live_id}", req.PathParams, req.QueryParams),
15-
Body: req.Body,
12+
URL: "/v1/audio/live/:live_id",
13+
Body: req,
1614
}
17-
response := new(SwaggerOperationResponse)
15+
response := new(retrieveAudioLiveResp)
1816
err := r.core.rawRequest(ctx, request, response)
19-
return response, err
17+
return response.Data, err
18+
}
19+
20+
// LiveType represents the type of live stream
21+
type LiveType string
22+
23+
const (
24+
LiveTypeOrigin LiveType = "origin"
25+
LiveTypeTranslation LiveType = "translation"
26+
)
27+
28+
func (l LiveType) String() string {
29+
return string(l)
30+
}
31+
32+
func (l LiveType) Ptr() *LiveType {
33+
return &l
34+
}
35+
36+
// StreamInfo represents information about a stream
37+
type StreamInfo struct {
38+
StreamID string `json:"stream_id"`
39+
Name string `json:"name"`
40+
LiveType LiveType `json:"live_type"`
41+
}
42+
43+
// LiveInfo represents information about a live session
44+
type LiveInfo struct {
45+
baseModel
46+
AppID string `json:"app_id"`
47+
StreamInfos []*StreamInfo `json:"stream_infos"`
48+
}
49+
50+
// RetrieveAudioLiveReq represents the request for retrieving live information
51+
type RetrieveAudioLiveReq struct {
52+
LiveID string `path:"live_id" json:"-"`
53+
}
54+
55+
type retrieveAudioLiveResp struct {
56+
baseResponse
57+
Data *LiveInfo `json:"data"`
2058
}
2159

60+
// audioLive provides operations for live audio streams
2261
type audioLive struct {
2362
core *core
2463
}

audio_speech.go

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,62 @@ package coze
22

33
import (
44
"context"
5+
"io"
56
"net/http"
7+
"os"
68
)
79

8-
// Create 语音合成
9-
func (r *audioSpeech) Create(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10-
if req == nil {
11-
req = &SwaggerOperationRequest{}
12-
}
10+
func (r *audioSpeech) Create(ctx context.Context, req *CreateAudioSpeechReq) (*CreateAudioSpeechResp, error) {
1311
request := &RawRequestReq{
1412
Method: http.MethodPost,
15-
URL: buildSwaggerOperationURL("/v1/audio/speech", req.PathParams, req.QueryParams),
16-
Body: req.Body,
13+
URL: "/v1/audio/speech",
14+
Body: req,
1715
}
18-
response := new(SwaggerOperationResponse)
16+
response := new(createAudioSpeechResp)
1917
err := r.core.rawRequest(ctx, request, response)
20-
return response, err
18+
return response.Data, err
19+
}
20+
21+
// CreateAudioSpeechReq represents the request for creating speech
22+
type CreateAudioSpeechReq struct {
23+
Input string `json:"input"`
24+
VoiceID string `json:"voice_id"`
25+
ResponseFormat *AudioFormat `json:"response_format"`
26+
Speed *float32 `json:"speed"`
27+
SampleRate *int `json:"sample_rate"`
28+
LoudnessRate *int `json:"loudness_rate"`
29+
Emotion *string `json:"emotion"`
30+
EmotionScale *float32 `json:"emotion_scale"`
31+
}
32+
33+
// CreateAudioSpeechResp represents the response for creating speech
34+
type CreateAudioSpeechResp struct {
35+
baseModel
36+
Data io.ReadCloser
37+
}
38+
39+
type createAudioSpeechResp struct {
40+
baseResponse
41+
Data *CreateAudioSpeechResp
42+
}
43+
44+
func (r *createAudioSpeechResp) SetReader(file io.ReadCloser) {
45+
if r.Data == nil {
46+
r.Data = &CreateAudioSpeechResp{}
47+
}
48+
r.Data.Data = file
49+
}
50+
51+
func (c *CreateAudioSpeechResp) WriteToFile(path string) error {
52+
file, err := os.Create(path)
53+
if err != nil {
54+
return err
55+
}
56+
defer file.Close()
57+
defer c.Data.Close()
58+
59+
_, err = io.Copy(file, c.Data)
60+
return err
2161
}
2262

2363
type audioSpeech struct {

audio_transcription.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,39 @@ package coze
22

33
import (
44
"context"
5+
"io"
56
"net/http"
67
)
78

8-
// Create 语音识别
9-
func (r *audioTranscriptions) Create(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10-
if req == nil {
11-
req = &SwaggerOperationRequest{}
12-
}
9+
func (r *audioTranscriptions) Create(ctx context.Context, req *AudioSpeechTranscriptionsReq) (*CreateAudioTranscriptionsResp, error) {
1310
request := &RawRequestReq{
1411
Method: http.MethodPost,
15-
URL: buildSwaggerOperationURL("/v1/audio/transcriptions", req.PathParams, req.QueryParams),
16-
Body: req.Body,
12+
URL: "/v1/audio/transcriptions",
13+
Body: req,
1714
IsFile: true,
1815
}
19-
response := new(SwaggerOperationResponse)
16+
response := new(createAudioTranscriptionsResp)
2017
err := r.core.rawRequest(ctx, request, response)
21-
return response, err
18+
return response.CreateAudioTranscriptionsResp, err
19+
}
20+
21+
type AudioSpeechTranscriptionsReq struct {
22+
Filename string `json:"filename"`
23+
Audio io.Reader `json:"file"`
24+
}
25+
26+
type createAudioTranscriptionsResp struct {
27+
baseResponse
28+
*CreateAudioTranscriptionsResp
29+
}
30+
31+
type CreateAudioTranscriptionsResp struct {
32+
baseModel
33+
Data AudioTranscriptionsData `json:"data"`
34+
}
35+
36+
type AudioTranscriptionsData struct {
37+
Text string `json:"text"`
2238
}
2339

2440
type audioTranscriptions struct {

chats_messages.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,36 @@ import (
55
"net/http"
66
)
77

8-
// List 查看对话消息详情
9-
func (r *chatMessages) List(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10-
if req == nil {
11-
req = &SwaggerOperationRequest{}
12-
}
8+
func (r *chatMessages) List(ctx context.Context, req *ListChatsMessagesReq) (*ListChatsMessagesResp, error) {
139
request := &RawRequestReq{
1410
Method: http.MethodGet,
15-
URL: buildSwaggerOperationURL("/v3/chat/message/list", req.PathParams, req.QueryParams),
16-
Body: req.Body,
11+
URL: "/v3/chat/message/list",
12+
Body: req,
1713
}
18-
response := new(SwaggerOperationResponse)
14+
response := new(listChatsMessagesResp)
1915
err := r.core.rawRequest(ctx, request, response)
20-
return response, err
16+
return response.ListChatsMessagesResp, err
17+
}
18+
19+
// ListChatsMessagesReq represents the request to list messages
20+
type ListChatsMessagesReq struct {
21+
// The Conversation ID can be viewed in the 'conversation_id' field of the Response when
22+
// initiating a conversation through the Chat API.
23+
ConversationID string `query:"conversation_id" json:"-"`
24+
25+
// The Chat ID can be viewed in the 'id' field of the Response when initiating a chat through the
26+
// Chat API. If it is a streaming response, check the 'id' field in the chat event of the Response.
27+
ChatID string `query:"chat_id" json:"-"`
28+
}
29+
30+
type ListChatsMessagesResp struct {
31+
baseModel
32+
Messages []*Message `json:"data"`
33+
}
34+
35+
type listChatsMessagesResp struct {
36+
baseResponse
37+
*ListChatsMessagesResp
2138
}
2239

2340
type chatMessages struct {

0 commit comments

Comments
 (0)