@@ -48,6 +48,32 @@ class ToolChoice(BaseModel):
4848 type : Literal ["function" ] = Field (default = "function" , examples = ["function" ])
4949
5050
51+ class CompletionRequest (BaseModel ):
52+ model : str
53+ # prompt: string or tokens
54+ prompt : Union [str , List [str ], List [int ], List [List [int ]]]
55+ suffix : Optional [str ] = None
56+ max_tokens : Optional [int ] = 16
57+ temperature : Optional [float ] = 1.0
58+ top_p : Optional [float ] = 1.0
59+ n : Optional [int ] = 1
60+ stream : Optional [bool ] = False
61+ logprobs : Optional [int ] = None
62+ echo : Optional [bool ] = False
63+ stop : Optional [Union [str , List [str ]]] = None
64+ presence_penalty : Optional [float ] = 0.0
65+ frequency_penalty : Optional [float ] = 0.0
66+ best_of : Optional [int ] = 1
67+ logit_bias : Optional [Dict [str , float ]] = None
68+ user : Optional [str ] = None
69+
70+ # Additional parameters supported by LightLLM
71+ do_sample : Optional [bool ] = False
72+ top_k : Optional [int ] = - 1
73+ repetition_penalty : Optional [float ] = 1.0
74+ ignore_eos : Optional [bool ] = False
75+
76+
5177class ChatCompletionRequest (BaseModel ):
5278 model : str
5379 messages : List [Message ]
@@ -148,3 +174,49 @@ class ChatCompletionStreamResponse(BaseModel):
148174 @field_validator ("id" , mode = "before" )
149175 def ensure_id_is_str (cls , v ):
150176 return str (v )
177+
178+
179+ class CompletionLogprobs (BaseModel ):
180+ tokens : List [str ] = []
181+ token_logprobs : List [Optional [float ]] = []
182+ top_logprobs : List [Optional [Dict [str , float ]]] = []
183+ text_offset : List [int ] = []
184+
185+
186+ class CompletionChoice (BaseModel ):
187+ text : str
188+ index : int
189+ logprobs : Optional ["CompletionLogprobs" ] = None
190+ finish_reason : Optional [Literal ["stop" , "length" ]] = None
191+
192+
193+ class CompletionResponse (BaseModel ):
194+ id : str = Field (default_factory = lambda : f"cmpl-{ uuid .uuid4 ().hex } " )
195+ object : str = "text_completion"
196+ created : int = Field (default_factory = lambda : int (time .time ()))
197+ model : str
198+ choices : List [CompletionChoice ]
199+ usage : UsageInfo
200+
201+ @field_validator ("id" , mode = "before" )
202+ def ensure_id_is_str (cls , v ):
203+ return str (v )
204+
205+
206+ class CompletionStreamChoice (BaseModel ):
207+ text : str
208+ index : int
209+ logprobs : Optional [Dict ] = None
210+ finish_reason : Optional [Literal ["stop" , "length" ]] = None
211+
212+
213+ class CompletionStreamResponse (BaseModel ):
214+ id : str = Field (default_factory = lambda : f"cmpl-{ uuid .uuid4 ().hex } " )
215+ object : str = "text_completion"
216+ created : int = Field (default_factory = lambda : int (time .time ()))
217+ model : str
218+ choices : List [CompletionStreamChoice ]
219+
220+ @field_validator ("id" , mode = "before" )
221+ def ensure_id_is_str (cls , v ):
222+ return str (v )
0 commit comments