Merge PR #596: Add supportsUsageInStreaming compat flag
|
|
@ -5,6 +5,7 @@
|
|||
### Added
|
||||
|
||||
- Added `GOOGLE_APPLICATION_CREDENTIALS` env var support for Vertex AI credential detection (standard for CI/production).
|
||||
- Added `supportsUsageInStreaming` compatibility flag for OpenAI-compatible providers that reject `stream_options: { include_usage: true }`. Defaults to `true`. Set to `false` in model config for providers like gatewayz.ai. ([#596](https://github.com/badlogic/pi-mono/pull/596) by [@XesGaDeus](https://github.com/XesGaDeus))
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
|||
|
|
@ -370,9 +370,12 @@ function buildParams(model: Model<"openai-completions">, context: Context, optio
|
|||
model: model.id,
|
||||
messages,
|
||||
stream: true,
|
||||
stream_options: { include_usage: true },
|
||||
};
|
||||
|
||||
if (compat.supportsUsageInStreaming !== false) {
|
||||
(params as any).stream_options = { include_usage: true };
|
||||
}
|
||||
|
||||
if (compat.supportsStore) {
|
||||
params.store = false;
|
||||
}
|
||||
|
|
@ -657,6 +660,7 @@ function detectCompatFromUrl(baseUrl: string): Required<OpenAICompat> {
|
|||
supportsStore: !isNonStandard,
|
||||
supportsDeveloperRole: !isNonStandard,
|
||||
supportsReasoningEffort: !isGrok,
|
||||
supportsUsageInStreaming: true,
|
||||
maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
|
||||
requiresToolResultName: isMistral,
|
||||
requiresAssistantAfterToolResult: false, // Mistral no longer requires this as of Dec 2024
|
||||
|
|
@ -677,6 +681,7 @@ function getCompat(model: Model<"openai-completions">): Required<OpenAICompat> {
|
|||
supportsStore: model.compat.supportsStore ?? detected.supportsStore,
|
||||
supportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,
|
||||
supportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,
|
||||
supportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
|
||||
maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
|
||||
requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
|
||||
requiresAssistantAfterToolResult:
|
||||
|
|
|
|||
|
|
@ -207,6 +207,8 @@ export interface OpenAICompat {
|
|||
supportsDeveloperRole?: boolean;
|
||||
/** Whether the provider supports `reasoning_effort`. Default: auto-detected from URL. */
|
||||
supportsReasoningEffort?: boolean;
|
||||
/** Whether the provider supports `stream_options: { include_usage: true }` for token usage in streaming responses. Default: true. */
|
||||
supportsUsageInStreaming?: boolean;
|
||||
/** Which field to use for max tokens. Default: auto-detected from URL. */
|
||||
maxTokensField?: "max_completion_tokens" | "max_tokens";
|
||||
/** Whether tool results require the `name` field. Default: auto-detected from URL. */
|
||||
|
|
|
|||
BIN
packages/ai/test/.temp-images/dim-1000.png
Normal file
|
After Width: | Height: | Size: 446 B |
BIN
packages/ai/test/.temp-images/dim-10000.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
packages/ai/test/.temp-images/dim-2000.png
Normal file
|
After Width: | Height: | Size: 810 B |
BIN
packages/ai/test/.temp-images/dim-4000.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
packages/ai/test/.temp-images/dim-6000.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
packages/ai/test/.temp-images/dim-8000.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 1 MiB After Width: | Height: | Size: 1 MiB |
|
Before Width: | Height: | Size: 2 MiB After Width: | Height: | Size: 2 MiB |
BIN
packages/ai/test/.temp-images/size-3mb.png
Normal file
|
After Width: | Height: | Size: 3 MiB |
BIN
packages/ai/test/.temp-images/size-4mb.png
Normal file
|
After Width: | Height: | Size: 4 MiB |
|
Before Width: | Height: | Size: 321 B After Width: | Height: | Size: 321 B |