FILE / ScuroNeko/go-deepseek
methods.go
Исходный файл и его история в репозитории.
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package deepseek
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// ChatSession describes a DeepSeek chat session.
|
|
type ChatSession struct {
|
|
ID string `json:"id"`
|
|
SeqID uint64 `json:"seq_id"`
|
|
Agent string `json:"agent"`
|
|
ModelType string `json:"model_type"`
|
|
InsertedAt float64 `json:"inserted_at"`
|
|
UpdatedAt float64 `json:"updated_at"`
|
|
}
|
|
|
|
// CreateChatRes is the data returned when a chat session is created.
|
|
type CreateChatRes struct {
|
|
ChatSession ChatSession `json:"chat_session"`
|
|
TTLSeconds uint64 `json:"ttl_seconds"`
|
|
}
|
|
|
|
// CreateChat creates a chat session using a background context.
|
|
func (api *Client) CreateChat() (ChatSession, error) {
|
|
return api.CreateChatWithContext(context.Background())
|
|
}
|
|
|
|
// CreateChatWithContext creates a chat session and honors ctx cancellation.
|
|
func (api *Client) CreateChatWithContext(ctx context.Context) (ChatSession, error) {
|
|
var zero ChatSession
|
|
req := NewRequest[CreateChatRes]("POST", "chat_session/create", NoParams)
|
|
resp, err := req.DoWithContext(ctx, api)
|
|
if err != nil {
|
|
return zero, err
|
|
}
|
|
defer func() {
|
|
_ = resp.Body.Close()
|
|
}()
|
|
data, err := req.unmarshallBizResponse(resp)
|
|
if err != nil {
|
|
return zero, err
|
|
}
|
|
return data.Data.Data.ChatSession, nil
|
|
}
|
|
|
|
type deleteChatReq struct {
|
|
ChatSessionID string `json:"chat_session_id"`
|
|
}
|
|
|
|
// DeleteChat deletes a chat session using a background context.
|
|
func (api *Client) DeleteChat(chatID string) error {
|
|
return api.DeleteChatWithContext(context.Background(), chatID)
|
|
}
|
|
|
|
// DeleteChatWithContext deletes a chat session and honors ctx cancellation.
|
|
func (api *Client) DeleteChatWithContext(ctx context.Context, chatID string) error {
|
|
data := deleteChatReq{ChatSessionID: chatID}
|
|
req := NewRequest[any]("POST", "chat_session/delete", data)
|
|
resp, err := req.DoWithContext(ctx, api)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
_, err = req.unmarshallBizResponse(resp)
|
|
return err
|
|
}
|