File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -855,6 +855,12 @@ class CompletionRequest(OpenAIBaseModel):
855
855
" as strings of the form 'token_id:{token_id}' so that tokens "
856
856
"that are not JSON-encodable can be identified." ))
857
857
858
+ accumulate : Optional [bool ] = Field (
859
+ default = None ,
860
+ description = (
861
+ "Special kind of echo where in the response instead of delta we return the accumulated text"
862
+ )
863
+ )
858
864
# doc: end-completion-extra-params
859
865
860
866
# Default sampling parameters for completion requests
Original file line number Diff line number Diff line change @@ -262,6 +262,9 @@ async def completion_stream_generator(
262
262
previous_num_tokens = [0 ] * num_choices * num_prompts
263
263
has_echoed = [False ] * num_choices * num_prompts
264
264
num_prompt_tokens = [0 ] * num_prompts
265
+ accumulated_text = ["" ] * num_choices * num_prompts
266
+ accumulated_tokens = [[] * num_choices * num_prompts ]
267
+ accumulated_logprobs = [[] * num_choices * num_prompts ]
265
268
266
269
stream_options = request .stream_options
267
270
if stream_options :
@@ -309,6 +312,16 @@ async def completion_stream_generator(
309
312
* (output .logprobs or []),
310
313
]
311
314
has_echoed [i ] = True
315
+ elif request .accumulate :
316
+ i = output .index + prompt_idx * num_choices
317
+ # return the accumulated response
318
+ accumulated_text [i ] += output .text
319
+ accumulated_tokens [i ].extend (output .token_ids )
320
+ accumulated_logprobs [i ].extend (output .logprobs or [])
321
+
322
+ delta_text = accumulated_text [i ]
323
+ delta_token_ids = accumulated_tokens [i ]
324
+ out_logprobs = accumulated_logprobs [i ]
312
325
else :
313
326
# return just the delta
314
327
delta_text = output .text
You can’t perform that action at this time.
0 commit comments