Skip to content

Conversation

@aimbit-ni
Copy link

Summary

  • Adds an api_format config option to the OpenAI driver (default: responses, alternative: chat_completions)
  • Enables using Prism with OpenAI-compatible backends (vLLM, LiteLLM, LocalAI) that only implement /chat/completions
  • Only text(), structured(), and stream() dispatch conditionally — other modalities (embeddings, images, moderation, TTS, STT) already use standard endpoints that work as-is

Usage

// config/prism.php or .env
OPENAI_API_FORMAT=chat_completions
OPENAI_URL=http://your-vllm-proxy:8000/v1

New files

  • Handlers/ChatCompletions/Text.php, Structured.php, Stream.php — chat/completions protocol handlers
  • Maps/ChatCompletionsMessageMap.php — standard message format (text type, flat assistant content)
  • Maps/ChatCompletionsFinishReasonMap.php — maps stop/tool_calls/length
  • Maps/ChatCompletionsToolMap.php, ChatCompletionsToolChoiceMap.php — nested function key format
  • Maps/ChatCompletionsImageMapper.phpimage_url format

Refs #900

Test plan

  • 11 new tests covering text, structured, and streaming via chat/completions
  • All existing tests still pass (1361 total, 0 failures)
  • PHPStan level 8 clean
  • Pint + Rector formatted
  • Manual: set OPENAI_API_FORMAT=chat_completions with a LiteLLM/vLLM proxy

StreamEndEvent.usage can be null when providers don't include usage
data in their final stream chunk, causing a TypeError downstream.
Add `?? new Usage(0, 0)` fallback to emitStreamEndEvent() in all
providers missing it, matching the existing pattern in the OpenAI
stream handler.
Add an `api_format` config option to the OpenAI driver that allows
switching from the default `/responses` endpoint to `/chat/completions`.
This enables using Prism with OpenAI-compatible backends like vLLM,
LiteLLM, and LocalAI that only implement the chat/completions API.

Set `OPENAI_API_FORMAT=chat_completions` in your env to use it. Only
text, structured, and stream methods dispatch conditionally — other
modalities (embeddings, images, moderation, TTS, STT) already use
standard endpoints that work with compatible backends as-is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant