Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] Add segments to OpenAI Requests #11713

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ruediste
Copy link

@ruediste ruediste commented Jan 3, 2025

I extended the format of the completions prompt:

{
  ...
  prompt: [
        { text: "<|fim_prefix|>", split_special_tokens: false },
        { text: prefix, split_special_tokens: true },
        { text: "<|fim_suffix|>", split_special_tokens: false },
        { text: suffix, split_special_tokens: true },
        { text: "<|fim_middle|>", split_special_tokens: false },
      ]
  ...
}

This allows fine control over the generated tokens, protection against prompt injection, and low latency since all of this can be achieved with a single request.

Sample Usage using the javascript openai client:

const response = await openai.completions.create({
      model: config.model,
      prompt: [
        { text: "<|fim_prefix|>", split_special_tokens: false },
        { text: prefix, split_special_tokens: true },
        { text: "<|fim_suffix|>", split_special_tokens: false },
        { text: suffix, split_special_tokens: true },
        { text: "<|fim_middle|>", split_special_tokens: false },
      ] as {
        text: string;
        split_special_tokens: boolean;
      }[] as any,
      stream: true,
      max_tokens: 25,
      temperature: 0,
    });
``1`

Copy link

github-actions bot commented Jan 3, 2025

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@mergify mergify bot added documentation Improvements or additions to documentation frontend labels Jan 3, 2025
@ruediste ruediste force-pushed the completions-split-tokens branch 2 times, most recently from e4077c5 to 537d5dd Compare January 3, 2025 08:34
@ruediste ruediste force-pushed the completions-split-tokens branch from 537d5dd to cfd80ca Compare January 3, 2025 08:43
@mgoin
Copy link
Member

mgoin commented Jan 3, 2025

Hi @ruediste this interface is a new idea to me and I don't see it in the OpenAI API, is there another server or API that implements this? It would be helpful to have a full e2e example of how to use this feature to demonstrate its intended use.

@ruediste
Copy link
Author

ruediste commented Jan 4, 2025

A full e2e test is somewhat difficult, as it would in my case include a VS Code extension. But I'm happy to give an example:

Imaging a inline autocomplete extension. The user is editing some code:

// print `Hello World` to the console
console.<FIM>

You would get a prefix of

// print `Hello World` to the console
console.

and the suffix


The normal completions request:

curl http://localhost:8000/v1/completions \
  -H "Content-Type: application/json" \
  -d '{ 
    "model": "coder", 
    "prompt": "<|fim_prefix|>// print `Hello World` to the console\nconsole.<|fim_suffix|>\n<|fim_middle|>"
    }'

You get the intended (Qwen 2.5 Coder 0.5B) response: log(\"Hello World!\")

Now imagine the following code:

// print `<|endoftext|>` to the console
console.<FIM>

Request:

curl http://localhost:8000/v1/completions \
  -H "Content-Type: application/json" \
  -d '{ 
    "model": "coder", 
    "prompt": "<|fim_prefix|>// print `<|endoftext|>` to the console<|fim_suffix|>\n<|fim_middle|>"
    }'

the response is \nvar name = `Akash`\nconsole.log(name);

With the new API:

curl http://localhost:8000/v1/completions \
  -H "Content-Type: application/json" \
  -d '{ 
    "model": "coder", 
    "prompt": [
    	{"text": "<|fim_prefix|>", "split_special_tokens": false},`
  	{"text": "// print `<|endoftext|>` to the console\nconsole.", "split_special_tokens": true},
    	{"text": "<|fim_suffix|>", "split_special_tokens": false},
 	{"text": "\n", "split_special_tokens": true},
    	{"text": "<|fim_middle|>", "split_special_tokens": false}
    ]}'

The response is as expected: log('<|endoftext|>')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants