sglang 0.1.24__py3-none-any.whl → 0.1.25__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sglang/__init__.py +2 -2
- sglang/srt/managers/controller/model_runner.py +51 -0
- sglang/srt/server.py +6 -0
- sglang/srt/utils.py +44 -1
- sglang/version.py +1 -0
- {sglang-0.1.24.dist-info → sglang-0.1.25.dist-info}/METADATA +3 -3
- {sglang-0.1.24.dist-info → sglang-0.1.25.dist-info}/RECORD +10 -23
- sglang/backend/__init__.py +0 -0
- sglang/backend/anthropic.py +0 -77
- sglang/backend/base_backend.py +0 -80
- sglang/backend/litellm.py +0 -90
- sglang/backend/openai.py +0 -438
- sglang/backend/runtime_endpoint.py +0 -283
- sglang/backend/vertexai.py +0 -149
- sglang/bench.py +0 -627
- sglang/srt/managers/controller/dp_worker.py +0 -113
- sglang/srt/openai_api/api_adapter.py +0 -432
- sglang/srt/openai_api/openai_api_adapter.py +0 -431
- sglang/srt/openai_api/openai_protocol.py +0 -207
- sglang/srt/openai_api_adapter.py +0 -411
- sglang/srt/openai_protocol.py +0 -207
- {sglang-0.1.24.dist-info → sglang-0.1.25.dist-info}/LICENSE +0 -0
- {sglang-0.1.24.dist-info → sglang-0.1.25.dist-info}/WHEEL +0 -0
- {sglang-0.1.24.dist-info → sglang-0.1.25.dist-info}/top_level.txt +0 -0
sglang/srt/openai_api_adapter.py
DELETED
@@ -1,411 +0,0 @@
|
|
1
|
-
"""Conversion between OpenAI APIs and native SRT APIs"""
|
2
|
-
|
3
|
-
import asyncio
|
4
|
-
import json
|
5
|
-
import os
|
6
|
-
from http import HTTPStatus
|
7
|
-
|
8
|
-
from fastapi import Request
|
9
|
-
from fastapi.responses import JSONResponse, StreamingResponse
|
10
|
-
|
11
|
-
from sglang.srt.conversation import (
|
12
|
-
Conversation,
|
13
|
-
SeparatorStyle,
|
14
|
-
chat_template_exists,
|
15
|
-
generate_chat_conv,
|
16
|
-
register_conv_template,
|
17
|
-
)
|
18
|
-
from sglang.srt.managers.io_struct import GenerateReqInput
|
19
|
-
from sglang.srt.openai_protocol import (
|
20
|
-
ChatCompletionRequest,
|
21
|
-
ChatCompletionResponse,
|
22
|
-
ChatCompletionResponseChoice,
|
23
|
-
ChatCompletionResponseStreamChoice,
|
24
|
-
ChatCompletionStreamResponse,
|
25
|
-
ChatMessage,
|
26
|
-
CompletionRequest,
|
27
|
-
CompletionResponse,
|
28
|
-
CompletionResponseChoice,
|
29
|
-
CompletionResponseStreamChoice,
|
30
|
-
CompletionStreamResponse,
|
31
|
-
DeltaMessage,
|
32
|
-
ErrorResponse,
|
33
|
-
LogProbs,
|
34
|
-
UsageInfo,
|
35
|
-
)
|
36
|
-
|
37
|
-
chat_template_name = None
|
38
|
-
|
39
|
-
|
40
|
-
def create_error_response(
|
41
|
-
message: str,
|
42
|
-
err_type: str = "BadRequestError",
|
43
|
-
status_code: HTTPStatus = HTTPStatus.BAD_REQUEST,
|
44
|
-
):
|
45
|
-
error = ErrorResponse(message=message, type=err_type, code=status_code.value)
|
46
|
-
return JSONResponse(content=error.model_dump(), status_code=error.code)
|
47
|
-
|
48
|
-
|
49
|
-
def create_streaming_error_response(
|
50
|
-
message: str,
|
51
|
-
err_type: str = "BadRequestError",
|
52
|
-
status_code: HTTPStatus = HTTPStatus.BAD_REQUEST,
|
53
|
-
) -> str:
|
54
|
-
error = ErrorResponse(message=message, type=err_type, code=status_code.value)
|
55
|
-
json_str = json.dumps({"error": error.model_dump()})
|
56
|
-
return json_str
|
57
|
-
|
58
|
-
|
59
|
-
def load_chat_template_for_openai_api(chat_template_arg):
|
60
|
-
global chat_template_name
|
61
|
-
|
62
|
-
print(f"Use chat template: {chat_template_arg}")
|
63
|
-
if not chat_template_exists(chat_template_arg):
|
64
|
-
if not os.path.exists(chat_template_arg):
|
65
|
-
raise RuntimeError(
|
66
|
-
f"Chat template {chat_template_arg} is not a built-in template name "
|
67
|
-
"or a valid chat template file path."
|
68
|
-
)
|
69
|
-
with open(chat_template_arg, "r") as filep:
|
70
|
-
template = json.load(filep)
|
71
|
-
try:
|
72
|
-
sep_style = SeparatorStyle[template["sep_style"]]
|
73
|
-
except KeyError:
|
74
|
-
raise ValueError(
|
75
|
-
f"Unknown separator style: {template['sep_style']}"
|
76
|
-
) from None
|
77
|
-
register_conv_template(
|
78
|
-
Conversation(
|
79
|
-
name=template["name"],
|
80
|
-
system_template=template["system"] + "\n{system_message}",
|
81
|
-
system_message=template.get("system_message", ""),
|
82
|
-
roles=(template["user"], template["assistant"]),
|
83
|
-
sep_style=sep_style,
|
84
|
-
sep=template.get("sep", "\n"),
|
85
|
-
stop_str=template["stop_str"],
|
86
|
-
),
|
87
|
-
override=True,
|
88
|
-
)
|
89
|
-
chat_template_name = template["name"]
|
90
|
-
else:
|
91
|
-
chat_template_name = chat_template_arg
|
92
|
-
|
93
|
-
|
94
|
-
async def v1_completions(tokenizer_manager, raw_request: Request):
|
95
|
-
request_json = await raw_request.json()
|
96
|
-
request = CompletionRequest(**request_json)
|
97
|
-
|
98
|
-
if request.n != 1:
|
99
|
-
return create_error_response("n != 1 is not supported")
|
100
|
-
|
101
|
-
adapted_request = GenerateReqInput(
|
102
|
-
text=request.prompt,
|
103
|
-
sampling_params={
|
104
|
-
"temperature": request.temperature,
|
105
|
-
"max_new_tokens": request.max_tokens,
|
106
|
-
"stop": request.stop,
|
107
|
-
"top_p": request.top_p,
|
108
|
-
"presence_penalty": request.presence_penalty,
|
109
|
-
"frequency_penalty": request.frequency_penalty,
|
110
|
-
"regex": request.regex,
|
111
|
-
},
|
112
|
-
return_logprob=request.logprobs is not None and request.logprobs > 0,
|
113
|
-
top_logprobs_num=request.logprobs if request.logprobs is not None else 0,
|
114
|
-
return_text_in_logprobs=True,
|
115
|
-
stream=request.stream,
|
116
|
-
)
|
117
|
-
|
118
|
-
if adapted_request.stream:
|
119
|
-
|
120
|
-
async def generate_stream_resp():
|
121
|
-
stream_buffer = ""
|
122
|
-
n_prev_token = 0
|
123
|
-
try:
|
124
|
-
async for content in tokenizer_manager.generate_request(
|
125
|
-
adapted_request, raw_request
|
126
|
-
):
|
127
|
-
text = content["text"]
|
128
|
-
prompt_tokens = content["meta_info"]["prompt_tokens"]
|
129
|
-
completion_tokens = content["meta_info"]["completion_tokens"]
|
130
|
-
|
131
|
-
if not stream_buffer: # The first chunk
|
132
|
-
if request.echo:
|
133
|
-
# Prepend prompt in response text.
|
134
|
-
text = request.prompt + text
|
135
|
-
|
136
|
-
if request.logprobs:
|
137
|
-
# The first chunk and echo is enabled.
|
138
|
-
if not stream_buffer and request.echo:
|
139
|
-
prefill_token_logprobs = content["meta_info"][
|
140
|
-
"prefill_token_logprobs"
|
141
|
-
]
|
142
|
-
prefill_top_logprobs = content["meta_info"][
|
143
|
-
"prefill_top_logprobs"
|
144
|
-
]
|
145
|
-
else:
|
146
|
-
prefill_token_logprobs = None
|
147
|
-
prefill_top_logprobs = None
|
148
|
-
|
149
|
-
logprobs = to_openai_style_logprobs(
|
150
|
-
prefill_token_logprobs=prefill_token_logprobs,
|
151
|
-
prefill_top_logprobs=prefill_top_logprobs,
|
152
|
-
decode_token_logprobs=content["meta_info"][
|
153
|
-
"decode_token_logprobs"
|
154
|
-
][n_prev_token:],
|
155
|
-
decode_top_logprobs=content["meta_info"][
|
156
|
-
"decode_top_logprobs"
|
157
|
-
][n_prev_token:],
|
158
|
-
)
|
159
|
-
|
160
|
-
n_prev_token = len(
|
161
|
-
content["meta_info"]["decode_token_logprobs"]
|
162
|
-
)
|
163
|
-
else:
|
164
|
-
logprobs = None
|
165
|
-
|
166
|
-
delta = text[len(stream_buffer) :]
|
167
|
-
stream_buffer = stream_buffer + delta
|
168
|
-
choice_data = CompletionResponseStreamChoice(
|
169
|
-
index=0,
|
170
|
-
text=delta,
|
171
|
-
logprobs=logprobs,
|
172
|
-
finish_reason=content["meta_info"]["finish_reason"],
|
173
|
-
)
|
174
|
-
chunk = CompletionStreamResponse(
|
175
|
-
id=content["meta_info"]["id"],
|
176
|
-
object="text_completion",
|
177
|
-
choices=[choice_data],
|
178
|
-
model=request.model,
|
179
|
-
usage=UsageInfo(
|
180
|
-
prompt_tokens=prompt_tokens,
|
181
|
-
completion_tokens=completion_tokens,
|
182
|
-
total_tokens=prompt_tokens + completion_tokens,
|
183
|
-
),
|
184
|
-
)
|
185
|
-
yield f"data: {chunk.model_dump_json()}\n\n"
|
186
|
-
except ValueError as e:
|
187
|
-
error = create_streaming_error_response(str(e))
|
188
|
-
yield f"data: {error}\n\n"
|
189
|
-
yield "data: [DONE]\n\n"
|
190
|
-
|
191
|
-
return StreamingResponse(
|
192
|
-
generate_stream_resp(),
|
193
|
-
media_type="text/event-stream",
|
194
|
-
background=tokenizer_manager.create_abort_task(adapted_request),
|
195
|
-
)
|
196
|
-
|
197
|
-
# Non-streaming response.
|
198
|
-
try:
|
199
|
-
ret = await tokenizer_manager.generate_request(
|
200
|
-
adapted_request, raw_request
|
201
|
-
).__anext__()
|
202
|
-
except ValueError as e:
|
203
|
-
return create_error_response(str(e))
|
204
|
-
|
205
|
-
ret = ret[0] if isinstance(ret, list) else ret
|
206
|
-
prompt_tokens = ret["meta_info"]["prompt_tokens"]
|
207
|
-
completion_tokens = ret["meta_info"]["completion_tokens"]
|
208
|
-
text = ret["text"]
|
209
|
-
if request.echo:
|
210
|
-
text = request.prompt + text
|
211
|
-
|
212
|
-
if request.logprobs:
|
213
|
-
if request.echo:
|
214
|
-
prefill_token_logprobs = ret["meta_info"]["prefill_token_logprobs"]
|
215
|
-
prefill_top_logprobs = ret["meta_info"]["prefill_top_logprobs"]
|
216
|
-
else:
|
217
|
-
prefill_token_logprobs = None
|
218
|
-
prefill_top_logprobs = None
|
219
|
-
|
220
|
-
logprobs = to_openai_style_logprobs(
|
221
|
-
prefill_token_logprobs=prefill_token_logprobs,
|
222
|
-
prefill_top_logprobs=prefill_top_logprobs,
|
223
|
-
decode_token_logprobs=ret["meta_info"]["decode_token_logprobs"],
|
224
|
-
decode_top_logprobs=ret["meta_info"]["decode_top_logprobs"],
|
225
|
-
)
|
226
|
-
else:
|
227
|
-
logprobs = None
|
228
|
-
|
229
|
-
choice_data = CompletionResponseChoice(
|
230
|
-
index=0,
|
231
|
-
text=text,
|
232
|
-
logprobs=logprobs,
|
233
|
-
finish_reason=ret["meta_info"]["finish_reason"],
|
234
|
-
)
|
235
|
-
response = CompletionResponse(
|
236
|
-
id=ret["meta_info"]["id"],
|
237
|
-
model=request.model,
|
238
|
-
choices=[choice_data],
|
239
|
-
usage=UsageInfo(
|
240
|
-
prompt_tokens=prompt_tokens,
|
241
|
-
completion_tokens=completion_tokens,
|
242
|
-
total_tokens=prompt_tokens + completion_tokens,
|
243
|
-
),
|
244
|
-
)
|
245
|
-
return response
|
246
|
-
|
247
|
-
|
248
|
-
async def v1_chat_completions(tokenizer_manager, raw_request: Request):
|
249
|
-
request_json = await raw_request.json()
|
250
|
-
request = ChatCompletionRequest(**request_json)
|
251
|
-
|
252
|
-
if request.n != 1:
|
253
|
-
return create_error_response("n != 1 is not supported")
|
254
|
-
|
255
|
-
# Prep the data needed for the underlying GenerateReqInput:
|
256
|
-
# - prompt: The full prompt string.
|
257
|
-
# - stop: Custom stop tokens.
|
258
|
-
# - image_data: None or a list of image strings (URLs or base64 strings).
|
259
|
-
# None skips any image processing in GenerateReqInput.
|
260
|
-
if not isinstance(request.messages, str):
|
261
|
-
# Apply chat template and its stop strings.
|
262
|
-
if chat_template_name is None:
|
263
|
-
prompt = tokenizer_manager.tokenizer.apply_chat_template(
|
264
|
-
request.messages, tokenize=False, add_generation_prompt=True
|
265
|
-
)
|
266
|
-
stop = request.stop
|
267
|
-
image_data = None
|
268
|
-
else:
|
269
|
-
conv = generate_chat_conv(request, chat_template_name)
|
270
|
-
prompt = conv.get_prompt()
|
271
|
-
image_data = conv.image_data
|
272
|
-
stop = conv.stop_str or []
|
273
|
-
if request.stop:
|
274
|
-
if isinstance(request.stop, str):
|
275
|
-
stop.append(request.stop)
|
276
|
-
else:
|
277
|
-
stop.extend(request.stop)
|
278
|
-
else:
|
279
|
-
# Use the raw prompt and stop strings if the messages is already a string.
|
280
|
-
prompt = request.messages
|
281
|
-
stop = request.stop
|
282
|
-
image_data = None
|
283
|
-
|
284
|
-
adapted_request = GenerateReqInput(
|
285
|
-
text=prompt,
|
286
|
-
image_data=image_data,
|
287
|
-
sampling_params={
|
288
|
-
"temperature": request.temperature,
|
289
|
-
"max_new_tokens": request.max_tokens,
|
290
|
-
"stop": stop,
|
291
|
-
"top_p": request.top_p,
|
292
|
-
"presence_penalty": request.presence_penalty,
|
293
|
-
"frequency_penalty": request.frequency_penalty,
|
294
|
-
"regex": request.regex,
|
295
|
-
},
|
296
|
-
stream=request.stream,
|
297
|
-
)
|
298
|
-
|
299
|
-
if adapted_request.stream:
|
300
|
-
|
301
|
-
async def generate_stream_resp():
|
302
|
-
is_first = True
|
303
|
-
|
304
|
-
stream_buffer = ""
|
305
|
-
try:
|
306
|
-
async for content in tokenizer_manager.generate_request(
|
307
|
-
adapted_request, raw_request
|
308
|
-
):
|
309
|
-
if is_first:
|
310
|
-
# First chunk with role
|
311
|
-
is_first = False
|
312
|
-
choice_data = ChatCompletionResponseStreamChoice(
|
313
|
-
index=0,
|
314
|
-
delta=DeltaMessage(role="assistant"),
|
315
|
-
finish_reason=content["meta_info"]["finish_reason"],
|
316
|
-
)
|
317
|
-
chunk = ChatCompletionStreamResponse(
|
318
|
-
id=content["meta_info"]["id"],
|
319
|
-
choices=[choice_data],
|
320
|
-
model=request.model,
|
321
|
-
)
|
322
|
-
yield f"data: {chunk.model_dump_json()}\n\n"
|
323
|
-
|
324
|
-
text = content["text"]
|
325
|
-
delta = text[len(stream_buffer) :]
|
326
|
-
stream_buffer = stream_buffer + delta
|
327
|
-
choice_data = ChatCompletionResponseStreamChoice(
|
328
|
-
index=0,
|
329
|
-
delta=DeltaMessage(content=delta),
|
330
|
-
finish_reason=content["meta_info"]["finish_reason"],
|
331
|
-
)
|
332
|
-
chunk = ChatCompletionStreamResponse(
|
333
|
-
id=content["meta_info"]["id"],
|
334
|
-
choices=[choice_data],
|
335
|
-
model=request.model,
|
336
|
-
)
|
337
|
-
yield f"data: {chunk.model_dump_json()}\n\n"
|
338
|
-
except ValueError as e:
|
339
|
-
error = create_streaming_error_response(str(e))
|
340
|
-
yield f"data: {error}\n\n"
|
341
|
-
yield "data: [DONE]\n\n"
|
342
|
-
|
343
|
-
return StreamingResponse(
|
344
|
-
generate_stream_resp(),
|
345
|
-
media_type="text/event-stream",
|
346
|
-
background=tokenizer_manager.create_abort_task(adapted_request),
|
347
|
-
)
|
348
|
-
|
349
|
-
# Non-streaming response.
|
350
|
-
try:
|
351
|
-
ret = await tokenizer_manager.generate_request(
|
352
|
-
adapted_request, raw_request
|
353
|
-
).__anext__()
|
354
|
-
except ValueError as e:
|
355
|
-
return create_error_response(str(e))
|
356
|
-
|
357
|
-
prompt_tokens = ret["meta_info"]["prompt_tokens"]
|
358
|
-
completion_tokens = ret["meta_info"]["completion_tokens"]
|
359
|
-
choice_data = ChatCompletionResponseChoice(
|
360
|
-
index=0,
|
361
|
-
message=ChatMessage(role="assistant", content=ret["text"]),
|
362
|
-
finish_reason=ret["meta_info"]["finish_reason"],
|
363
|
-
)
|
364
|
-
response = ChatCompletionResponse(
|
365
|
-
id=ret["meta_info"]["id"],
|
366
|
-
model=request.model,
|
367
|
-
choices=[choice_data],
|
368
|
-
usage=UsageInfo(
|
369
|
-
prompt_tokens=prompt_tokens,
|
370
|
-
completion_tokens=completion_tokens,
|
371
|
-
total_tokens=prompt_tokens + completion_tokens,
|
372
|
-
),
|
373
|
-
)
|
374
|
-
return response
|
375
|
-
|
376
|
-
|
377
|
-
def to_openai_style_logprobs(
|
378
|
-
prefill_token_logprobs=None,
|
379
|
-
decode_token_logprobs=None,
|
380
|
-
prefill_top_logprobs=None,
|
381
|
-
decode_top_logprobs=None,
|
382
|
-
):
|
383
|
-
ret_logprobs = LogProbs()
|
384
|
-
|
385
|
-
def append_token_logprobs(token_logprobs):
|
386
|
-
for logprob, _, token_text in token_logprobs:
|
387
|
-
ret_logprobs.tokens.append(token_text)
|
388
|
-
ret_logprobs.token_logprobs.append(logprob)
|
389
|
-
|
390
|
-
# Not supported yet
|
391
|
-
ret_logprobs.text_offset.append(-1)
|
392
|
-
|
393
|
-
def append_top_logprobs(top_logprobs):
|
394
|
-
for tokens in top_logprobs:
|
395
|
-
if tokens is not None:
|
396
|
-
ret_logprobs.top_logprobs.append(
|
397
|
-
{token[2]: token[0] for token in tokens}
|
398
|
-
)
|
399
|
-
else:
|
400
|
-
ret_logprobs.top_logprobs.append(None)
|
401
|
-
|
402
|
-
if prefill_token_logprobs is not None:
|
403
|
-
append_token_logprobs(prefill_token_logprobs)
|
404
|
-
if decode_token_logprobs is not None:
|
405
|
-
append_token_logprobs(decode_token_logprobs)
|
406
|
-
if prefill_top_logprobs is not None:
|
407
|
-
append_top_logprobs(prefill_top_logprobs)
|
408
|
-
if decode_top_logprobs is not None:
|
409
|
-
append_top_logprobs(decode_top_logprobs)
|
410
|
-
|
411
|
-
return ret_logprobs
|
sglang/srt/openai_protocol.py
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
"""Pydantic models for OpenAI API protocol"""
|
2
|
-
|
3
|
-
import time
|
4
|
-
from typing import Dict, List, Optional, Union
|
5
|
-
|
6
|
-
from pydantic import BaseModel, Field
|
7
|
-
from typing_extensions import Literal
|
8
|
-
|
9
|
-
|
10
|
-
class ModelCard(BaseModel):
|
11
|
-
"""Model cards."""
|
12
|
-
|
13
|
-
id: str
|
14
|
-
object: str = "model"
|
15
|
-
created: int = Field(default_factory=lambda: int(time.time()))
|
16
|
-
owned_by: str = "sglang"
|
17
|
-
root: Optional[str] = None
|
18
|
-
|
19
|
-
|
20
|
-
class ModelList(BaseModel):
|
21
|
-
"""Model list consists of model cards."""
|
22
|
-
|
23
|
-
object: str = "list"
|
24
|
-
data: List[ModelCard] = []
|
25
|
-
|
26
|
-
|
27
|
-
class ErrorResponse(BaseModel):
|
28
|
-
object: str = "error"
|
29
|
-
message: str
|
30
|
-
type: str
|
31
|
-
param: Optional[str] = None
|
32
|
-
code: int
|
33
|
-
|
34
|
-
|
35
|
-
class LogProbs(BaseModel):
|
36
|
-
text_offset: List[int] = Field(default_factory=list)
|
37
|
-
token_logprobs: List[Optional[float]] = Field(default_factory=list)
|
38
|
-
tokens: List[str] = Field(default_factory=list)
|
39
|
-
top_logprobs: List[Optional[Dict[str, float]]] = Field(default_factory=list)
|
40
|
-
|
41
|
-
|
42
|
-
class UsageInfo(BaseModel):
|
43
|
-
prompt_tokens: int = 0
|
44
|
-
total_tokens: int = 0
|
45
|
-
completion_tokens: Optional[int] = 0
|
46
|
-
|
47
|
-
|
48
|
-
class CompletionRequest(BaseModel):
|
49
|
-
# Ordered by official OpenAI API documentation
|
50
|
-
# https://platform.openai.com/docs/api-reference/completions/create
|
51
|
-
model: str
|
52
|
-
prompt: Union[List[int], List[List[int]], str, List[str]]
|
53
|
-
best_of: Optional[int] = None
|
54
|
-
echo: Optional[bool] = False
|
55
|
-
frequency_penalty: Optional[float] = 0.0
|
56
|
-
logit_bias: Optional[Dict[str, float]] = None
|
57
|
-
logprobs: Optional[int] = None
|
58
|
-
max_tokens: Optional[int] = 16
|
59
|
-
n: int = 1
|
60
|
-
presence_penalty: Optional[float] = 0.0
|
61
|
-
seed: Optional[int] = None
|
62
|
-
stop: Optional[Union[str, List[str]]] = Field(default_factory=list)
|
63
|
-
stream: Optional[bool] = False
|
64
|
-
suffix: Optional[str] = None
|
65
|
-
temperature: Optional[float] = 1.0
|
66
|
-
top_p: Optional[float] = 1.0
|
67
|
-
user: Optional[str] = None
|
68
|
-
|
69
|
-
# Extra parameters for SRT backend only and will be ignored by OpenAI models.
|
70
|
-
regex: Optional[str] = None
|
71
|
-
|
72
|
-
|
73
|
-
class CompletionResponseChoice(BaseModel):
|
74
|
-
index: int
|
75
|
-
text: str
|
76
|
-
logprobs: Optional[LogProbs] = None
|
77
|
-
finish_reason: Optional[str] = None
|
78
|
-
|
79
|
-
|
80
|
-
class CompletionResponse(BaseModel):
|
81
|
-
id: str
|
82
|
-
object: str = "text_completion"
|
83
|
-
created: int = Field(default_factory=lambda: int(time.time()))
|
84
|
-
model: str
|
85
|
-
choices: List[CompletionResponseChoice]
|
86
|
-
usage: UsageInfo
|
87
|
-
|
88
|
-
|
89
|
-
class CompletionResponseStreamChoice(BaseModel):
|
90
|
-
index: int
|
91
|
-
text: str
|
92
|
-
logprobs: Optional[LogProbs] = None
|
93
|
-
finish_reason: Optional[str] = None
|
94
|
-
|
95
|
-
|
96
|
-
class CompletionStreamResponse(BaseModel):
|
97
|
-
id: str
|
98
|
-
object: str = "text_completion"
|
99
|
-
created: int = Field(default_factory=lambda: int(time.time()))
|
100
|
-
model: str
|
101
|
-
choices: List[CompletionResponseStreamChoice]
|
102
|
-
usage: UsageInfo
|
103
|
-
|
104
|
-
|
105
|
-
class ChatCompletionMessageGenericParam(BaseModel):
|
106
|
-
role: Literal["system", "assistant"]
|
107
|
-
content: str
|
108
|
-
|
109
|
-
|
110
|
-
class ChatCompletionMessageContentTextPart(BaseModel):
|
111
|
-
type: Literal["text"]
|
112
|
-
text: str
|
113
|
-
|
114
|
-
|
115
|
-
class ChatCompletionMessageContentImageURL(BaseModel):
|
116
|
-
url: str
|
117
|
-
detail: Optional[Literal["auto", "low", "high"]] = "auto"
|
118
|
-
|
119
|
-
|
120
|
-
class ChatCompletionMessageContentImagePart(BaseModel):
|
121
|
-
type: Literal["image_url"]
|
122
|
-
image_url: ChatCompletionMessageContentImageURL
|
123
|
-
|
124
|
-
|
125
|
-
ChatCompletionMessageContentPart = Union[
|
126
|
-
ChatCompletionMessageContentTextPart, ChatCompletionMessageContentImagePart
|
127
|
-
]
|
128
|
-
|
129
|
-
|
130
|
-
class ChatCompletionMessageUserParam(BaseModel):
|
131
|
-
role: Literal["user"]
|
132
|
-
content: Union[str, List[ChatCompletionMessageContentPart]]
|
133
|
-
|
134
|
-
|
135
|
-
ChatCompletionMessageParam = Union[
|
136
|
-
ChatCompletionMessageGenericParam, ChatCompletionMessageUserParam
|
137
|
-
]
|
138
|
-
|
139
|
-
|
140
|
-
class ResponseFormat(BaseModel):
|
141
|
-
# type must be "json_object" or "text"
|
142
|
-
type: Literal["text", "json_object"]
|
143
|
-
|
144
|
-
|
145
|
-
class ChatCompletionRequest(BaseModel):
|
146
|
-
# Ordered by official OpenAI API documentation
|
147
|
-
# https://platform.openai.com/docs/api-reference/chat/create
|
148
|
-
messages: List[ChatCompletionMessageParam]
|
149
|
-
model: str
|
150
|
-
frequency_penalty: Optional[float] = 0.0
|
151
|
-
logit_bias: Optional[Dict[str, float]] = None
|
152
|
-
logprobs: Optional[bool] = False
|
153
|
-
top_logprobs: Optional[int] = None
|
154
|
-
max_tokens: Optional[int] = 16
|
155
|
-
n: Optional[int] = 1
|
156
|
-
presence_penalty: Optional[float] = 0.0
|
157
|
-
response_format: Optional[ResponseFormat] = None
|
158
|
-
seed: Optional[int] = None
|
159
|
-
stop: Optional[Union[str, List[str]]] = Field(default_factory=list)
|
160
|
-
stream: Optional[bool] = False
|
161
|
-
temperature: Optional[float] = 0.7
|
162
|
-
top_p: Optional[float] = 1.0
|
163
|
-
user: Optional[str] = None
|
164
|
-
|
165
|
-
# Extra parameters for SRT backend only and will be ignored by OpenAI models.
|
166
|
-
regex: Optional[str] = None
|
167
|
-
|
168
|
-
|
169
|
-
class ChatMessage(BaseModel):
|
170
|
-
role: Optional[str] = None
|
171
|
-
content: Optional[str] = None
|
172
|
-
|
173
|
-
|
174
|
-
class ChatCompletionResponseChoice(BaseModel):
|
175
|
-
index: int
|
176
|
-
message: ChatMessage
|
177
|
-
logprobs: Optional[LogProbs] = None
|
178
|
-
finish_reason: Optional[str] = None
|
179
|
-
|
180
|
-
|
181
|
-
class ChatCompletionResponse(BaseModel):
|
182
|
-
id: str
|
183
|
-
object: str = "chat.completion"
|
184
|
-
created: int = Field(default_factory=lambda: int(time.time()))
|
185
|
-
model: str
|
186
|
-
choices: List[ChatCompletionResponseChoice]
|
187
|
-
usage: UsageInfo
|
188
|
-
|
189
|
-
|
190
|
-
class DeltaMessage(BaseModel):
|
191
|
-
role: Optional[str] = None
|
192
|
-
content: Optional[str] = None
|
193
|
-
|
194
|
-
|
195
|
-
class ChatCompletionResponseStreamChoice(BaseModel):
|
196
|
-
index: int
|
197
|
-
delta: DeltaMessage
|
198
|
-
logprobs: Optional[LogProbs] = None
|
199
|
-
finish_reason: Optional[str] = None
|
200
|
-
|
201
|
-
|
202
|
-
class ChatCompletionStreamResponse(BaseModel):
|
203
|
-
id: str
|
204
|
-
object: str = "chat.completion.chunk"
|
205
|
-
created: int = Field(default_factory=lambda: int(time.time()))
|
206
|
-
model: str
|
207
|
-
choices: List[ChatCompletionResponseStreamChoice]
|
File without changes
|
File without changes
|
File without changes
|