-
Notifications
You must be signed in to change notification settings - Fork 0
/
groqcompletion.go
94 lines (82 loc) · 3.16 KB
/
groqcompletion.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
82
83
84
85
86
87
88
89
90
91
92
93
94
package omnicron
import (
"context"
)
type ToolChoice string
const (
ToolChoiceAuto ToolChoice = "auto"
ToolChoiceNone ToolChoice = "none"
)
type Message struct {
Content string `json:"content"` // Required fields, not omitting in JSON
Role string `json:"role"` // Required fields, not omitting in JSON
Name string `json:"name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []MessageToolCall `json:"tool_calls,omitempty"`
}
type MessageToolCall struct {
ID string `json:"id,omitempty"`
Function MessageToolCallFunction `json:"function,omitempty"`
Type string `json:"type,omitempty"`
}
type MessageToolCallFunction struct {
Arguments string `json:"arguments,omitempty"`
Name string `json:"name,omitempty"`
}
type ResponseFormat struct {
Type string `json:"type,omitempty"`
}
type ToolChoiceToolChoice struct {
Function ToolChoiceToolChoiceFunction `json:"function,omitempty"`
Type string `json:"type,omitempty"`
}
type ToolChoiceToolChoiceFunction struct {
Name string `json:"name,omitempty"`
}
type Tool struct {
Function ToolFunction `json:"function,omitempty"`
Type string `json:"type,omitempty"`
}
type ToolFunction struct {
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
// CompletionCreateParams represents the inputs for the groq completion params.
type GroqChatCompletionParams struct {
Messages []Message `json:"messages"`
Model string `json:"model"`
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
LogitBias map[string]int `json:"logit_bias,omitempty"`
Logprobs bool `json:"logprobs,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
N int `json:"n,omitempty"`
PresencePenalty float32 `json:"presence_penalty,omitempty"`
ResponseFormat ResponseFormat `json:"response_format,omitempty"`
Seed int `json:"seed,omitempty"`
Stop []string `json:"stop,omitempty"`
Stream bool `json:"stream,omitempty"`
Temperature float32 `json:"temperature,omitempty"`
ToolChoice ToolChoice `json:"tool_choice,omitempty"`
Tools []Tool `json:"tools,omitempty"`
TopLogprobs int `json:"top_logprobs,omitempty"`
TopP float32 `json:"top_p,omitempty"`
User string `json:"user,omitempty"`
}
func (c *Client) GroqChatCompletion(ctx context.Context, req *GroqChatCompletionParams) (*GabsContainer, error) {
if len(req.Messages) == 0 {
return nil, ErrGroqChatCompletionNoMessage
}
if req.Model == "" {
return nil, ErrModelNotFound
}
body, err := c.newJSONPostRequest(ctx, "/groq/chatcompletion", "", req)
if err != nil {
return nil, err
}
groqChatCompletionResponse, err := unmarshalJSONResponse(body)
if err != nil {
return nil, err
}
return groqChatCompletionResponse, nil
}