OpenAI-Compatible Provider
OpenAI-Compatible Provider Plugin (plugins/providers/openai/python/openai_provider.py)
Minimal provider for OpenAI-compatible Chat Completions endpoints (e.g., Ollama at /v1). Loads configuration only from the provided config dict (no environment variable usage).
OpenAICompatibleProvider
OpenAICompatibleProvider()
Bases: ProviderPlugin
Source code in plugins/openai_provider.py
53 54 55 | |
extract_delta
extract_delta(native_chunk)
Extract a provider-native delta dictionary from a streaming chunk.
Returns the first choice object when present, or an empty dict.
Source code in plugins/openai_provider.py
433 434 435 436 437 438 439 440 441 | |
finalize
finalize(native_messages, state)
Finalize streaming by emitting the accumulator as a final.
When streaming was used, state["accumulator"] holds the merged assistant
message (content, role, reasoning, tool_calls, etc.) built up across
chunks by the provider and any extensions. Non-streaming calls leave it
as None.
Source code in plugins/openai_provider.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
from_native_messages
from_native_messages(native_messages, state)
Convert provider-native finals to core messages.
This provider-level conversion intentionally ignores any provider-specific reasoning fields. Reasoning content should be surfaced by dedicated extensions (e.g., thinking extensions) via message metadata rather than as a top-level field.
Source code in plugins/openai_provider.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
get_models
get_models(config)
Return minimal model descriptors for this provider.
Currently returns the configured model (if any) as a single
ModelDescriptor with only an id field.
Source code in plugins/openai_provider.py
107 108 109 110 111 112 113 114 115 116 | |
get_tags
get_tags(config, models)
Return capability tags for the OpenAI-compatible provider.
This implementation is intentionally simple and conservative; it assumes chat-completions style models with tool calling and streaming support.
Source code in plugins/openai_provider.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
process_chunk
process_chunk(native_chunk, native_messages, state)
Process a streaming chunk into provider-native partials.
Pattern:
- Extract a delta from the chunk
- Reduce it into a partial fragment and update the accumulator
- Do not emit finals or modify history; :meth:finalize is responsible
for producing the final message from the accumulator.
Source code in plugins/openai_provider.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
process_delta
process_delta(delta, accumulated)
Reduce a delta dict into a new partial and accumulator.
Returns the current partial fragment from this chunk and an updated
accumulator used later by :meth:finalize to build the final message.
Source code in plugins/openai_provider.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |