@ai-sdk/openai-compatible
Advanced tools
Comparing version 0.0.7 to 0.0.8
# @ai-sdk/openai-compatible | ||
## 0.0.8 | ||
### Patch Changes | ||
- 6faab13: feat (provider/openai-compatible): simulated streaming setting | ||
## 0.0.7 | ||
@@ -4,0 +10,0 @@ |
@@ -12,2 +12,9 @@ import { ProviderV1, LanguageModelV1, EmbeddingModelV1, LanguageModelV1ObjectGenerationMode } from '@ai-sdk/provider'; | ||
user?: string; | ||
/** | ||
Simulates streaming by using a normal generate call and returning it as a stream. | ||
Enable this if the model that you are using does not support streaming. | ||
Defaults to `false`. | ||
*/ | ||
simulateStreaming?: boolean; | ||
} | ||
@@ -14,0 +21,0 @@ |
@@ -415,2 +415,38 @@ "use strict"; | ||
async doStream(options) { | ||
if (this.settings.simulateStreaming) { | ||
const result = await this.doGenerate(options); | ||
const simulatedStream = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue({ type: "response-metadata", ...result.response }); | ||
if (result.text) { | ||
controller.enqueue({ | ||
type: "text-delta", | ||
textDelta: result.text | ||
}); | ||
} | ||
if (result.toolCalls) { | ||
for (const toolCall of result.toolCalls) { | ||
controller.enqueue({ | ||
type: "tool-call", | ||
...toolCall | ||
}); | ||
} | ||
} | ||
controller.enqueue({ | ||
type: "finish", | ||
finishReason: result.finishReason, | ||
usage: result.usage, | ||
logprobs: result.logprobs, | ||
providerMetadata: result.providerMetadata | ||
}); | ||
controller.close(); | ||
} | ||
}); | ||
return { | ||
stream: simulatedStream, | ||
rawCall: result.rawCall, | ||
rawResponse: result.rawResponse, | ||
warnings: result.warnings | ||
}; | ||
} | ||
const { args, warnings } = this.getArgs({ ...options }); | ||
@@ -417,0 +453,0 @@ const body = JSON.stringify({ ...args, stream: true }); |
{ | ||
"name": "@ai-sdk/openai-compatible", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
242995
2449