-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathmodels.go
More file actions
114 lines (96 loc) · 3.04 KB
/
Copy pathmodels.go
File metadata and controls
114 lines (96 loc) · 3.04 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package openrouter
import (
"context"
"net/http"
)
const (
listModelsSuffix = "/models"
listUserModelsSuffix = "/models/user"
listEmbeddingsModelsSuffix = "/embeddings/models"
)
type ModelArchitecture struct {
InputModalities []string `json:"input_modalities"`
OutputModalities []string `json:"output_modalities"`
Tokenizer string `json:"tokenizer"`
InstructType *string `json:"instruct_type,omitempty"`
}
type ModelTopProvider struct {
IsModerated bool `json:"is_moderated"`
ContextLength *int64 `json:"context_length,omitempty"`
MaxCompletionTokens *int64 `json:"max_completion_tokens,omitempty"`
}
type ModelPricing struct {
Prompt string `json:"prompt"`
Completion string `json:"completion"`
Image string `json:"image"`
Request string `json:"request"`
WebSearch string `json:"web_search"`
InternalReasoning string `json:"internal_reasoning"`
InputCacheRead *string `json:"input_cache_read,omitempty"`
InputCacheWrite *string `json:"input_cache_write,omitempty"`
}
type Model struct {
ID string `json:"id"`
Name string `json:"name"`
Created int64 `json:"created"`
Description string `json:"description"`
Architecture ModelArchitecture `json:"architecture"`
TopProvider ModelTopProvider `json:"top_provider"`
Pricing ModelPricing `json:"pricing"`
CanonicalSlug *string `json:"canonical_slug,omitempty"`
ContextLength *int64 `json:"context_length,omitempty"`
HuggingFaceID *string `json:"hugging_face_id,omitempty"`
PerRequestLimits any `json:"per_request_limits,omitempty"`
SupportedParameters []string `json:"supported_parameters,omitempty"`
}
func (c *Client) ListModels(ctx context.Context) (models []Model, err error) {
req, err := c.newRequest(
ctx,
http.MethodGet,
c.fullURL(listModelsSuffix),
)
if err != nil {
return
}
var response struct {
Data []Model `json:"data"`
}
err = c.sendRequest(req, &response)
models = response.Data
return
}
func (c *Client) ListUserModels(ctx context.Context) (models []Model, err error) {
req, err := c.newRequest(
ctx,
http.MethodGet,
c.fullURL(listUserModelsSuffix),
)
if err != nil {
return
}
var response struct {
Data []Model `json:"data"`
}
err = c.sendRequest(req, &response)
models = response.Data
return
}
// ListEmbeddingsModels returns all available embeddings models and their properties.
// API reference: https://openrouter.ai/docs/api/api-reference/embeddings/list-embeddings-models
func (c *Client) ListEmbeddingsModels(ctx context.Context) ([]Model, error) {
req, err := c.newRequest(
ctx,
http.MethodGet,
c.fullURL(listEmbeddingsModelsSuffix),
)
if err != nil {
return nil, err
}
var response struct {
Data []Model `json:"data"`
}
if err := c.sendRequest(req, &response); err != nil {
return nil, err
}
return response.Data, nil
}