-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.go
More file actions
196 lines (137 loc) · 7.34 KB
/
Copy pathconstants.go
File metadata and controls
196 lines (137 loc) · 7.34 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package blmstudio
import "time"
// ── Base configuration ────────────────────────────────────────────────────────
const (
// DefaultBaseURL is the default LM Studio server address.
DefaultBaseURL = "http://localhost:1234"
// DefaultPort is the default LM Studio server port.
DefaultPort = 1234
// DefaultTimeout is the default HTTP client timeout.
// Generous to accommodate large model loading times.
DefaultTimeout = 5 * time.Minute
)
// ── API path prefixes ─────────────────────────────────────────────────────────
const (
// NativeAPIPrefix is the path prefix for the LM Studio native REST API.
NativeAPIPrefix = "/api/v1"
// OpenAIAPIPrefix is the path prefix for the OpenAI-compatible REST API.
OpenAIAPIPrefix = "/v1"
)
// ── Native API endpoint paths (/api/v1/*) ─────────────────────────────────────
const (
// PathChat is POST /api/v1/chat — native chat endpoint (text + images).
PathChat = NativeAPIPrefix + "/chat"
// PathModels is GET /api/v1/models — list all known models with metadata.
PathModels = NativeAPIPrefix + "/models"
// PathModelsLoad is POST /api/v1/models/load — load a model into memory.
PathModelsLoad = NativeAPIPrefix + "/models/load"
// PathModelsUnload is POST /api/v1/models/unload — unload a model instance.
PathModelsUnload = NativeAPIPrefix + "/models/unload"
// PathModelsDownload is POST /api/v1/models/download — start a model download.
PathModelsDownload = NativeAPIPrefix + "/models/download"
// PathModelsDownloadStatus is GET /api/v1/models/download/status/{job_id}.
// Append the job ID when constructing the full URL.
PathModelsDownloadStatus = NativeAPIPrefix + "/models/download/status/"
)
// ── OpenAI-compatible endpoint paths (/v1/*) ──────────────────────────────────
const (
// PathOpenAIModels is GET /v1/models — list models in OpenAI format.
PathOpenAIModels = OpenAIAPIPrefix + "/models"
// PathOpenAIChatCompletions is POST /v1/chat/completions.
PathOpenAIChatCompletions = OpenAIAPIPrefix + "/chat/completions"
// PathOpenAICompletions is POST /v1/completions — legacy text completions.
PathOpenAICompletions = OpenAIAPIPrefix + "/completions"
// PathOpenAIEmbeddings is POST /v1/embeddings.
PathOpenAIEmbeddings = OpenAIAPIPrefix + "/embeddings"
// PathOpenAIResponses is POST /v1/responses — OpenAI Responses API.
PathOpenAIResponses = OpenAIAPIPrefix + "/responses"
)
// ── HTTP header names and values ──────────────────────────────────────────────
const (
headerAuthorization = "Authorization"
headerContentType = "Content-Type"
headerAccept = "Accept"
contentTypeJSON = "application/json"
contentTypeEventStream = "text/event-stream"
)
// ── Model types ───────────────────────────────────────────────────────────────
const (
// ModelTypeLLM identifies a large language model.
ModelTypeLLM = "llm"
// ModelTypeEmbedding identifies an embedding model.
ModelTypeEmbedding = "embedding"
)
// ── Message roles ─────────────────────────────────────────────────────────────
const (
// RoleSystem is the system prompt role.
RoleSystem = "system"
// RoleUser is the end-user message role.
RoleUser = "user"
// RoleAssistant is the model response role.
RoleAssistant = "assistant"
// RoleTool is the tool (function) response role.
RoleTool = "tool"
)
// ── Finish reasons ────────────────────────────────────────────────────────────
const (
// FinishReasonStop means the model reached a natural stopping point.
FinishReasonStop = "stop"
// FinishReasonLength means the maximum token count was reached.
FinishReasonLength = "length"
// FinishReasonToolCalls means the model generated tool call(s).
FinishReasonToolCalls = "tool_calls"
// FinishReasonContentFilter means the output was filtered.
FinishReasonContentFilter = "content_filter"
)
// ── Native chat input item types ──────────────────────────────────────────────
const (
// InputItemTypeMessage is used for text message input items.
InputItemTypeMessage = "message"
// InputItemTypeImage is used for base64-encoded image input items.
InputItemTypeImage = "image"
)
// ── Native streaming event types (/api/v1/chat with stream: true) ─────────────
const (
// StreamEventChatStart is the first SSE event of a native streaming chat.
StreamEventChatStart = "chat.start"
// StreamEventChatDelta carries an incremental text fragment.
StreamEventChatDelta = "chat.delta"
// StreamEventChatEnd is the final SSE event containing the full output.
StreamEventChatEnd = "chat.end"
)
// ── SSE parsing tokens ────────────────────────────────────────────────────────
const (
sseDataPrefix = "data: "
sseEventPrefix = "event: "
sseDone = "[DONE]"
)
// ── Response format types ─────────────────────────────────────────────────────
const (
// ResponseFormatText requests plain text output (default).
ResponseFormatText = "text"
// ResponseFormatJSONObject requests unstructured JSON output.
ResponseFormatJSONObject = "json_object"
// ResponseFormatJSONSchema requests JSON output validated against a schema.
ResponseFormatJSONSchema = "json_schema"
)
// ── Tool choice string constants ──────────────────────────────────────────────
const (
// ToolChoiceNone instructs the model not to call any tools.
ToolChoiceNone = "none"
// ToolChoiceAuto lets the model decide whether to call a tool.
ToolChoiceAuto = "auto"
// ToolChoiceRequired forces the model to call at least one tool.
ToolChoiceRequired = "required"
)
// ── Tool types ────────────────────────────────────────────────────────────────
const (
// ToolTypeFunction is the only supported tool type.
ToolTypeFunction = "function"
)
// ── Embedding encoding formats ────────────────────────────────────────────────
const (
// EncodingFormatFloat returns embeddings as arrays of float64 (default).
EncodingFormatFloat = "float"
// EncodingFormatBase64 returns embeddings as base64-encoded strings.
EncodingFormatBase64 = "base64"
)