forked from zhouyangtingwen/dify-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 15
/
api_conversations.go
81 lines (69 loc) · 2.13 KB
/
api_conversations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package dify
import (
"context"
"errors"
"fmt"
"net/http"
"strconv"
)
type ConversationsRequest struct {
LastID string `json:"last_id,omitempty"`
Limit int `json:"limit"`
User string `json:"user"`
}
type ConversationsResponse struct {
Limit int `json:"limit"`
HasMore bool `json:"has_more"`
Data []ConversationsDataResponse `json:"data"`
}
type ConversationsDataResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Inputs map[string]string `json:"inputs"`
Status string `json:"status"`
CreatedAt int64 `json:"created_at"`
}
type ConversationsRenamingRequest struct {
ConversationID string `json:"conversation_id,omitempty"`
Name string `json:"name"`
User string `json:"user"`
}
type ConversationsRenamingResponse struct {
Result string `json:"result"`
}
/* Get conversation list
* Gets the session list of the current user. By default, the last 20 sessions are returned.
*/
func (api *API) Conversations(ctx context.Context, req *ConversationsRequest) (resp *ConversationsResponse, err error) {
if req.User == "" {
err = errors.New("ConversationsRequest.User Illegal")
return
}
if req.Limit == 0 {
req.Limit = 20
}
httpReq, err := api.createBaseRequest(ctx, http.MethodGet, "/v1/conversations", nil)
if err != nil {
return
}
query := httpReq.URL.Query()
query.Set("last_id", req.LastID)
query.Set("user", req.User)
query.Set("limit", strconv.FormatInt(int64(req.Limit), 10))
httpReq.URL.RawQuery = query.Encode()
err = api.c.sendJSONRequest(httpReq, &resp)
return
}
/* Conversation renaming
* Rename conversations; the name is displayed in multi-session client interfaces.
*/
func (api *API) ConversationsRenaming(ctx context.Context, req *ConversationsRenamingRequest) (resp *ConversationsRenamingResponse, err error) {
url := fmt.Sprintf("/v1/conversations/%s/name", req.ConversationID)
req.ConversationID = ""
httpReq, err := api.createBaseRequest(ctx, http.MethodPost, url, req)
if err != nil {
return
}
err = api.c.sendJSONRequest(httpReq, &resp)
return
}