modelfusion 0.104.0 → 0.106.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/README.md +8 -10
- package/core/DefaultRun.cjs +0 -4
- package/core/DefaultRun.d.ts +0 -2
- package/core/DefaultRun.js +0 -4
- package/core/ExtensionFunctionEvent.d.ts +11 -0
- package/core/FunctionEvent.d.ts +2 -2
- package/extension/index.cjs +22 -3
- package/extension/index.d.ts +5 -1
- package/extension/index.js +4 -1
- package/index.cjs +0 -3
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/model-function/Delta.d.ts +1 -2
- package/model-function/executeStreamCall.cjs +6 -4
- package/model-function/executeStreamCall.d.ts +2 -2
- package/model-function/executeStreamCall.js +6 -4
- package/model-function/generate-speech/streamSpeech.cjs +1 -2
- package/model-function/generate-speech/streamSpeech.js +1 -2
- package/model-function/generate-structure/StructureFromTextStreamingModel.cjs +25 -29
- package/model-function/generate-structure/StructureFromTextStreamingModel.d.ts +3 -1
- package/model-function/generate-structure/StructureFromTextStreamingModel.js +25 -29
- package/model-function/generate-structure/StructureGenerationModel.d.ts +2 -0
- package/model-function/generate-structure/jsonStructurePrompt.cjs +42 -6
- package/model-function/generate-structure/jsonStructurePrompt.d.ts +12 -1
- package/model-function/generate-structure/jsonStructurePrompt.js +42 -5
- package/model-function/generate-structure/streamStructure.cjs +7 -8
- package/model-function/generate-structure/streamStructure.d.ts +1 -1
- package/model-function/generate-structure/streamStructure.js +7 -8
- package/model-function/generate-text/PromptTemplateFullTextModel.cjs +35 -0
- package/model-function/generate-text/PromptTemplateFullTextModel.d.ts +41 -0
- package/model-function/generate-text/PromptTemplateFullTextModel.js +31 -0
- package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +2 -1
- package/model-function/generate-text/PromptTemplateTextGenerationModel.js +1 -1
- package/model-function/generate-text/PromptTemplateTextStreamingModel.cjs +3 -0
- package/model-function/generate-text/PromptTemplateTextStreamingModel.d.ts +2 -1
- package/model-function/generate-text/PromptTemplateTextStreamingModel.js +3 -0
- package/model-function/generate-text/TextGenerationModel.d.ts +2 -1
- package/model-function/generate-text/index.cjs +1 -0
- package/model-function/generate-text/index.d.ts +1 -0
- package/model-function/generate-text/index.js +1 -0
- package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.cjs +2 -2
- package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.js +1 -1
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.cjs +8 -5
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.js +7 -4
- package/model-function/generate-text/prompt-template/ChatPrompt.cjs +42 -0
- package/model-function/generate-text/prompt-template/ChatPrompt.d.ts +27 -5
- package/model-function/generate-text/prompt-template/ChatPrompt.js +41 -1
- package/model-function/generate-text/prompt-template/{Content.cjs → ContentPart.cjs} +1 -1
- package/model-function/generate-text/prompt-template/ContentPart.d.ts +30 -0
- package/model-function/generate-text/prompt-template/{Content.js → ContentPart.js} +1 -1
- package/model-function/generate-text/prompt-template/InstructionPrompt.d.ts +3 -2
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.cjs +8 -5
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.d.ts +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.js +6 -3
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.cjs +8 -4
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.js +6 -2
- package/model-function/generate-text/prompt-template/TextPromptTemplate.cjs +8 -4
- package/model-function/generate-text/prompt-template/TextPromptTemplate.js +6 -2
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.cjs +7 -3
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.js +6 -2
- package/model-function/generate-text/prompt-template/index.cjs +1 -1
- package/model-function/generate-text/prompt-template/index.d.ts +1 -1
- package/model-function/generate-text/prompt-template/index.js +1 -1
- package/model-function/generate-text/streamText.cjs +27 -28
- package/model-function/generate-text/streamText.d.ts +1 -0
- package/model-function/generate-text/streamText.js +27 -28
- package/model-function/index.cjs +0 -1
- package/model-function/index.d.ts +0 -1
- package/model-function/index.js +0 -1
- package/model-provider/anthropic/AnthropicPromptTemplate.cjs +7 -3
- package/model-provider/anthropic/AnthropicPromptTemplate.js +5 -1
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +8 -14
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +11 -2
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +8 -14
- package/model-provider/anthropic/AnthropicTextGenerationModel.test.cjs +44 -0
- package/model-provider/anthropic/AnthropicTextGenerationModel.test.js +42 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.cjs +6 -44
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +49 -15
- package/model-provider/cohere/CohereTextGenerationModel.js +7 -45
- package/model-provider/cohere/CohereTextGenerationModel.test.cjs +33 -0
- package/model-provider/cohere/CohereTextGenerationModel.test.js +31 -0
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +1 -2
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +1 -2
- package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.cjs +6 -1
- package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.js +6 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +7 -14
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +171 -20
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +8 -15
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.test.cjs +37 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.test.js +35 -0
- package/model-provider/mistral/MistralChatModel.cjs +30 -104
- package/model-provider/mistral/MistralChatModel.d.ts +47 -14
- package/model-provider/mistral/MistralChatModel.js +30 -104
- package/model-provider/mistral/MistralChatModel.test.cjs +51 -0
- package/model-provider/mistral/MistralChatModel.test.js +49 -0
- package/model-provider/mistral/MistralPromptTemplate.cjs +11 -4
- package/model-provider/mistral/MistralPromptTemplate.js +9 -2
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- package/model-provider/ollama/OllamaChatModel.cjs +7 -43
- package/model-provider/ollama/OllamaChatModel.d.ts +67 -14
- package/model-provider/ollama/OllamaChatModel.js +8 -44
- package/model-provider/ollama/OllamaChatModel.test.cjs +27 -0
- package/model-provider/ollama/OllamaChatModel.test.js +25 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.cjs +34 -4
- package/model-provider/ollama/OllamaChatPromptTemplate.js +34 -4
- package/model-provider/ollama/OllamaCompletionModel.cjs +22 -43
- package/model-provider/ollama/OllamaCompletionModel.d.ts +67 -10
- package/model-provider/ollama/OllamaCompletionModel.js +24 -45
- package/model-provider/ollama/OllamaCompletionModel.test.cjs +95 -13
- package/model-provider/ollama/OllamaCompletionModel.test.js +72 -13
- package/model-provider/openai/{chat/AbstractOpenAIChatModel.cjs → AbstractOpenAIChatModel.cjs} +71 -15
- package/model-provider/openai/{chat/AbstractOpenAIChatModel.d.ts → AbstractOpenAIChatModel.d.ts} +273 -19
- package/model-provider/openai/{chat/AbstractOpenAIChatModel.js → AbstractOpenAIChatModel.js} +71 -15
- package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.cjs → OpenAIChatFunctionCallStructureGenerationModel.cjs} +18 -2
- package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts → OpenAIChatFunctionCallStructureGenerationModel.d.ts} +41 -11
- package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.js → OpenAIChatFunctionCallStructureGenerationModel.js} +18 -2
- package/model-provider/openai/{chat/OpenAIChatMessage.d.ts → OpenAIChatMessage.d.ts} +3 -3
- package/model-provider/openai/{chat/OpenAIChatModel.cjs → OpenAIChatModel.cjs} +5 -5
- package/model-provider/openai/{chat/OpenAIChatModel.d.ts → OpenAIChatModel.d.ts} +12 -12
- package/model-provider/openai/{chat/OpenAIChatModel.js → OpenAIChatModel.js} +5 -5
- package/model-provider/openai/OpenAIChatModel.test.cjs +94 -0
- package/model-provider/openai/OpenAIChatModel.test.js +92 -0
- package/model-provider/openai/OpenAIChatPromptTemplate.cjs +114 -0
- package/model-provider/openai/{chat/OpenAIChatPromptTemplate.d.ts → OpenAIChatPromptTemplate.d.ts} +3 -3
- package/model-provider/openai/OpenAIChatPromptTemplate.js +107 -0
- package/model-provider/openai/OpenAICompletionModel.cjs +32 -84
- package/model-provider/openai/OpenAICompletionModel.d.ts +27 -10
- package/model-provider/openai/OpenAICompletionModel.js +33 -85
- package/model-provider/openai/OpenAICompletionModel.test.cjs +53 -0
- package/model-provider/openai/OpenAICompletionModel.test.js +51 -0
- package/model-provider/openai/OpenAIFacade.cjs +2 -2
- package/model-provider/openai/OpenAIFacade.d.ts +3 -3
- package/model-provider/openai/OpenAIFacade.js +2 -2
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +12 -12
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +17 -17
- package/model-provider/openai/TikTokenTokenizer.d.ts +1 -1
- package/model-provider/openai/{chat/countOpenAIChatMessageTokens.cjs → countOpenAIChatMessageTokens.cjs} +2 -2
- package/model-provider/openai/{chat/countOpenAIChatMessageTokens.js → countOpenAIChatMessageTokens.js} +2 -2
- package/model-provider/openai/index.cjs +6 -7
- package/model-provider/openai/index.d.ts +5 -7
- package/model-provider/openai/index.js +5 -6
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.cjs +4 -4
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +6 -6
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +4 -4
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +5 -5
- package/package.json +13 -24
- package/test/JsonTestServer.cjs +33 -0
- package/test/JsonTestServer.d.ts +7 -0
- package/test/JsonTestServer.js +29 -0
- package/test/StreamingTestServer.cjs +55 -0
- package/test/StreamingTestServer.d.ts +7 -0
- package/test/StreamingTestServer.js +51 -0
- package/test/arrayFromAsync.cjs +13 -0
- package/test/arrayFromAsync.d.ts +1 -0
- package/test/arrayFromAsync.js +9 -0
- package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.js +1 -1
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.d.ts +1 -11
- package/tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.d.ts +12 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.js +1 -0
- package/tool/generate-tool-calls-or-text/index.cjs +1 -0
- package/tool/generate-tool-calls-or-text/index.d.ts +1 -0
- package/tool/generate-tool-calls-or-text/index.js +1 -0
- package/util/index.cjs +0 -1
- package/util/index.d.ts +0 -1
- package/util/index.js +0 -1
- package/util/streaming/createEventSourceResponseHandler.cjs +9 -0
- package/util/streaming/createEventSourceResponseHandler.d.ts +4 -0
- package/util/streaming/createEventSourceResponseHandler.js +5 -0
- package/util/streaming/createJsonStreamResponseHandler.cjs +9 -0
- package/util/streaming/createJsonStreamResponseHandler.d.ts +4 -0
- package/util/streaming/createJsonStreamResponseHandler.js +5 -0
- package/util/streaming/parseEventSourceStreamAsAsyncIterable.cjs +52 -0
- package/util/streaming/parseEventSourceStreamAsAsyncIterable.d.ts +6 -0
- package/util/streaming/parseEventSourceStreamAsAsyncIterable.js +48 -0
- package/util/streaming/parseJsonStreamAsAsyncIterable.cjs +21 -0
- package/util/streaming/parseJsonStreamAsAsyncIterable.d.ts +6 -0
- package/util/streaming/parseJsonStreamAsAsyncIterable.js +17 -0
- package/browser/MediaSourceAppender.cjs +0 -54
- package/browser/MediaSourceAppender.d.ts +0 -11
- package/browser/MediaSourceAppender.js +0 -50
- package/browser/convertAudioChunksToBase64.cjs +0 -8
- package/browser/convertAudioChunksToBase64.d.ts +0 -4
- package/browser/convertAudioChunksToBase64.js +0 -4
- package/browser/convertBlobToBase64.cjs +0 -23
- package/browser/convertBlobToBase64.d.ts +0 -1
- package/browser/convertBlobToBase64.js +0 -19
- package/browser/index.cjs +0 -22
- package/browser/index.d.ts +0 -6
- package/browser/index.js +0 -6
- package/browser/invokeFlow.cjs +0 -23
- package/browser/invokeFlow.d.ts +0 -8
- package/browser/invokeFlow.js +0 -19
- package/browser/readEventSource.cjs +0 -29
- package/browser/readEventSource.d.ts +0 -9
- package/browser/readEventSource.js +0 -25
- package/browser/readEventSourceStream.cjs +0 -35
- package/browser/readEventSourceStream.d.ts +0 -7
- package/browser/readEventSourceStream.js +0 -31
- package/composed-function/index.cjs +0 -19
- package/composed-function/index.d.ts +0 -3
- package/composed-function/index.js +0 -3
- package/composed-function/summarize/SummarizationFunction.d.ts +0 -4
- package/composed-function/summarize/summarizeRecursively.cjs +0 -19
- package/composed-function/summarize/summarizeRecursively.d.ts +0 -11
- package/composed-function/summarize/summarizeRecursively.js +0 -15
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +0 -25
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +0 -24
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +0 -21
- package/cost/Cost.cjs +0 -38
- package/cost/Cost.d.ts +0 -16
- package/cost/Cost.js +0 -34
- package/cost/CostCalculator.d.ts +0 -8
- package/cost/calculateCost.cjs +0 -28
- package/cost/calculateCost.d.ts +0 -7
- package/cost/calculateCost.js +0 -24
- package/cost/index.cjs +0 -19
- package/cost/index.d.ts +0 -3
- package/cost/index.js +0 -3
- package/guard/GuardEvent.cjs +0 -2
- package/guard/GuardEvent.d.ts +0 -7
- package/guard/fixStructure.cjs +0 -75
- package/guard/fixStructure.d.ts +0 -64
- package/guard/fixStructure.js +0 -71
- package/guard/guard.cjs +0 -79
- package/guard/guard.d.ts +0 -29
- package/guard/guard.js +0 -75
- package/guard/index.cjs +0 -19
- package/guard/index.d.ts +0 -3
- package/guard/index.js +0 -3
- package/model-function/SuccessfulModelCall.cjs +0 -10
- package/model-function/SuccessfulModelCall.d.ts +0 -12
- package/model-function/SuccessfulModelCall.js +0 -6
- package/model-function/generate-text/prompt-template/Content.d.ts +0 -25
- package/model-provider/openai/OpenAICostCalculator.cjs +0 -89
- package/model-provider/openai/OpenAICostCalculator.d.ts +0 -6
- package/model-provider/openai/OpenAICostCalculator.js +0 -85
- package/model-provider/openai/chat/OpenAIChatModel.test.cjs +0 -61
- package/model-provider/openai/chat/OpenAIChatModel.test.js +0 -59
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.cjs +0 -70
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.js +0 -63
- package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +0 -156
- package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +0 -19
- package/model-provider/openai/chat/OpenAIChatStreamIterable.js +0 -152
- package/server/fastify/AssetStorage.cjs +0 -2
- package/server/fastify/AssetStorage.d.ts +0 -17
- package/server/fastify/DefaultFlow.cjs +0 -22
- package/server/fastify/DefaultFlow.d.ts +0 -16
- package/server/fastify/DefaultFlow.js +0 -18
- package/server/fastify/FileSystemAssetStorage.cjs +0 -60
- package/server/fastify/FileSystemAssetStorage.d.ts +0 -19
- package/server/fastify/FileSystemAssetStorage.js +0 -56
- package/server/fastify/FileSystemLogger.cjs +0 -49
- package/server/fastify/FileSystemLogger.d.ts +0 -18
- package/server/fastify/FileSystemLogger.js +0 -45
- package/server/fastify/Flow.cjs +0 -2
- package/server/fastify/Flow.d.ts +0 -9
- package/server/fastify/FlowRun.cjs +0 -71
- package/server/fastify/FlowRun.d.ts +0 -28
- package/server/fastify/FlowRun.js +0 -67
- package/server/fastify/FlowSchema.cjs +0 -2
- package/server/fastify/FlowSchema.d.ts +0 -5
- package/server/fastify/Logger.cjs +0 -2
- package/server/fastify/Logger.d.ts +0 -13
- package/server/fastify/PathProvider.cjs +0 -34
- package/server/fastify/PathProvider.d.ts +0 -12
- package/server/fastify/PathProvider.js +0 -30
- package/server/fastify/index.cjs +0 -24
- package/server/fastify/index.d.ts +0 -8
- package/server/fastify/index.js +0 -8
- package/server/fastify/modelFusionFlowPlugin.cjs +0 -103
- package/server/fastify/modelFusionFlowPlugin.d.ts +0 -12
- package/server/fastify/modelFusionFlowPlugin.js +0 -99
- package/util/getAudioFileExtension.cjs +0 -29
- package/util/getAudioFileExtension.d.ts +0 -1
- package/util/getAudioFileExtension.js +0 -25
- /package/{composed-function/summarize/SummarizationFunction.cjs → core/ExtensionFunctionEvent.cjs} +0 -0
- /package/{composed-function/summarize/SummarizationFunction.js → core/ExtensionFunctionEvent.js} +0 -0
- /package/{cost/CostCalculator.js → model-provider/anthropic/AnthropicTextGenerationModel.test.d.ts} +0 -0
- /package/{guard/GuardEvent.js → model-provider/cohere/CohereTextGenerationModel.test.d.ts} +0 -0
- /package/model-provider/{openai/chat/OpenAIChatModel.test.d.ts → llamacpp/LlamaCppTextGenerationModel.test.d.ts} +0 -0
- /package/{server/fastify/AssetStorage.js → model-provider/mistral/MistralChatModel.test.d.ts} +0 -0
- /package/{server/fastify/Flow.js → model-provider/ollama/OllamaChatModel.test.d.ts} +0 -0
- /package/model-provider/openai/{chat/OpenAIChatMessage.cjs → OpenAIChatMessage.cjs} +0 -0
- /package/model-provider/openai/{chat/OpenAIChatMessage.js → OpenAIChatMessage.js} +0 -0
- /package/{server/fastify/FlowSchema.js → model-provider/openai/OpenAIChatModel.test.d.ts} +0 -0
- /package/{server/fastify/Logger.js → model-provider/openai/OpenAICompletionModel.test.d.ts} +0 -0
- /package/model-provider/openai/{chat/countOpenAIChatMessageTokens.d.ts → countOpenAIChatMessageTokens.d.ts} +0 -0
- /package/{cost/CostCalculator.cjs → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.cjs} +0 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,65 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.106.0 - 2023-12-28
|
4
|
+
|
5
|
+
Experimental features that are unlikely to become stable before v1.0 have been moved to a separate `modelfusion-experimental` package.
|
6
|
+
|
7
|
+
### Removed
|
8
|
+
|
9
|
+
- Cost calculation
|
10
|
+
- `guard` function
|
11
|
+
- Browser and server features (incl. flow)
|
12
|
+
- `summarizeRecursively` function
|
13
|
+
|
14
|
+
## v0.105.0 - 2023-12-26
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Tool call support for chat prompts. Assistant messages can contain tool calls, and tool messages can contain tool call results. Tool calls can be used to implement e.g. agents:
|
19
|
+
|
20
|
+
```ts
|
21
|
+
const chat: ChatPrompt = {
|
22
|
+
system: "You are ...",
|
23
|
+
messages: [ChatMessage.user({ text: instruction })],
|
24
|
+
};
|
25
|
+
|
26
|
+
while (true) {
|
27
|
+
const { text, toolResults } = await useToolsOrGenerateText(
|
28
|
+
openai
|
29
|
+
.ChatTextGenerator({ model: "gpt-4-1106-preview" })
|
30
|
+
.withChatPrompt(),
|
31
|
+
tools, // array of tools
|
32
|
+
chat
|
33
|
+
);
|
34
|
+
|
35
|
+
// add the assistant and tool messages to the chat:
|
36
|
+
chat.messages.push(
|
37
|
+
ChatMessage.assistant({ text, toolResults }),
|
38
|
+
ChatMessage.tool({ toolResults })
|
39
|
+
);
|
40
|
+
|
41
|
+
if (toolResults == null) {
|
42
|
+
return; // no more actions, break loop
|
43
|
+
}
|
44
|
+
|
45
|
+
// ... (handle tool results)
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
- `streamText` returns a `text` promise when invoked with `fullResponse: true`. After the streaming has finished, the promise resolves with the full text.
|
50
|
+
|
51
|
+
```ts
|
52
|
+
const { text, textStream } = await streamText(
|
53
|
+
openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }).withTextPrompt(),
|
54
|
+
"Write a short story about a robot learning to love:",
|
55
|
+
{ fullResponse: true }
|
56
|
+
);
|
57
|
+
|
58
|
+
// ... (handle streaming)
|
59
|
+
|
60
|
+
console.log(await text); // full text
|
61
|
+
```
|
62
|
+
|
3
63
|
## v0.104.0 - 2023-12-24
|
4
64
|
|
5
65
|
### Changed
|
package/README.md
CHANGED
@@ -12,16 +12,13 @@
|
|
12
12
|
|
13
13
|
## Introduction
|
14
14
|
|
15
|
-
**ModelFusion** is
|
15
|
+
**ModelFusion** is an abstraction layer for integrating AI models into JavaScript and TypeScript applications, unifying the API for common operations such as text streaming, structure generation, and tool usage. It provides features to support production environments, including observability hooks, logging, and automatic retries. You can use ModelFusion to build AI applications, chatbots, and agents.
|
16
16
|
|
17
17
|
- **Vendor-neutral**: ModelFusion is a non-commercial open source project that is community-driven. You can use it with any supported provider.
|
18
18
|
- **Multi-modal**: ModelFusion supports a wide range of models including text generation, image generation, vision, text-to-speech, speech-to-text, and embedding models.
|
19
|
-
- **Streaming**: ModelFusion supports streaming for many generation models, e.g. text streaming, structure streaming, and full duplex speech streaming.
|
20
|
-
- **Utility functions**: ModelFusion provides functionality for tools and tool usage, vector indices, and guards functions.
|
21
19
|
- **Type inference and validation**: ModelFusion infers TypeScript types wherever possible and to validates model responses.
|
22
20
|
- **Observability and logging**: ModelFusion provides an observer framework and out-of-the-box logging support.
|
23
21
|
- **Resilience and Robustness**: ModelFusion ensures seamless operation through automatic retries, throttling, and error handling mechanisms.
|
24
|
-
- **Server**: ModelFusion provides a Fastify plugin that exposes a ModelFusion flow as a REST endpoint that uses server-sent events.
|
25
22
|
|
26
23
|
> [!NOTE]
|
27
24
|
> ModelFusion is in its initial development phase. The main API is now mostly stable, but until version 1.0 there may be breaking changes. Feedback and suggestions are welcome.
|
@@ -649,7 +646,7 @@ import { modelfusion } from "modelfusion";
|
|
649
646
|
modelfusion.setLogFormat("detailed-object"); // log full events
|
650
647
|
```
|
651
648
|
|
652
|
-
### [Server](https://modelfusion.dev/guide/server/)
|
649
|
+
### [Server](https://modelfusion.dev/guide/experimental/server/)
|
653
650
|
|
654
651
|
> [!WARNING]
|
655
652
|
> ModelFusion Server is in its initial development phase and not feature-complete. The API is experimental and breaking changes are likely. Feedback and suggestions are welcome.
|
@@ -668,7 +665,7 @@ import {
|
|
668
665
|
FileSystemAssetStorage,
|
669
666
|
FileSystemLogger,
|
670
667
|
modelFusionFastifyPlugin,
|
671
|
-
} from "modelfusion/fastify-server"; // '/fastify-server' import path
|
668
|
+
} from "modelfusion-experimental/fastify-server"; // '/fastify-server' import path
|
672
669
|
|
673
670
|
// configurable logging for all runs using ModelFusion observability:
|
674
671
|
const logger = new FileSystemLogger({
|
@@ -693,7 +690,7 @@ fastify.register(modelFusionFastifyPlugin, {
|
|
693
690
|
Using `invokeFlow`, you can easily connect your client to a ModelFusion flow endpoint:
|
694
691
|
|
695
692
|
```ts
|
696
|
-
import { invokeFlow } from "modelfusion/browser"; // '/browser' import path
|
693
|
+
import { invokeFlow } from "modelfusion-experimental/browser"; // '/browser' import path
|
697
694
|
|
698
695
|
invokeFlow({
|
699
696
|
url: `${BASE_URL}/myFlow`,
|
@@ -727,14 +724,12 @@ invokeFlow({
|
|
727
724
|
- [Generate structure or text](https://modelfusion.dev/guide/function/generate-structure-or-text)
|
728
725
|
- [Tokenize Text](https://modelfusion.dev/guide/function/tokenize-text)
|
729
726
|
- [Embed Value](https://modelfusion.dev/guide/function/embed)
|
730
|
-
- [Guards](https://modelfusion.dev/guide/guard)
|
731
727
|
- [Tools](https://modelfusion.dev/guide/tools)
|
732
728
|
- [Vector Indices](https://modelfusion.dev/guide/vector-index)
|
733
729
|
- [Upsert](https://modelfusion.dev/guide/vector-index/upsert)
|
734
730
|
- [Retrieve](https://modelfusion.dev/guide/vector-index/retrieve)
|
735
731
|
- [Text Chunks](https://modelfusion.dev/guide/text-chunk/)
|
736
732
|
- [Split Text](https://modelfusion.dev/guide/text-chunk/split)
|
737
|
-
- [Server](https://modelfusion.dev/guide/server/)
|
738
733
|
- [Utilities](https://modelfusion.dev/guide/util/)
|
739
734
|
- [API Configuration](https://modelfusion.dev/guide/util/api-configuration)
|
740
735
|
- [Retry strategies](https://modelfusion.dev/guide/util/api-configuration/retry)
|
@@ -743,7 +738,10 @@ invokeFlow({
|
|
743
738
|
- [Observers](https://modelfusion.dev/guide/util/observer)
|
744
739
|
- [Runs](https://modelfusion.dev/guide/util/run)
|
745
740
|
- [Abort signals](https://modelfusion.dev/guide/util/abort)
|
746
|
-
|
741
|
+
- [Experimental](https://modelfusion.dev/guide/experimental/)
|
742
|
+
- [Guards](https://modelfusion.dev/guide/experimental/guard)
|
743
|
+
- [Server](https://modelfusion.dev/guide/experimental/server/)
|
744
|
+
- [Cost calculation](https://modelfusion.dev/guide/experimental/cost-calculation)
|
747
745
|
- [Troubleshooting](https://modelfusion.dev/guide/troubleshooting)
|
748
746
|
- [Bundling](https://modelfusion.dev/guide/troubleshooting/bundling)
|
749
747
|
|
package/core/DefaultRun.cjs
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.DefaultRun = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
|
-
const SuccessfulModelCall_js_1 = require("../model-function/SuccessfulModelCall.cjs");
|
6
5
|
const FunctionEventSource_js_1 = require("./FunctionEventSource.cjs");
|
7
6
|
class DefaultRun {
|
8
7
|
constructor({ runId = `run-${(0, nanoid_1.nanoid)()}`, sessionId, userId, abortSignal, observers, errorHandler, } = {}) {
|
@@ -69,8 +68,5 @@ class DefaultRun {
|
|
69
68
|
errorHandler: this.errorHandler.bind(this),
|
70
69
|
});
|
71
70
|
}
|
72
|
-
get successfulModelCalls() {
|
73
|
-
return (0, SuccessfulModelCall_js_1.extractSuccessfulModelCalls)(this.events);
|
74
|
-
}
|
75
71
|
}
|
76
72
|
exports.DefaultRun = DefaultRun;
|
package/core/DefaultRun.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { SuccessfulModelCall } from "../model-function/SuccessfulModelCall.js";
|
2
1
|
import { ErrorHandler } from "../util/ErrorHandler.js";
|
3
2
|
import { FunctionEvent } from "./FunctionEvent.js";
|
4
3
|
import { FunctionObserver } from "./FunctionObserver.js";
|
@@ -22,5 +21,4 @@ export declare class DefaultRun implements Run {
|
|
22
21
|
readonly functionObserver: {
|
23
22
|
onFunctionEvent: (event: FunctionEvent) => void;
|
24
23
|
};
|
25
|
-
get successfulModelCalls(): Array<SuccessfulModelCall>;
|
26
24
|
}
|
package/core/DefaultRun.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
|
-
import { extractSuccessfulModelCalls, } from "../model-function/SuccessfulModelCall.js";
|
3
2
|
import { FunctionEventSource } from "./FunctionEventSource.js";
|
4
3
|
export class DefaultRun {
|
5
4
|
constructor({ runId = `run-${createId()}`, sessionId, userId, abortSignal, observers, errorHandler, } = {}) {
|
@@ -66,7 +65,4 @@ export class DefaultRun {
|
|
66
65
|
errorHandler: this.errorHandler.bind(this),
|
67
66
|
});
|
68
67
|
}
|
69
|
-
get successfulModelCalls() {
|
70
|
-
return extractSuccessfulModelCalls(this.events);
|
71
|
-
}
|
72
68
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "./FunctionEvent.js";
|
2
|
+
export interface ExtensionFunctionStartedEvent extends BaseFunctionStartedEvent {
|
3
|
+
functionType: "extension";
|
4
|
+
extension: string;
|
5
|
+
data: unknown;
|
6
|
+
}
|
7
|
+
export interface ExtensionFunctionFinishedEvent extends BaseFunctionFinishedEvent {
|
8
|
+
functionType: "extension";
|
9
|
+
extension: string;
|
10
|
+
data: unknown;
|
11
|
+
}
|
package/core/FunctionEvent.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ExtensionFunctionStartedEvent, ExtensionFunctionFinishedEvent } from "./ExtensionFunctionEvent.js";
|
2
2
|
import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
|
3
3
|
import { RetrieveFinishedEvent, RetrieveStartedEvent } from "../retriever/RetrieveEvent.js";
|
4
4
|
import { ExecuteToolFinishedEvent, ExecuteToolStartedEvent } from "../tool/execute-tool/ExecuteToolEvent.js";
|
@@ -82,4 +82,4 @@ export interface BaseFunctionFinishedEvent extends BaseFunctionEvent {
|
|
82
82
|
*/
|
83
83
|
result: BaseFunctionFinishedEventResult;
|
84
84
|
}
|
85
|
-
export type FunctionEvent = ExecuteFunctionStartedEvent | ExecuteFunctionFinishedEvent | ExecuteToolStartedEvent | ExecuteToolFinishedEvent |
|
85
|
+
export type FunctionEvent = ExecuteFunctionStartedEvent | ExecuteFunctionFinishedEvent | ExecuteToolStartedEvent | ExecuteToolFinishedEvent | ExtensionFunctionStartedEvent | ExtensionFunctionFinishedEvent | ModelCallStartedEvent | ModelCallFinishedEvent | RetrieveStartedEvent | RetrieveFinishedEvent | UpsertIntoVectorIndexStartedEvent | UpsertIntoVectorIndexFinishedEvent | UseToolStartedEvent | UseToolFinishedEvent | UseToolsOrGenerateTextStartedEvent | UseToolsOrGenerateTextFinishedEvent;
|
package/extension/index.cjs
CHANGED
@@ -1,15 +1,34 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.AbstractModel = exports.
|
17
|
+
exports.parseEventSourceStream = exports.AbstractModel = exports.executeFunctionCall = exports.postToApi = exports.postJsonToApi = exports.createTextResponseHandler = exports.createJsonResponseHandler = exports.createAudioMpegResponseHandler = exports.loadApiKey = exports.callWithRetryAndThrottle = void 0;
|
18
|
+
__exportStar(require("../core/ExtensionFunctionEvent.cjs"), exports);
|
4
19
|
var callWithRetryAndThrottle_js_1 = require("../core/api/callWithRetryAndThrottle.cjs");
|
5
20
|
Object.defineProperty(exports, "callWithRetryAndThrottle", { enumerable: true, get: function () { return callWithRetryAndThrottle_js_1.callWithRetryAndThrottle; } });
|
6
21
|
var loadApiKey_js_1 = require("../core/api/loadApiKey.cjs");
|
7
22
|
Object.defineProperty(exports, "loadApiKey", { enumerable: true, get: function () { return loadApiKey_js_1.loadApiKey; } });
|
8
23
|
var postToApi_js_1 = require("../core/api/postToApi.cjs");
|
9
|
-
Object.defineProperty(exports, "postJsonToApi", { enumerable: true, get: function () { return postToApi_js_1.postJsonToApi; } });
|
10
|
-
Object.defineProperty(exports, "postToApi", { enumerable: true, get: function () { return postToApi_js_1.postToApi; } });
|
11
24
|
Object.defineProperty(exports, "createAudioMpegResponseHandler", { enumerable: true, get: function () { return postToApi_js_1.createAudioMpegResponseHandler; } });
|
12
25
|
Object.defineProperty(exports, "createJsonResponseHandler", { enumerable: true, get: function () { return postToApi_js_1.createJsonResponseHandler; } });
|
13
26
|
Object.defineProperty(exports, "createTextResponseHandler", { enumerable: true, get: function () { return postToApi_js_1.createTextResponseHandler; } });
|
27
|
+
Object.defineProperty(exports, "postJsonToApi", { enumerable: true, get: function () { return postToApi_js_1.postJsonToApi; } });
|
28
|
+
Object.defineProperty(exports, "postToApi", { enumerable: true, get: function () { return postToApi_js_1.postToApi; } });
|
29
|
+
var executeFunctionCall_js_1 = require("../core/executeFunctionCall.cjs");
|
30
|
+
Object.defineProperty(exports, "executeFunctionCall", { enumerable: true, get: function () { return executeFunctionCall_js_1.executeFunctionCall; } });
|
14
31
|
var AbstractModel_js_1 = require("../model-function/AbstractModel.cjs");
|
15
32
|
Object.defineProperty(exports, "AbstractModel", { enumerable: true, get: function () { return AbstractModel_js_1.AbstractModel; } });
|
33
|
+
var parseEventSourceStream_js_1 = require("../util/streaming/parseEventSourceStream.cjs");
|
34
|
+
Object.defineProperty(exports, "parseEventSourceStream", { enumerable: true, get: function () { return parseEventSourceStream_js_1.parseEventSourceStream; } });
|
package/extension/index.d.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
export * from "../core/ExtensionFunctionEvent.js";
|
1
2
|
export { callWithRetryAndThrottle } from "../core/api/callWithRetryAndThrottle.js";
|
2
3
|
export { loadApiKey } from "../core/api/loadApiKey.js";
|
3
|
-
export {
|
4
|
+
export { ResponseHandler, createAudioMpegResponseHandler, createJsonResponseHandler, createTextResponseHandler, postJsonToApi, postToApi, } from "../core/api/postToApi.js";
|
5
|
+
export { executeFunctionCall } from "../core/executeFunctionCall.js";
|
4
6
|
export { AbstractModel } from "../model-function/AbstractModel.js";
|
7
|
+
export { ErrorHandler } from "../util/ErrorHandler.js";
|
8
|
+
export { parseEventSourceStream } from "../util/streaming/parseEventSourceStream.js";
|
package/extension/index.js
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
export * from "../core/ExtensionFunctionEvent.js";
|
1
2
|
export { callWithRetryAndThrottle } from "../core/api/callWithRetryAndThrottle.js";
|
2
3
|
export { loadApiKey } from "../core/api/loadApiKey.js";
|
3
|
-
export {
|
4
|
+
export { createAudioMpegResponseHandler, createJsonResponseHandler, createTextResponseHandler, postJsonToApi, postToApi, } from "../core/api/postToApi.js";
|
5
|
+
export { executeFunctionCall } from "../core/executeFunctionCall.js";
|
4
6
|
export { AbstractModel } from "../model-function/AbstractModel.js";
|
7
|
+
export { parseEventSourceStream } from "../util/streaming/parseEventSourceStream.js";
|
package/index.cjs
CHANGED
@@ -14,10 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./composed-function/index.cjs"), exports);
|
18
17
|
__exportStar(require("./core/index.cjs"), exports);
|
19
|
-
__exportStar(require("./cost/index.cjs"), exports);
|
20
|
-
__exportStar(require("./guard/index.cjs"), exports);
|
21
18
|
__exportStar(require("./model-function/index.cjs"), exports);
|
22
19
|
__exportStar(require("./model-provider/index.cjs"), exports);
|
23
20
|
__exportStar(require("./observability/index.cjs"), exports);
|
package/index.d.ts
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
export * from "./composed-function/index.js";
|
2
1
|
export * from "./core/index.js";
|
3
|
-
export * from "./cost/index.js";
|
4
|
-
export * from "./guard/index.js";
|
5
2
|
export * from "./model-function/index.js";
|
6
3
|
export * from "./model-provider/index.js";
|
7
4
|
export * from "./observability/index.js";
|
package/index.js
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
export * from "./composed-function/index.js";
|
2
1
|
export * from "./core/index.js";
|
3
|
-
export * from "./cost/index.js";
|
4
|
-
export * from "./guard/index.js";
|
5
2
|
export * from "./model-function/index.js";
|
6
3
|
export * from "./model-provider/index.js";
|
7
4
|
export * from "./observability/index.js";
|
@@ -11,7 +11,7 @@ const getRun_js_1 = require("../core/getRun.cjs");
|
|
11
11
|
const AsyncQueue_js_1 = require("../util/AsyncQueue.cjs");
|
12
12
|
const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
|
13
13
|
const runSafe_js_1 = require("../util/runSafe.cjs");
|
14
|
-
async function executeStreamCall({ model, options, input, functionType, startStream, processDelta, processFinished,
|
14
|
+
async function executeStreamCall({ model, options, input, functionType, startStream, processDelta, processFinished, onDone, }) {
|
15
15
|
const run = await (0, getRun_js_1.getRun)(options?.run);
|
16
16
|
const settings = model.settings;
|
17
17
|
const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
|
@@ -121,6 +121,7 @@ async function executeStreamCall({ model, options, input, functionType, startStr
|
|
121
121
|
responseQueue.error(loopResult.error);
|
122
122
|
return; // error is handled through queue
|
123
123
|
}
|
124
|
+
onDone?.();
|
124
125
|
const finishMetadata = {
|
125
126
|
eventType: "finished",
|
126
127
|
...startMetadata,
|
@@ -131,7 +132,6 @@ async function executeStreamCall({ model, options, input, functionType, startStr
|
|
131
132
|
...finishMetadata,
|
132
133
|
result: {
|
133
134
|
status: "success",
|
134
|
-
...getResult(),
|
135
135
|
},
|
136
136
|
});
|
137
137
|
}
|
@@ -140,7 +140,9 @@ async function executeStreamCall({ model, options, input, functionType, startStr
|
|
140
140
|
responseQueue.close();
|
141
141
|
}
|
142
142
|
})();
|
143
|
-
return
|
143
|
+
return {
|
144
|
+
stream: responseQueue,
|
145
|
+
};
|
144
146
|
});
|
145
147
|
if (!result.ok) {
|
146
148
|
const finishMetadata = {
|
@@ -170,7 +172,7 @@ async function executeStreamCall({ model, options, input, functionType, startStr
|
|
170
172
|
throw result.error;
|
171
173
|
}
|
172
174
|
return {
|
173
|
-
value: result.value,
|
175
|
+
value: result.value.stream,
|
174
176
|
metadata: startMetadata,
|
175
177
|
};
|
176
178
|
}
|
@@ -3,7 +3,7 @@ import { Delta } from "./Delta.js";
|
|
3
3
|
import { Model, ModelSettings } from "./Model.js";
|
4
4
|
import { ModelCallStartedEvent } from "./ModelCallEvent.js";
|
5
5
|
import { ModelCallMetadata } from "./ModelCallMetadata.js";
|
6
|
-
export declare function executeStreamCall<DELTA_VALUE, VALUE, MODEL extends Model<ModelSettings>>({ model, options, input, functionType, startStream, processDelta, processFinished,
|
6
|
+
export declare function executeStreamCall<DELTA_VALUE, VALUE, MODEL extends Model<ModelSettings>>({ model, options, input, functionType, startStream, processDelta, processFinished, onDone, }: {
|
7
7
|
model: MODEL;
|
8
8
|
options?: FunctionOptions;
|
9
9
|
input: unknown;
|
@@ -13,7 +13,7 @@ export declare function executeStreamCall<DELTA_VALUE, VALUE, MODEL extends Mode
|
|
13
13
|
type: "delta";
|
14
14
|
}) => VALUE | undefined;
|
15
15
|
processFinished?: () => VALUE | undefined;
|
16
|
-
|
16
|
+
onDone?: () => void;
|
17
17
|
}): Promise<{
|
18
18
|
value: AsyncIterable<VALUE>;
|
19
19
|
metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
|
@@ -8,7 +8,7 @@ import { getRun } from "../core/getRun.js";
|
|
8
8
|
import { AsyncQueue } from "../util/AsyncQueue.js";
|
9
9
|
import { startDurationMeasurement } from "../util/DurationMeasurement.js";
|
10
10
|
import { runSafe } from "../util/runSafe.js";
|
11
|
-
export async function executeStreamCall({ model, options, input, functionType, startStream, processDelta, processFinished,
|
11
|
+
export async function executeStreamCall({ model, options, input, functionType, startStream, processDelta, processFinished, onDone, }) {
|
12
12
|
const run = await getRun(options?.run);
|
13
13
|
const settings = model.settings;
|
14
14
|
const eventSource = new FunctionEventSource({
|
@@ -118,6 +118,7 @@ export async function executeStreamCall({ model, options, input, functionType, s
|
|
118
118
|
responseQueue.error(loopResult.error);
|
119
119
|
return; // error is handled through queue
|
120
120
|
}
|
121
|
+
onDone?.();
|
121
122
|
const finishMetadata = {
|
122
123
|
eventType: "finished",
|
123
124
|
...startMetadata,
|
@@ -128,7 +129,6 @@ export async function executeStreamCall({ model, options, input, functionType, s
|
|
128
129
|
...finishMetadata,
|
129
130
|
result: {
|
130
131
|
status: "success",
|
131
|
-
...getResult(),
|
132
132
|
},
|
133
133
|
});
|
134
134
|
}
|
@@ -137,7 +137,9 @@ export async function executeStreamCall({ model, options, input, functionType, s
|
|
137
137
|
responseQueue.close();
|
138
138
|
}
|
139
139
|
})();
|
140
|
-
return
|
140
|
+
return {
|
141
|
+
stream: responseQueue,
|
142
|
+
};
|
141
143
|
});
|
142
144
|
if (!result.ok) {
|
143
145
|
const finishMetadata = {
|
@@ -167,7 +169,7 @@ export async function executeStreamCall({ model, options, input, functionType, s
|
|
167
169
|
throw result.error;
|
168
170
|
}
|
169
171
|
return {
|
170
|
-
value: result.value,
|
172
|
+
value: result.value.stream,
|
171
173
|
metadata: startMetadata,
|
172
174
|
};
|
173
175
|
}
|
@@ -21,8 +21,7 @@ async function streamSpeech(model, text, options) {
|
|
21
21
|
model,
|
22
22
|
options,
|
23
23
|
startStream: async (options) => model.doGenerateSpeechStreamDuplex(textStream, options),
|
24
|
-
processDelta: (delta) => delta.
|
25
|
-
getResult: () => ({}),
|
24
|
+
processDelta: (delta) => delta.deltaValue,
|
26
25
|
});
|
27
26
|
return options?.fullResponse
|
28
27
|
? {
|
@@ -18,8 +18,7 @@ export async function streamSpeech(model, text, options) {
|
|
18
18
|
model,
|
19
19
|
options,
|
20
20
|
startStream: async (options) => model.doGenerateSpeechStreamDuplex(textStream, options),
|
21
|
-
processDelta: (delta) => delta.
|
22
|
-
getResult: () => ({}),
|
21
|
+
processDelta: (delta) => delta.deltaValue,
|
23
22
|
});
|
24
23
|
return options?.fullResponse
|
25
24
|
? {
|
@@ -11,35 +11,6 @@ class StructureFromTextStreamingModel extends StructureFromTextGenerationModel_j
|
|
11
11
|
constructor(options) {
|
12
12
|
super(options);
|
13
13
|
}
|
14
|
-
async doStreamStructure(schema, prompt, options) {
|
15
|
-
const textStream = await (0, streamText_js_1.streamText)(this.model, this.template.createPrompt(prompt, schema), options);
|
16
|
-
const queue = new AsyncQueue_js_1.AsyncQueue();
|
17
|
-
// run async on purpose:
|
18
|
-
(async () => {
|
19
|
-
try {
|
20
|
-
let fullText = "";
|
21
|
-
for await (const deltaText of textStream) {
|
22
|
-
fullText += deltaText;
|
23
|
-
const deltaStructure = (0, parsePartialJson_js_1.parsePartialJson)(fullText);
|
24
|
-
// only publish parsable structures
|
25
|
-
if (deltaStructure != null) {
|
26
|
-
queue.push({
|
27
|
-
type: "delta",
|
28
|
-
fullDelta: fullText,
|
29
|
-
valueDelta: deltaStructure,
|
30
|
-
});
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
34
|
-
catch (error) {
|
35
|
-
queue.push({ type: "error", error });
|
36
|
-
}
|
37
|
-
finally {
|
38
|
-
queue.close();
|
39
|
-
}
|
40
|
-
})();
|
41
|
-
return queue;
|
42
|
-
}
|
43
14
|
async doGenerateStructure(schema, prompt, options) {
|
44
15
|
const { response, text } = await (0, generateText_js_1.generateText)(this.model, this.template.createPrompt(prompt, schema), {
|
45
16
|
...options,
|
@@ -59,6 +30,31 @@ class StructureFromTextStreamingModel extends StructureFromTextGenerationModel_j
|
|
59
30
|
});
|
60
31
|
}
|
61
32
|
}
|
33
|
+
async doStreamStructure(schema, prompt, options) {
|
34
|
+
const textStream = await (0, streamText_js_1.streamText)(this.model, this.template.createPrompt(prompt, schema), options);
|
35
|
+
const queue = new AsyncQueue_js_1.AsyncQueue();
|
36
|
+
// run async on purpose:
|
37
|
+
(async () => {
|
38
|
+
try {
|
39
|
+
for await (const deltaText of textStream) {
|
40
|
+
queue.push({ type: "delta", deltaValue: deltaText });
|
41
|
+
}
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
queue.push({ type: "error", error });
|
45
|
+
}
|
46
|
+
finally {
|
47
|
+
queue.close();
|
48
|
+
}
|
49
|
+
})();
|
50
|
+
return queue;
|
51
|
+
}
|
52
|
+
extractStructureTextDelta(delta) {
|
53
|
+
return delta;
|
54
|
+
}
|
55
|
+
parseAccumulatedStructureText(accumulatedText) {
|
56
|
+
return (0, parsePartialJson_js_1.parsePartialJson)(accumulatedText);
|
57
|
+
}
|
62
58
|
withSettings(additionalSettings) {
|
63
59
|
return new StructureFromTextStreamingModel({
|
64
60
|
model: this.model.withSettings(additionalSettings),
|
@@ -12,11 +12,13 @@ export declare class StructureFromTextStreamingModel<SOURCE_PROMPT, TARGET_PROMP
|
|
12
12
|
model: MODEL;
|
13
13
|
template: StructureFromTextPromptTemplate<SOURCE_PROMPT, TARGET_PROMPT>;
|
14
14
|
});
|
15
|
-
doStreamStructure(schema: Schema<unknown> & JsonSchemaProducer, prompt: SOURCE_PROMPT, options?: FunctionOptions): Promise<AsyncQueue<Delta<unknown>>>;
|
16
15
|
doGenerateStructure(schema: Schema<unknown> & JsonSchemaProducer, prompt: SOURCE_PROMPT, options?: FunctionOptions): Promise<{
|
17
16
|
response: unknown;
|
18
17
|
value: unknown;
|
19
18
|
valueText: string;
|
20
19
|
}>;
|
20
|
+
doStreamStructure(schema: Schema<unknown> & JsonSchemaProducer, prompt: SOURCE_PROMPT, options?: FunctionOptions): Promise<AsyncQueue<Delta<string>>>;
|
21
|
+
extractStructureTextDelta(delta: unknown): string;
|
22
|
+
parseAccumulatedStructureText(accumulatedText: string): unknown;
|
21
23
|
withSettings(additionalSettings: Partial<MODEL["settings"]>): this;
|
22
24
|
}
|
@@ -8,35 +8,6 @@ export class StructureFromTextStreamingModel extends StructureFromTextGeneration
|
|
8
8
|
constructor(options) {
|
9
9
|
super(options);
|
10
10
|
}
|
11
|
-
async doStreamStructure(schema, prompt, options) {
|
12
|
-
const textStream = await streamText(this.model, this.template.createPrompt(prompt, schema), options);
|
13
|
-
const queue = new AsyncQueue();
|
14
|
-
// run async on purpose:
|
15
|
-
(async () => {
|
16
|
-
try {
|
17
|
-
let fullText = "";
|
18
|
-
for await (const deltaText of textStream) {
|
19
|
-
fullText += deltaText;
|
20
|
-
const deltaStructure = parsePartialJson(fullText);
|
21
|
-
// only publish parsable structures
|
22
|
-
if (deltaStructure != null) {
|
23
|
-
queue.push({
|
24
|
-
type: "delta",
|
25
|
-
fullDelta: fullText,
|
26
|
-
valueDelta: deltaStructure,
|
27
|
-
});
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
catch (error) {
|
32
|
-
queue.push({ type: "error", error });
|
33
|
-
}
|
34
|
-
finally {
|
35
|
-
queue.close();
|
36
|
-
}
|
37
|
-
})();
|
38
|
-
return queue;
|
39
|
-
}
|
40
11
|
async doGenerateStructure(schema, prompt, options) {
|
41
12
|
const { response, text } = await generateText(this.model, this.template.createPrompt(prompt, schema), {
|
42
13
|
...options,
|
@@ -56,6 +27,31 @@ export class StructureFromTextStreamingModel extends StructureFromTextGeneration
|
|
56
27
|
});
|
57
28
|
}
|
58
29
|
}
|
30
|
+
async doStreamStructure(schema, prompt, options) {
|
31
|
+
const textStream = await streamText(this.model, this.template.createPrompt(prompt, schema), options);
|
32
|
+
const queue = new AsyncQueue();
|
33
|
+
// run async on purpose:
|
34
|
+
(async () => {
|
35
|
+
try {
|
36
|
+
for await (const deltaText of textStream) {
|
37
|
+
queue.push({ type: "delta", deltaValue: deltaText });
|
38
|
+
}
|
39
|
+
}
|
40
|
+
catch (error) {
|
41
|
+
queue.push({ type: "error", error });
|
42
|
+
}
|
43
|
+
finally {
|
44
|
+
queue.close();
|
45
|
+
}
|
46
|
+
})();
|
47
|
+
return queue;
|
48
|
+
}
|
49
|
+
extractStructureTextDelta(delta) {
|
50
|
+
return delta;
|
51
|
+
}
|
52
|
+
parseAccumulatedStructureText(accumulatedText) {
|
53
|
+
return parsePartialJson(accumulatedText);
|
54
|
+
}
|
59
55
|
withSettings(additionalSettings) {
|
60
56
|
return new StructureFromTextStreamingModel({
|
61
57
|
model: this.model.withSettings(additionalSettings),
|
@@ -19,4 +19,6 @@ export interface StructureGenerationModel<PROMPT, SETTINGS extends StructureGene
|
|
19
19
|
}
|
20
20
|
export interface StructureStreamingModel<PROMPT, SETTINGS extends StructureGenerationModelSettings = StructureGenerationModelSettings> extends StructureGenerationModel<PROMPT, SETTINGS> {
|
21
21
|
doStreamStructure(schema: Schema<unknown> & JsonSchemaProducer, prompt: PROMPT, options?: FunctionOptions): PromiseLike<AsyncIterable<Delta<unknown>>>;
|
22
|
+
extractStructureTextDelta(delta: unknown): string | undefined;
|
23
|
+
parseAccumulatedStructureText(accumulatedText: string): unknown;
|
22
24
|
}
|