-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.go
78 lines (62 loc) · 1.52 KB
/
chat.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
package aisuite
type FunctionCall struct {
Name string
Args string
}
type ToolCall struct {
ID string
Tool string
Function FunctionCall
}
type FinishReason string
const (
FinishReasonNone FinishReason = ""
FinishReasonStop FinishReason = "stop"
FinishReasonMaxTokens FinishReason = "max_tokens"
FinishReasonContentFilter FinishReason = "content_filter"
FinishReasonUnknown FinishReason = "unknown"
)
// ChatCompletionMessage is a message in a chat completion request.
type Role string
const (
RoleUser Role = "user"
RoleSystem Role = "system"
RoleAssistant Role = "assistant"
)
type ChatCompletionMessage struct {
Role Role
Content string
}
type ChatCompletionRequest struct {
Model string
Messages []ChatCompletionMessage
MaxTokens int
Stream bool
}
type ChatCompletionChoice struct {
Message ChatCompletionMessage
}
type ChatCompletionResponse struct {
Choices []ChatCompletionChoice
}
// ChatCompletionStreamResponse is the response from a chat completion stream.
type ChatCompletionStreamChoiceDelta struct {
Content string
Role Role
FunctionCall *FunctionCall
ToolCalls []ToolCall
Refusal string
}
type ChatCompletionStreamChoice struct {
Delta ChatCompletionStreamChoiceDelta
FinishReason FinishReason
}
type ChatCompletionStreamResponse struct {
ID string
Model string
Choices []ChatCompletionStreamChoice
}
type ChatCompletionStream interface {
Recv() (ChatCompletionStreamResponse, error)
Close() error
}