Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/api/completions.go
2649 views
1
package api
2
3
import "encoding/json"
4
5
// Float64 is a custom type that wraps float64 and implements a custom YAML marshaller.
6
type Float64 float64
7
8
// MarshalJSON omits the field if the value is 0.0.
9
func (f Float64) MarshalJSON() ([]byte, error) {
10
if f == 0.0 {
11
return []byte("null"), nil // Returning null to omit the field
12
}
13
return json.Marshal(float64(f))
14
}
15
16
type CompletionsRequest struct {
17
Model string `json:"model"`
18
Temperature float64 `json:"temperature,omitempty"`
19
TopP float64 `json:"top_p,omitempty"`
20
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
21
MaxTokens int `json:"max_completion_tokens"`
22
PresencePenalty float64 `json:"presence_penalty,omitempty"`
23
Messages []Message `json:"messages"`
24
Stream bool `json:"stream"`
25
Seed int `json:"seed,omitempty"`
26
}
27
28
type Message struct {
29
Role string `json:"role"`
30
Name string `json:"name,omitempty"`
31
Content interface{} `json:"content"`
32
}
33
34
type AudioContent struct {
35
Type string `json:"type"`
36
Text string `json:"text,omitempty"`
37
InputAudio InputAudio `json:"input_audio,omitempty"`
38
}
39
40
type InputAudio struct {
41
Data string `json:"data"`
42
Format string `json:"format"`
43
}
44
45
type ImageContent struct {
46
Type string `json:"type"`
47
ImageURL struct {
48
URL string `json:"url"`
49
} `json:"image_url"`
50
}
51
52
type CompletionsResponse struct {
53
ID string `json:"id"`
54
Object string `json:"object"`
55
Created int `json:"created"`
56
Model string `json:"model"`
57
Usage Usage `json:"usage"`
58
Choices []Choice `json:"choices"`
59
}
60
61
type Usage struct {
62
PromptTokens int `json:"prompt_tokens"`
63
CompletionTokens int `json:"completion_tokens"`
64
TotalTokens int `json:"total_tokens"`
65
}
66
67
type Choice struct {
68
Message Message `json:"message"`
69
FinishReason string `json:"finish_reason"`
70
Index int `json:"index"`
71
}
72
73
type Data struct {
74
ID string `json:"id"`
75
Object string `json:"object"`
76
Created int `json:"created"`
77
Model string `json:"model"`
78
Temperature float64 `json:"temperature"`
79
TopP float64 `json:"top_p"`
80
FrequencyPenalty float64 `json:"frequency_penalty"`
81
PresencePenalty float64 `json:"presence_penalty"`
82
Choices []struct {
83
Delta map[string]interface{} `json:"delta"`
84
Index int `json:"index"`
85
FinishReason string `json:"finish_reason"`
86
} `json:"choices"`
87
}
88
89
type ErrorResponse struct {
90
Error struct {
91
Message string `json:"message"`
92
Type string `json:"type"`
93
Code string `json:"code"`
94
} `json:"error"`
95
}
96
97