Skip to content

Commit cf8669e

Browse files
committed
feat: regenerate go api modules with swagger-mode generator
1 parent c701843 commit cf8669e

File tree

10 files changed

+182
-372
lines changed

10 files changed

+182
-372
lines changed

apps.go

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

8-
func (r *apps) List(ctx context.Context, req *ListAppReq) (NumberPaged[SimpleApp], error) {
9-
if req.PageSize == 0 {
10-
req.PageSize = 20
8+
// List 查看应用列表
9+
func (r *apps) List(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10+
if req == nil {
11+
req = &SwaggerOperationRequest{}
1112
}
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,
13+
request := &RawRequestReq{
14+
Method: http.MethodGet,
15+
URL: buildSwaggerOperationURL("/v1/apps", req.PathParams, req.QueryParams),
16+
Body: req.Body,
7117
}
18+
response := new(SwaggerOperationResponse)
19+
err := r.core.rawRequest(ctx, request, response)
20+
return response, err
7221
}
7322

7423
type apps struct {
7524
core *core
7625
}
7726

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

audio_live.go

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

8-
// Retrieve retrieves live stream information
9-
func (r *audioLive) Retrieve(ctx context.Context, req *RetrieveAudioLiveReq) (*LiveInfo, error) {
8+
func (r *audioLive) Retrieve(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
9+
if req == nil {
10+
req = &SwaggerOperationRequest{}
11+
}
1012
request := &RawRequestReq{
1113
Method: http.MethodGet,
12-
URL: "/v1/audio/live/:live_id",
13-
Body: req,
14+
URL: buildSwaggerOperationURL("/v1/audio/live/{live_id}", req.PathParams, req.QueryParams),
15+
Body: req.Body,
1416
}
15-
response := new(retrieveAudioLiveResp)
17+
response := new(SwaggerOperationResponse)
1618
err := r.core.rawRequest(ctx, request, response)
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"`
19+
return response, err
5820
}
5921

60-
// audioLive provides operations for live audio streams
6122
type audioLive struct {
6223
core *core
6324
}

audio_speech.go

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

33
import (
44
"context"
5-
"io"
65
"net/http"
7-
"os"
86
)
97

10-
func (r *audioSpeech) Create(ctx context.Context, req *CreateAudioSpeechReq) (*CreateAudioSpeechResp, error) {
8+
// Create 语音合成
9+
func (r *audioSpeech) Create(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10+
if req == nil {
11+
req = &SwaggerOperationRequest{}
12+
}
1113
request := &RawRequestReq{
1214
Method: http.MethodPost,
13-
URL: "/v1/audio/speech",
14-
Body: req,
15+
URL: buildSwaggerOperationURL("/v1/audio/speech", req.PathParams, req.QueryParams),
16+
Body: req.Body,
1517
}
16-
response := new(createAudioSpeechResp)
18+
response := new(SwaggerOperationResponse)
1719
err := r.core.rawRequest(ctx, request, response)
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
20+
return response, err
6121
}
6222

6323
type audioSpeech struct {

audio_transcription.go

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

33
import (
44
"context"
5-
"io"
65
"net/http"
76
)
87

9-
func (r *audioTranscriptions) Create(ctx context.Context, req *AudioSpeechTranscriptionsReq) (*CreateAudioTranscriptionsResp, error) {
8+
// Create 语音识别
9+
func (r *audioTranscriptions) Create(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10+
if req == nil {
11+
req = &SwaggerOperationRequest{}
12+
}
1013
request := &RawRequestReq{
1114
Method: http.MethodPost,
12-
URL: "/v1/audio/transcriptions",
13-
Body: req,
15+
URL: buildSwaggerOperationURL("/v1/audio/transcriptions", req.PathParams, req.QueryParams),
16+
Body: req.Body,
1417
IsFile: true,
1518
}
16-
response := new(createAudioTranscriptionsResp)
19+
response := new(SwaggerOperationResponse)
1720
err := r.core.rawRequest(ctx, request, response)
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"`
21+
return response, err
3822
}
3923

4024
type audioTranscriptions struct {

chats_messages.go

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

8-
func (r *chatMessages) List(ctx context.Context, req *ListChatsMessagesReq) (*ListChatsMessagesResp, error) {
8+
// List 查看对话消息详情
9+
func (r *chatMessages) List(ctx context.Context, req *SwaggerOperationRequest) (*SwaggerOperationResponse, error) {
10+
if req == nil {
11+
req = &SwaggerOperationRequest{}
12+
}
913
request := &RawRequestReq{
1014
Method: http.MethodGet,
11-
URL: "/v3/chat/message/list",
12-
Body: req,
15+
URL: buildSwaggerOperationURL("/v3/chat/message/list", req.PathParams, req.QueryParams),
16+
Body: req.Body,
1317
}
14-
response := new(listChatsMessagesResp)
18+
response := new(SwaggerOperationResponse)
1519
err := r.core.rawRequest(ctx, request, response)
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
20+
return response, err
3821
}
3922

4023
type chatMessages struct {

0 commit comments

Comments
 (0)