ListChats returns all chats for the authenticated user.
(ctx context.Context, opts *ListChatsOptions)
| 2045 | |
| 2046 | // ListChats returns all chats for the authenticated user. |
| 2047 | func (c *ExperimentalClient) ListChats(ctx context.Context, opts *ListChatsOptions) ([]Chat, error) { |
| 2048 | var reqOpts []RequestOption |
| 2049 | if opts != nil { |
| 2050 | reqOpts = append(reqOpts, opts.Pagination.asRequestOption()) |
| 2051 | if opts.Query != "" { |
| 2052 | reqOpts = append(reqOpts, func(r *http.Request) { |
| 2053 | q := r.URL.Query() |
| 2054 | q.Set("q", opts.Query) |
| 2055 | r.URL.RawQuery = q.Encode() |
| 2056 | }) |
| 2057 | } |
| 2058 | if len(opts.Labels) > 0 { |
| 2059 | reqOpts = append(reqOpts, func(r *http.Request) { |
| 2060 | q := r.URL.Query() |
| 2061 | for k, v := range opts.Labels { |
| 2062 | q.Add("label", k+":"+v) |
| 2063 | } |
| 2064 | r.URL.RawQuery = q.Encode() |
| 2065 | }) |
| 2066 | } |
| 2067 | } |
| 2068 | res, err := c.Request(ctx, http.MethodGet, "/api/experimental/chats", nil, reqOpts...) |
| 2069 | if err != nil { |
| 2070 | return nil, err |
| 2071 | } |
| 2072 | defer res.Body.Close() |
| 2073 | if res.StatusCode != http.StatusOK { |
| 2074 | return nil, ReadBodyAsError(res) |
| 2075 | } |
| 2076 | var chats []Chat |
| 2077 | return chats, json.NewDecoder(res.Body).Decode(&chats) |
| 2078 | } |
| 2079 | |
| 2080 | // ListChatModels returns the available chat model catalog. |
| 2081 | func (c *ExperimentalClient) ListChatModels(ctx context.Context) (ChatModelsResponse, error) { |