Fix echo + lobprob for OpenAI API when the prompt is a list (#791)
This commit is contained in:
@@ -223,13 +223,19 @@ async def v1_completions(tokenizer_manager, raw_request: Request):
|
|||||||
|
|
||||||
if not isinstance(ret, list):
|
if not isinstance(ret, list):
|
||||||
ret = [ret]
|
ret = [ret]
|
||||||
|
if request.echo:
|
||||||
|
# TODO: handle the case propmt is token ids
|
||||||
|
if isinstance(request.prompt, list):
|
||||||
|
prompts = request.prompt
|
||||||
|
else:
|
||||||
|
prompts = [request.prompt]
|
||||||
choices = []
|
choices = []
|
||||||
|
|
||||||
for idx, ret_item in enumerate(ret):
|
for idx, ret_item in enumerate(ret):
|
||||||
text = ret_item["text"]
|
text = ret_item["text"]
|
||||||
|
|
||||||
if request.echo:
|
if request.echo:
|
||||||
text = request.prompt + text
|
text = prompts[idx] + text
|
||||||
|
|
||||||
if request.logprobs:
|
if request.logprobs:
|
||||||
if request.echo:
|
if request.echo:
|
||||||
@@ -257,17 +263,15 @@ async def v1_completions(tokenizer_manager, raw_request: Request):
|
|||||||
|
|
||||||
choices.append(choice_data)
|
choices.append(choice_data)
|
||||||
|
|
||||||
|
completion_tokens = sum(item["meta_info"]["completion_tokens"] for item in ret)
|
||||||
response = CompletionResponse(
|
response = CompletionResponse(
|
||||||
id=ret[0]["meta_info"]["id"],
|
id=ret[0]["meta_info"]["id"],
|
||||||
model=request.model,
|
model=request.model,
|
||||||
choices=choices,
|
choices=choices,
|
||||||
usage=UsageInfo(
|
usage=UsageInfo(
|
||||||
prompt_tokens=ret[0]["meta_info"]["prompt_tokens"],
|
prompt_tokens=ret[0]["meta_info"]["prompt_tokens"],
|
||||||
completion_tokens=sum(
|
completion_tokens=completion_tokens,
|
||||||
item["meta_info"]["completion_tokens"] for item in ret
|
total_tokens=ret[0]["meta_info"]["prompt_tokens"] + completion_tokens,
|
||||||
),
|
|
||||||
total_tokens=ret[0]["meta_info"]["prompt_tokens"]
|
|
||||||
+ sum(item["meta_info"]["completion_tokens"] for item in ret),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user