OpenAI compat API adapter#466
Conversation
|
This is a great idea although I would probably simplify the syntax a bit into a single object. Is there any other project that does this currently? If theres an establish spec I could follow it. |
|
Without any other spec, what about something like: "adapter": { With any missing or null field replaced with the default value for it. What's a good use case for after_last_mes? Seems like it would break most bot responses |
|
@LostRuins thanks, I've implemented preliminary support in my lib OpenAiNg, however the format can be changed, I'm open to the one you've proposed. As for |
|
I see. I think the |
|
Hi @lofcz please take a look, I have simplified the API as mentioned, let me know if it works adequately with your frontend (try both with and without the adapter to see if everything is ok) |
|
@LostRuins thanks for the edit, I've tried it both with and without and it works great. I'd share a video but my frontend is not in English so it wouldn't be legible for most. |
|
okay then looks good to me. will merge this :) cheers |
|
thanks! |
|
Nice addition lofcz and LostRuins!!! Very cool. |
|
What is the final format expected? |
|
As shown above. Just add the adapter to the regular json request body. |
The current OpenAI-like API uses hardcoded chat templates. This PR implements a non-breaking adapter users can exploit to use models requiring various chat templates. Testing request against Mistral7B Dolphin:
{ "temperature": 0.5, "max_tokens": 1024, "messages": [ { "role": "system", "content": "You roleplay as a dungeon master engaged in a session of Dungeons and Dragons with the user. Write in an immersive way to avoid spoiling the user's experience." }, { "role": "user", "content": "I am a kobold named Nico, what should I do?" } ], "adapter": { "templates": { "system": { "start": "<|im_start|>system\n", "end": "<|im_end|>\n" }, "user": { "start": "<|im_start|>user\n", "end": "<|im_end|>\n" }, "assistent": { "start": "", "end": "" }, "after_last_message": "" } } }This PR proposes the following non-breaking addition to
/v1/chat/completionsendpoint:If users omit the
adapterobject in the request, we fall back to the default Vicuna-style template.Response with this patch:

Response with stock 1.46.1 build:
