From bb0501c0d96cc9531dc8885dec8d5e701156010d Mon Sep 17 00:00:00 2001 From: yichuan~ <73766326+yichuan520030910320@users.noreply.github.com> Date: Wed, 31 Jul 2024 04:40:51 +0800 Subject: [PATCH] Fix List input bug (#838) --- examples/usage/openai_batch_chat.py | 10 ++++++++++ examples/usage/openai_batch_complete.py | 11 +++++++++++ examples/usage/openai_parallel_sample.py | 20 ++++++++++++++++++-- python/sglang/srt/openai_api/adapter.py | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/examples/usage/openai_batch_chat.py b/examples/usage/openai_batch_chat.py index cffa50c67..8640d0925 100644 --- a/examples/usage/openai_batch_chat.py +++ b/examples/usage/openai_batch_chat.py @@ -1,3 +1,13 @@ +""" +Usage: +python -m sglang.launch_server --model-path meta-llama/Llama-2-7b-chat-hf --port 30000 +python openai_batch_chat.py +Note: Before running this script, +you should create the input.jsonl file with the following content: +{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo-0125", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world! List 3 NBA players and tell a story"}],"max_tokens": 300}} +{"custom_id": "request-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo-0125", "messages": [{"role": "system", "content": "You are an assistant. "},{"role": "user", "content": "Hello world! List three capital and tell a story"}],"max_tokens": 500}} +""" + import json import os import time diff --git a/examples/usage/openai_batch_complete.py b/examples/usage/openai_batch_complete.py index 3cf2ede0b..af694b54a 100644 --- a/examples/usage/openai_batch_complete.py +++ b/examples/usage/openai_batch_complete.py @@ -1,3 +1,14 @@ +""" +Usage: +python -m sglang.launch_server --model-path meta-llama/Llama-2-7b-chat-hf --port 30000 +python openai_batch_complete.py +Note: Before running this script, +you should create the input.jsonl file with the following content: +{"custom_id": "request-1", "method": "POST", "url": "/v1/completions", "body": {"model": "gpt-3.5-turbo-instruct", "prompt": "List 3 names of famous soccer player: ", "max_tokens": 200}} +{"custom_id": "request-2", "method": "POST", "url": "/v1/completions", "body": {"model": "gpt-3.5-turbo-instruct", "prompt": "List 6 names of famous basketball player: ", "max_tokens": 400}} +{"custom_id": "request-3", "method": "POST", "url": "/v1/completions", "body": {"model": "gpt-3.5-turbo-instruct", "prompt": "List 6 names of famous basketball player: ", "max_tokens": 400}} +""" + import json import os import time diff --git a/examples/usage/openai_parallel_sample.py b/examples/usage/openai_parallel_sample.py index 0d3a372b4..99ec0aa58 100644 --- a/examples/usage/openai_parallel_sample.py +++ b/examples/usage/openai_parallel_sample.py @@ -17,9 +17,9 @@ print(response) response = client.completions.create( model="default", prompt="I am a robot and I want to study like humans. Now let's tell a story. Once upon a time, there was a little", - n=1, + n=5, temperature=0.8, - max_tokens=32, + max_tokens=320, ) print(response) @@ -68,6 +68,22 @@ response = client.completions.create( print(response) +response = client.completions.create( + model="default", + prompt=[ + "prompt1: I am a robot and I want to learn like humans. Now let's begin a tale. Once upon a time, there was a small", + "prompt2: As a robot, my goal is to understand human learning. Let's start a story. In a faraway land, there lived a tiny", + "prompt3: Being a robot, I aspire to study like people. Let's share a story. Long ago, there was a little", + "prompt4: I am a robot aiming to learn like humans. Let's narrate a story. Once, in a distant kingdom, there was a young", + "prompt5: As a robot, I seek to learn in human ways. Let's tell a story. Once upon a time, in a small village, there was a young", + ], + n=1, + temperature=0.8, + max_tokens=320, +) +print(response) + + # Text completion response = client.completions.create( model="default", diff --git a/python/sglang/srt/openai_api/adapter.py b/python/sglang/srt/openai_api/adapter.py index 5fa75f1b8..21f38cd22 100644 --- a/python/sglang/srt/openai_api/adapter.py +++ b/python/sglang/srt/openai_api/adapter.py @@ -361,7 +361,7 @@ def v1_generate_request(all_requests): if len(all_requests) == 1: prompt = prompts[0] sampling_params_list = sampling_params_list[0] - if isinstance(prompts, str) or isinstance(prompts[0], str): + if isinstance(prompt, str) or isinstance(prompt[0], str): prompt_kwargs = {"text": prompt} else: prompt_kwargs = {"input_ids": prompt}