@llumiverse/drivers 0.22.0 → 0.23.0-dev-20251118
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/README.md +1 -1
- package/lib/cjs/adobe/firefly.js +8 -7
- package/lib/cjs/adobe/firefly.js.map +1 -1
- package/lib/cjs/azure/azure_foundry.js +12 -12
- package/lib/cjs/azure/azure_foundry.js.map +1 -1
- package/lib/cjs/bedrock/index.js +172 -22
- package/lib/cjs/bedrock/index.js.map +1 -1
- package/lib/cjs/bedrock/twelvelabs.js +87 -0
- package/lib/cjs/bedrock/twelvelabs.js.map +1 -0
- package/lib/cjs/groq/index.js +91 -16
- package/lib/cjs/groq/index.js.map +1 -1
- package/lib/cjs/huggingface_ie.js +7 -6
- package/lib/cjs/huggingface_ie.js.map +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/mistral/index.js +5 -4
- package/lib/cjs/mistral/index.js.map +1 -1
- package/lib/cjs/openai/azure_openai.js +1 -1
- package/lib/cjs/openai/azure_openai.js.map +1 -1
- package/lib/cjs/openai/index.js +16 -12
- package/lib/cjs/openai/index.js.map +1 -1
- package/lib/cjs/replicate.js +6 -6
- package/lib/cjs/replicate.js.map +1 -1
- package/lib/cjs/test/utils.js +1 -1
- package/lib/cjs/test/utils.js.map +1 -1
- package/lib/cjs/test-driver/TestErrorCompletionStream.js +20 -0
- package/lib/cjs/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js +24 -0
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/cjs/test-driver/index.js +109 -0
- package/lib/cjs/test-driver/index.js.map +1 -0
- package/lib/cjs/test-driver/utils.js +30 -0
- package/lib/cjs/test-driver/utils.js.map +1 -0
- package/lib/cjs/togetherai/index.js +4 -4
- package/lib/cjs/togetherai/index.js.map +1 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js +1 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +1 -1
- package/lib/cjs/vertexai/index.js +136 -31
- package/lib/cjs/vertexai/index.js.map +1 -1
- package/lib/cjs/vertexai/models/claude.js +38 -16
- package/lib/cjs/vertexai/models/claude.js.map +1 -1
- package/lib/cjs/vertexai/models/gemini.js +131 -41
- package/lib/cjs/vertexai/models/gemini.js.map +1 -1
- package/lib/cjs/vertexai/models/imagen.js +12 -23
- package/lib/cjs/vertexai/models/imagen.js.map +1 -1
- package/lib/cjs/vertexai/models/llama.js +4 -3
- package/lib/cjs/vertexai/models/llama.js.map +1 -1
- package/lib/cjs/vertexai/models.js +13 -2
- package/lib/cjs/vertexai/models.js.map +1 -1
- package/lib/cjs/watsonx/index.js +5 -5
- package/lib/cjs/watsonx/index.js.map +1 -1
- package/lib/cjs/xai/index.js +1 -1
- package/lib/cjs/xai/index.js.map +1 -1
- package/lib/esm/adobe/firefly.js +8 -7
- package/lib/esm/adobe/firefly.js.map +1 -1
- package/lib/esm/azure/azure_foundry.js +12 -12
- package/lib/esm/azure/azure_foundry.js.map +1 -1
- package/lib/esm/bedrock/index.js +172 -22
- package/lib/esm/bedrock/index.js.map +1 -1
- package/lib/esm/bedrock/twelvelabs.js +84 -0
- package/lib/esm/bedrock/twelvelabs.js.map +1 -0
- package/lib/esm/groq/index.js +91 -16
- package/lib/esm/groq/index.js.map +1 -1
- package/lib/esm/huggingface_ie.js +8 -7
- package/lib/esm/huggingface_ie.js.map +1 -1
- package/lib/esm/index.js +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/mistral/index.js +5 -4
- package/lib/esm/mistral/index.js.map +1 -1
- package/lib/esm/openai/azure_openai.js +1 -1
- package/lib/esm/openai/azure_openai.js.map +1 -1
- package/lib/esm/openai/index.js +16 -12
- package/lib/esm/openai/index.js.map +1 -1
- package/lib/esm/replicate.js +6 -6
- package/lib/esm/replicate.js.map +1 -1
- package/lib/esm/src/adobe/firefly.js +116 -0
- package/lib/esm/src/adobe/firefly.js.map +1 -0
- package/lib/esm/src/azure/azure_foundry.js +382 -0
- package/lib/esm/src/azure/azure_foundry.js.map +1 -0
- package/lib/esm/src/bedrock/converse.js +278 -0
- package/lib/esm/src/bedrock/converse.js.map +1 -0
- package/lib/esm/src/bedrock/index.js +962 -0
- package/lib/esm/src/bedrock/index.js.map +1 -0
- package/lib/esm/src/bedrock/nova-image-payload.js +203 -0
- package/lib/esm/src/bedrock/nova-image-payload.js.map +1 -0
- package/lib/esm/src/bedrock/payloads.js +2 -0
- package/lib/esm/src/bedrock/payloads.js.map +1 -0
- package/lib/esm/src/bedrock/s3.js +99 -0
- package/lib/esm/src/bedrock/s3.js.map +1 -0
- package/lib/esm/src/bedrock/twelvelabs.js +84 -0
- package/lib/esm/src/bedrock/twelvelabs.js.map +1 -0
- package/lib/esm/src/groq/index.js +286 -0
- package/lib/esm/src/groq/index.js.map +1 -0
- package/lib/esm/src/huggingface_ie.js +197 -0
- package/lib/esm/src/huggingface_ie.js.map +1 -0
- package/lib/esm/src/index.js +14 -0
- package/lib/esm/src/index.js.map +1 -0
- package/lib/esm/src/mistral/index.js +169 -0
- package/lib/esm/src/mistral/index.js.map +1 -0
- package/lib/esm/src/mistral/types.js +80 -0
- package/lib/esm/src/mistral/types.js.map +1 -0
- package/lib/esm/src/openai/azure_openai.js +68 -0
- package/lib/esm/src/openai/azure_openai.js.map +1 -0
- package/lib/esm/src/openai/index.js +464 -0
- package/lib/esm/src/openai/index.js.map +1 -0
- package/lib/esm/src/openai/openai.js +14 -0
- package/lib/esm/src/openai/openai.js.map +1 -0
- package/lib/esm/src/openai/openai_format.js +134 -0
- package/lib/esm/src/openai/openai_format.js.map +1 -0
- package/lib/esm/src/replicate.js +268 -0
- package/lib/esm/src/replicate.js.map +1 -0
- package/lib/esm/src/test/TestErrorCompletionStream.js +16 -0
- package/lib/esm/src/test/TestErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test/TestValidationErrorCompletionStream.js +20 -0
- package/lib/esm/src/test/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test/index.js +91 -0
- package/lib/esm/src/test/index.js.map +1 -0
- package/lib/esm/src/test/utils.js +25 -0
- package/lib/esm/src/test/utils.js.map +1 -0
- package/lib/esm/src/test-driver/TestErrorCompletionStream.js +16 -0
- package/lib/esm/src/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test-driver/TestValidationErrorCompletionStream.js +20 -0
- package/lib/esm/src/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test-driver/index.js +91 -0
- package/lib/esm/src/test-driver/index.js.map +1 -0
- package/lib/esm/src/test-driver/utils.js +25 -0
- package/lib/esm/src/test-driver/utils.js.map +1 -0
- package/lib/esm/src/togetherai/index.js +122 -0
- package/lib/esm/src/togetherai/index.js.map +1 -0
- package/lib/esm/src/togetherai/interfaces.js +2 -0
- package/lib/esm/src/togetherai/interfaces.js.map +1 -0
- package/lib/esm/src/vertexai/debug.js +6 -0
- package/lib/esm/src/vertexai/debug.js.map +1 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-image.js +24 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-image.js.map +1 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-text.js +20 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-text.js.map +1 -0
- package/lib/esm/src/vertexai/index.js +383 -0
- package/lib/esm/src/vertexai/index.js.map +1 -0
- package/lib/esm/src/vertexai/models/claude.js +394 -0
- package/lib/esm/src/vertexai/models/claude.js.map +1 -0
- package/lib/esm/src/vertexai/models/gemini.js +817 -0
- package/lib/esm/src/vertexai/models/gemini.js.map +1 -0
- package/lib/esm/src/vertexai/models/imagen.js +302 -0
- package/lib/esm/src/vertexai/models/imagen.js.map +1 -0
- package/lib/esm/src/vertexai/models/llama.js +179 -0
- package/lib/esm/src/vertexai/models/llama.js.map +1 -0
- package/lib/esm/src/vertexai/models.js +32 -0
- package/lib/esm/src/vertexai/models.js.map +1 -0
- package/lib/esm/src/watsonx/index.js +157 -0
- package/lib/esm/src/watsonx/index.js.map +1 -0
- package/lib/esm/src/watsonx/interfaces.js +2 -0
- package/lib/esm/src/watsonx/interfaces.js.map +1 -0
- package/lib/esm/src/xai/index.js +64 -0
- package/lib/esm/src/xai/index.js.map +1 -0
- package/lib/esm/test/utils.js +1 -1
- package/lib/esm/test/utils.js.map +1 -1
- package/lib/esm/test-driver/TestErrorCompletionStream.js +16 -0
- package/lib/esm/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/esm/test-driver/TestValidationErrorCompletionStream.js +20 -0
- package/lib/esm/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/esm/test-driver/index.js +91 -0
- package/lib/esm/test-driver/index.js.map +1 -0
- package/lib/esm/test-driver/utils.js +25 -0
- package/lib/esm/test-driver/utils.js.map +1 -0
- package/lib/esm/togetherai/index.js +4 -4
- package/lib/esm/togetherai/index.js.map +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/vertexai/embeddings/embeddings-text.js +1 -1
- package/lib/esm/vertexai/embeddings/embeddings-text.js.map +1 -1
- package/lib/esm/vertexai/index.js +136 -31
- package/lib/esm/vertexai/index.js.map +1 -1
- package/lib/esm/vertexai/models/claude.js +37 -15
- package/lib/esm/vertexai/models/claude.js.map +1 -1
- package/lib/esm/vertexai/models/gemini.js +133 -43
- package/lib/esm/vertexai/models/gemini.js.map +1 -1
- package/lib/esm/vertexai/models/imagen.js +9 -17
- package/lib/esm/vertexai/models/imagen.js.map +1 -1
- package/lib/esm/vertexai/models/llama.js +4 -3
- package/lib/esm/vertexai/models/llama.js.map +1 -1
- package/lib/esm/vertexai/models.js +13 -2
- package/lib/esm/vertexai/models.js.map +1 -1
- package/lib/esm/watsonx/index.js +5 -5
- package/lib/esm/watsonx/index.js.map +1 -1
- package/lib/esm/xai/index.js +1 -1
- package/lib/esm/xai/index.js.map +1 -1
- package/lib/types/adobe/firefly.d.ts +3 -3
- package/lib/types/adobe/firefly.d.ts.map +1 -1
- package/lib/types/azure/azure_foundry.d.ts +2 -2
- package/lib/types/azure/azure_foundry.d.ts.map +1 -1
- package/lib/types/bedrock/index.d.ts +9 -5
- package/lib/types/bedrock/index.d.ts.map +1 -1
- package/lib/types/bedrock/twelvelabs.d.ts +50 -0
- package/lib/types/bedrock/twelvelabs.d.ts.map +1 -0
- package/lib/types/groq/index.d.ts +3 -0
- package/lib/types/groq/index.d.ts.map +1 -1
- package/lib/types/huggingface_ie.d.ts +8 -5
- package/lib/types/huggingface_ie.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/mistral/index.d.ts +2 -2
- package/lib/types/mistral/index.d.ts.map +1 -1
- package/lib/types/openai/index.d.ts +2 -2
- package/lib/types/openai/index.d.ts.map +1 -1
- package/lib/types/replicate.d.ts +6 -3
- package/lib/types/replicate.d.ts.map +1 -1
- package/lib/types/src/adobe/firefly.d.ts +29 -0
- package/lib/types/src/azure/azure_foundry.d.ts +49 -0
- package/lib/types/src/bedrock/converse.d.ts +8 -0
- package/lib/types/src/bedrock/index.d.ts +61 -0
- package/lib/types/src/bedrock/nova-image-payload.d.ts +73 -0
- package/lib/types/src/bedrock/payloads.d.ts +11 -0
- package/lib/types/src/bedrock/s3.d.ts +22 -0
- package/lib/types/src/bedrock/twelvelabs.d.ts +49 -0
- package/lib/types/src/groq/index.d.ts +26 -0
- package/lib/types/src/huggingface_ie.d.ts +34 -0
- package/lib/types/src/index.d.ts +13 -0
- package/lib/types/src/mistral/index.d.ts +24 -0
- package/lib/types/src/mistral/types.d.ts +131 -0
- package/lib/types/src/openai/azure_openai.d.ts +24 -0
- package/lib/types/src/openai/index.d.ts +24 -0
- package/lib/types/src/openai/openai.d.ts +14 -0
- package/lib/types/src/openai/openai_format.d.ts +18 -0
- package/lib/types/src/replicate.d.ts +47 -0
- package/lib/types/src/test/TestErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test/TestValidationErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test/index.d.ts +23 -0
- package/lib/types/src/test/utils.d.ts +4 -0
- package/lib/types/src/test-driver/TestErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test-driver/TestValidationErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test-driver/index.d.ts +23 -0
- package/lib/types/src/test-driver/utils.d.ts +4 -0
- package/lib/types/src/togetherai/index.d.ts +22 -0
- package/lib/types/src/togetherai/interfaces.d.ts +95 -0
- package/lib/types/src/vertexai/debug.d.ts +1 -0
- package/lib/types/src/vertexai/embeddings/embeddings-image.d.ts +10 -0
- package/lib/types/src/vertexai/embeddings/embeddings-text.d.ts +9 -0
- package/lib/types/src/vertexai/index.d.ts +52 -0
- package/lib/types/src/vertexai/models/claude.d.ts +19 -0
- package/lib/types/src/vertexai/models/gemini.d.ts +17 -0
- package/lib/types/src/vertexai/models/imagen.d.ts +74 -0
- package/lib/types/src/vertexai/models/llama.d.ts +19 -0
- package/lib/types/src/vertexai/models.d.ts +14 -0
- package/lib/types/src/watsonx/index.d.ts +26 -0
- package/lib/types/src/watsonx/interfaces.d.ts +64 -0
- package/lib/types/src/xai/index.d.ts +18 -0
- package/lib/types/test-driver/TestErrorCompletionStream.d.ts +9 -0
- package/lib/types/test-driver/TestErrorCompletionStream.d.ts.map +1 -0
- package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts +9 -0
- package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts.map +1 -0
- package/lib/types/test-driver/index.d.ts +24 -0
- package/lib/types/test-driver/index.d.ts.map +1 -0
- package/lib/types/test-driver/utils.d.ts +5 -0
- package/lib/types/test-driver/utils.d.ts.map +1 -0
- package/lib/types/togetherai/index.d.ts +3 -3
- package/lib/types/togetherai/index.d.ts.map +1 -1
- package/lib/types/vertexai/index.d.ts +17 -14
- package/lib/types/vertexai/index.d.ts.map +1 -1
- package/lib/types/vertexai/models/claude.d.ts +2 -0
- package/lib/types/vertexai/models/claude.d.ts.map +1 -1
- package/lib/types/vertexai/models/gemini.d.ts.map +1 -1
- package/lib/types/vertexai/models/imagen.d.ts +2 -2
- package/lib/types/vertexai/models/imagen.d.ts.map +1 -1
- package/lib/types/vertexai/models/llama.d.ts +2 -2
- package/lib/types/vertexai/models/llama.d.ts.map +1 -1
- package/lib/types/vertexai/models.d.ts +2 -2
- package/lib/types/vertexai/models.d.ts.map +1 -1
- package/lib/types/watsonx/index.d.ts +3 -3
- package/lib/types/watsonx/index.d.ts.map +1 -1
- package/package.json +90 -85
- package/src/adobe/firefly.ts +14 -22
- package/src/azure/azure_foundry.ts +16 -16
- package/src/bedrock/index.ts +207 -28
- package/src/bedrock/twelvelabs.ts +150 -0
- package/src/groq/index.ts +134 -37
- package/src/huggingface_ie.ts +13 -14
- package/src/index.ts +2 -2
- package/src/mistral/index.ts +8 -7
- package/src/openai/azure_openai.ts +5 -5
- package/src/openai/index.ts +19 -13
- package/src/replicate.ts +14 -14
- package/src/{test → test-driver}/utils.ts +1 -1
- package/src/togetherai/index.ts +7 -7
- package/src/vertexai/embeddings/embeddings-text.ts +2 -2
- package/src/vertexai/index.ts +156 -40
- package/src/vertexai/models/claude.ts +45 -19
- package/src/vertexai/models/gemini.ts +161 -60
- package/src/vertexai/models/imagen.ts +15 -26
- package/src/vertexai/models/llama.ts +6 -5
- package/src/vertexai/models.ts +18 -6
- package/src/watsonx/index.ts +8 -8
- package/src/xai/index.ts +11 -12
- /package/src/{test → test-driver}/TestErrorCompletionStream.ts +0 -0
- /package/src/{test → test-driver}/TestValidationErrorCompletionStream.ts +0 -0
- /package/src/{test → test-driver}/index.ts +0 -0
package/src/groq/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AIModel, AbstractDriver, Completion, CompletionChunkObject, DriverOptions, EmbeddingsOptions, EmbeddingsResult, ExecutionOptions, PromptSegment, TextFallbackOptions } from "@llumiverse/core";
|
|
1
|
+
import { AIModel, AbstractDriver, Completion, CompletionChunkObject, DriverOptions, EmbeddingsOptions, EmbeddingsResult, ExecutionOptions, PromptSegment, TextFallbackOptions, ToolDefinition, ToolUse } from "@llumiverse/core";
|
|
2
2
|
import { transformAsyncIterator } from "@llumiverse/core/async";
|
|
3
3
|
import { formatOpenAILikeMultimodalPrompt } from "../openai/openai_format.js";
|
|
4
4
|
|
|
5
5
|
import Groq from "groq-sdk";
|
|
6
|
-
import type { ChatCompletionMessageParam } from "groq-sdk/resources/chat/completions";
|
|
6
|
+
import type { ChatCompletionMessageParam, ChatCompletionTool } from "groq-sdk/resources/chat/completions";
|
|
7
|
+
import type { FunctionParameters } from "groq-sdk/resources/shared";
|
|
7
8
|
|
|
8
9
|
interface GroqDriverOptions extends DriverOptions {
|
|
9
10
|
apiKey: string;
|
|
@@ -52,7 +53,7 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
52
53
|
...opts,
|
|
53
54
|
multimodal: true,
|
|
54
55
|
});
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
// Convert OpenAI ChatCompletionMessageParam[] to Groq ChatCompletionMessageParam[]
|
|
57
58
|
// Handle differences between OpenAI and Groq SDK types
|
|
58
59
|
const groqMessages: ChatCompletionMessageParam[] = openaiMessages.map(msg => {
|
|
@@ -60,7 +61,7 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
60
61
|
if (msg.role === 'developer' || msg.role === 'system') {
|
|
61
62
|
const systemMsg: ChatCompletionMessageParam = {
|
|
62
63
|
role: 'system',
|
|
63
|
-
content: Array.isArray(msg.content)
|
|
64
|
+
content: Array.isArray(msg.content)
|
|
64
65
|
? msg.content.map(part => part.text).join('\n')
|
|
65
66
|
: msg.content,
|
|
66
67
|
// Preserve name if present
|
|
@@ -68,23 +69,23 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
68
69
|
};
|
|
69
70
|
return systemMsg;
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
|
|
72
73
|
// Handle user messages - filter content parts to only supported types
|
|
73
74
|
if (msg.role === 'user') {
|
|
74
|
-
let content: string | Array<{type: 'text', text: string} | {type: 'image_url', image_url: {url: string, detail?: 'auto' | 'low' | 'high'}}> | undefined = undefined;
|
|
75
|
-
|
|
75
|
+
let content: string | Array<{ type: 'text', text: string } | { type: 'image_url', image_url: { url: string, detail?: 'auto' | 'low' | 'high' } }> | undefined = undefined;
|
|
76
|
+
|
|
76
77
|
if (typeof msg.content === 'string') {
|
|
77
78
|
content = msg.content;
|
|
78
79
|
} else if (Array.isArray(msg.content)) {
|
|
79
80
|
// Filter to only text and image_url parts that Groq supports
|
|
80
|
-
const supportedParts = msg.content.filter(part =>
|
|
81
|
+
const supportedParts = msg.content.filter(part =>
|
|
81
82
|
part.type === 'text' || part.type === 'image_url'
|
|
82
83
|
).map(part => {
|
|
83
84
|
if (part.type === 'text') {
|
|
84
85
|
return { type: 'text' as const, text: part.text };
|
|
85
86
|
} else if (part.type === 'image_url') {
|
|
86
|
-
return {
|
|
87
|
-
type: 'image_url' as const,
|
|
87
|
+
return {
|
|
88
|
+
type: 'image_url' as const,
|
|
88
89
|
image_url: {
|
|
89
90
|
url: part.image_url.url,
|
|
90
91
|
...(part.image_url.detail && { detail: part.image_url.detail })
|
|
@@ -92,11 +93,11 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
95
|
return null;
|
|
95
|
-
}).filter(Boolean) as Array<{type: 'text', text: string} | {type: 'image_url', image_url: {url: string, detail?: 'auto' | 'low' | 'high'}}>;
|
|
96
|
-
|
|
96
|
+
}).filter(Boolean) as Array<{ type: 'text', text: string } | { type: 'image_url', image_url: { url: string, detail?: 'auto' | 'low' | 'high' } }>;
|
|
97
|
+
|
|
97
98
|
content = supportedParts.length > 0 ? supportedParts : 'Content not supported';
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
+
|
|
100
101
|
const userMsg: ChatCompletionMessageParam = {
|
|
101
102
|
role: 'user',
|
|
102
103
|
content: content ?? "",
|
|
@@ -105,34 +106,33 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
105
106
|
};
|
|
106
107
|
return userMsg;
|
|
107
108
|
}
|
|
108
|
-
|
|
109
|
+
|
|
109
110
|
// Handle assistant messages - handle content arrays if needed
|
|
110
111
|
if (msg.role === 'assistant') {
|
|
111
112
|
const assistantMsg: ChatCompletionMessageParam = {
|
|
112
113
|
role: 'assistant',
|
|
113
|
-
content: Array.isArray(msg.content)
|
|
114
|
+
content: Array.isArray(msg.content)
|
|
114
115
|
? msg.content.map(part => 'text' in part ? part.text : '').filter(Boolean).join('\n') || null
|
|
115
116
|
: msg.content,
|
|
116
117
|
// Preserve other assistant message properties
|
|
117
|
-
...(msg.function_call && { function_call: msg.function_call }),
|
|
118
118
|
...(msg.tool_calls && { tool_calls: msg.tool_calls }),
|
|
119
119
|
...(msg.name && { name: msg.name })
|
|
120
120
|
};
|
|
121
121
|
return assistantMsg;
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
// For tool and function messages, they should be compatible
|
|
125
125
|
if (msg.role === 'tool') {
|
|
126
126
|
const toolMsg: ChatCompletionMessageParam = {
|
|
127
127
|
role: 'tool',
|
|
128
128
|
tool_call_id: msg.tool_call_id,
|
|
129
|
-
content: Array.isArray(msg.content)
|
|
129
|
+
content: Array.isArray(msg.content)
|
|
130
130
|
? msg.content.map(part => part.text).join('\n')
|
|
131
131
|
: msg.content
|
|
132
132
|
};
|
|
133
133
|
return toolMsg;
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
if (msg.role === 'function') {
|
|
137
137
|
const functionMsg: ChatCompletionMessageParam = {
|
|
138
138
|
role: 'function',
|
|
@@ -141,7 +141,7 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
141
141
|
};
|
|
142
142
|
return functionMsg;
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
// Fallback - should not reach here but provides type safety
|
|
146
146
|
throw new Error(`Unsupported message role: ${(msg as any).role}`);
|
|
147
147
|
});
|
|
@@ -149,15 +149,67 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
149
149
|
return groqMessages;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
private getToolDefinitions(tools: ToolDefinition[] | undefined): ChatCompletionTool[] | undefined {
|
|
153
|
+
if (!tools || tools.length === 0) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return tools.map(tool => ({
|
|
158
|
+
type: 'function' as const,
|
|
159
|
+
function: {
|
|
160
|
+
name: tool.name,
|
|
161
|
+
description: tool.description,
|
|
162
|
+
parameters: tool.input_schema satisfies FunctionParameters,
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private extractToolUse(message: any): ToolUse[] | undefined {
|
|
168
|
+
if (!message.tool_calls || message.tool_calls.length === 0) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return message.tool_calls.map((toolCall: any) => ({
|
|
173
|
+
id: toolCall.id,
|
|
174
|
+
tool_name: toolCall.function.name,
|
|
175
|
+
tool_input: JSON.parse(toolCall.function.arguments || '{}'),
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private sanitizeMessagesForGroq(messages: ChatCompletionMessageParam[]): ChatCompletionMessageParam[] {
|
|
180
|
+
return messages.map(message => {
|
|
181
|
+
// Remove any reasoning field from message objects
|
|
182
|
+
const { reasoning, ...sanitizedMessage } = message as any;
|
|
183
|
+
|
|
184
|
+
// If message has content array, filter out reasoning content types
|
|
185
|
+
if (Array.isArray(sanitizedMessage.content)) {
|
|
186
|
+
sanitizedMessage.content = sanitizedMessage.content.filter((part: any) => {
|
|
187
|
+
// Filter out any reasoning-related content parts
|
|
188
|
+
return part.type !== 'reasoning' && !('reasoning' in part);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return sanitizedMessage as ChatCompletionMessageParam;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
152
196
|
async requestTextCompletion(messages: ChatCompletionMessageParam[], options: ExecutionOptions): Promise<Completion> {
|
|
153
197
|
if (options.model_options?._option_id !== "text-fallback" && options.model_options?._option_id !== "groq-deepseek-thinking") {
|
|
154
|
-
this.logger.warn(
|
|
198
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
155
199
|
}
|
|
156
200
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
157
201
|
|
|
202
|
+
// Update conversation with current messages
|
|
203
|
+
let conversation = updateConversation(options.conversation as ChatCompletionMessageParam[], messages);
|
|
204
|
+
|
|
205
|
+
// Filter out any reasoning content that Groq doesn't support
|
|
206
|
+
conversation = this.sanitizeMessagesForGroq(conversation);
|
|
207
|
+
|
|
208
|
+
const tools = this.getToolDefinitions(options.tools);
|
|
209
|
+
|
|
158
210
|
const res = await this.client.chat.completions.create({
|
|
159
211
|
model: options.model,
|
|
160
|
-
messages:
|
|
212
|
+
messages: conversation,
|
|
161
213
|
max_completion_tokens: options.model_options?.max_tokens,
|
|
162
214
|
temperature: options.model_options?.temperature,
|
|
163
215
|
top_p: options.model_options?.top_p,
|
|
@@ -166,33 +218,54 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
166
218
|
presence_penalty: options.model_options?.presence_penalty,
|
|
167
219
|
frequency_penalty: options.model_options?.frequency_penalty,
|
|
168
220
|
response_format: this.getResponseFormat(options),
|
|
221
|
+
tools: tools,
|
|
169
222
|
});
|
|
170
223
|
|
|
171
|
-
|
|
172
224
|
const choice = res.choices[0];
|
|
173
225
|
const result = choice.message.content;
|
|
174
226
|
|
|
227
|
+
// Extract tool use from the response
|
|
228
|
+
const tool_use = this.extractToolUse(choice.message);
|
|
229
|
+
|
|
230
|
+
// Update conversation with the response
|
|
231
|
+
conversation = updateConversation(conversation, [choice.message]);
|
|
232
|
+
|
|
233
|
+
let finish_reason = choice.finish_reason;
|
|
234
|
+
if (tool_use && tool_use.length > 0) {
|
|
235
|
+
finish_reason = "tool_calls";
|
|
236
|
+
}
|
|
237
|
+
|
|
175
238
|
return {
|
|
176
|
-
result: result,
|
|
239
|
+
result: result ? [{ type: "text", value: result }] : [],
|
|
177
240
|
token_usage: {
|
|
178
241
|
prompt: res.usage?.prompt_tokens,
|
|
179
242
|
result: res.usage?.completion_tokens,
|
|
180
243
|
total: res.usage?.total_tokens,
|
|
181
244
|
},
|
|
182
|
-
finish_reason:
|
|
245
|
+
finish_reason: finish_reason,
|
|
183
246
|
original_response: options.include_original_response ? res : undefined,
|
|
247
|
+
conversation,
|
|
248
|
+
tool_use,
|
|
184
249
|
};
|
|
185
250
|
}
|
|
186
251
|
|
|
187
|
-
async requestTextCompletionStream(messages: ChatCompletionMessageParam[], options: ExecutionOptions): Promise
|
|
252
|
+
async requestTextCompletionStream(messages: ChatCompletionMessageParam[], options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
188
253
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
189
|
-
this.logger.warn(
|
|
254
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
190
255
|
}
|
|
191
256
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
192
257
|
|
|
258
|
+
// Update conversation with current messages
|
|
259
|
+
let conversation = updateConversation(options.conversation as ChatCompletionMessageParam[], messages);
|
|
260
|
+
|
|
261
|
+
// Filter out any reasoning content that Groq doesn't support
|
|
262
|
+
conversation = this.sanitizeMessagesForGroq(conversation);
|
|
263
|
+
|
|
264
|
+
const tools = this.getToolDefinitions(options.tools);
|
|
265
|
+
|
|
193
266
|
const res = await this.client.chat.completions.create({
|
|
194
267
|
model: options.model,
|
|
195
|
-
messages:
|
|
268
|
+
messages: conversation,
|
|
196
269
|
max_completion_tokens: options.model_options?.max_tokens,
|
|
197
270
|
temperature: options.model_options?.temperature,
|
|
198
271
|
top_p: options.model_options?.top_p,
|
|
@@ -201,17 +274,28 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
201
274
|
presence_penalty: options.model_options?.presence_penalty,
|
|
202
275
|
frequency_penalty: options.model_options?.frequency_penalty,
|
|
203
276
|
stream: true,
|
|
277
|
+
tools: tools,
|
|
204
278
|
});
|
|
205
279
|
|
|
206
|
-
return transformAsyncIterator(res, (
|
|
207
|
-
|
|
208
|
-
finish_reason
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
280
|
+
return transformAsyncIterator(res, (chunk) => {
|
|
281
|
+
const choice = chunk.choices[0];
|
|
282
|
+
let finish_reason = choice.finish_reason;
|
|
283
|
+
|
|
284
|
+
// Check for tool calls in the delta
|
|
285
|
+
if (choice.delta.tool_calls && choice.delta.tool_calls.length > 0) {
|
|
286
|
+
finish_reason = "tool_calls";
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
result: choice.delta.content ? [{ type: "text", value: choice.delta.content }] : [],
|
|
291
|
+
finish_reason: finish_reason ?? undefined,
|
|
292
|
+
token_usage: {
|
|
293
|
+
prompt: chunk.x_groq?.usage?.prompt_tokens,
|
|
294
|
+
result: chunk.x_groq?.usage?.completion_tokens,
|
|
295
|
+
total: chunk.x_groq?.usage?.total_tokens,
|
|
296
|
+
},
|
|
297
|
+
} satisfies CompletionChunkObject;
|
|
298
|
+
});
|
|
215
299
|
}
|
|
216
300
|
|
|
217
301
|
async listModels(): Promise<AIModel<string>[]> {
|
|
@@ -245,4 +329,17 @@ export class GroqDriver extends AbstractDriver<GroqDriverOptions, ChatCompletion
|
|
|
245
329
|
throw new Error("Method not implemented.");
|
|
246
330
|
}
|
|
247
331
|
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Update the conversation messages by combining existing conversation with new messages
|
|
336
|
+
* @param conversation Existing conversation messages
|
|
337
|
+
* @param messages New messages to add
|
|
338
|
+
* @returns Combined conversation
|
|
339
|
+
*/
|
|
340
|
+
function updateConversation(
|
|
341
|
+
conversation: ChatCompletionMessageParam[] | undefined,
|
|
342
|
+
messages: ChatCompletionMessageParam[]
|
|
343
|
+
): ChatCompletionMessageParam[] {
|
|
344
|
+
return (conversation || []).concat(messages);
|
|
248
345
|
}
|
package/src/huggingface_ie.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
TextGenerationStreamOutput
|
|
2
|
+
InferenceClient,
|
|
3
|
+
TextGenerationStreamOutput,
|
|
5
4
|
} from "@huggingface/inference";
|
|
6
5
|
import {
|
|
7
6
|
AIModel,
|
|
@@ -25,7 +24,7 @@ export class HuggingFaceIEDriver extends AbstractDriver<HuggingFaceIEDriverOptio
|
|
|
25
24
|
static PROVIDER = "huggingface_ie";
|
|
26
25
|
provider = HuggingFaceIEDriver.PROVIDER;
|
|
27
26
|
service: FetchClient;
|
|
28
|
-
_executor?:
|
|
27
|
+
_executor?: InferenceClient;
|
|
29
28
|
|
|
30
29
|
constructor(
|
|
31
30
|
options: HuggingFaceIEDriverOptions
|
|
@@ -60,7 +59,8 @@ export class HuggingFaceIEDriver extends AbstractDriver<HuggingFaceIEDriverOptio
|
|
|
60
59
|
`Endpoint ${model} is not running - current status: ${endpoint.status}`
|
|
61
60
|
);
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
// Use the new InferenceClient and bind it to the endpoint URL
|
|
63
|
+
this._executor = new InferenceClient(this.options.apiKey).endpoint(
|
|
64
64
|
endpoint.url
|
|
65
65
|
);
|
|
66
66
|
}
|
|
@@ -69,7 +69,7 @@ export class HuggingFaceIEDriver extends AbstractDriver<HuggingFaceIEDriverOptio
|
|
|
69
69
|
|
|
70
70
|
async requestTextCompletionStream(prompt: string, options: ExecutionOptions) {
|
|
71
71
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
72
|
-
this.logger.warn(
|
|
72
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
73
73
|
}
|
|
74
74
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
75
75
|
|
|
@@ -81,31 +81,30 @@ export class HuggingFaceIEDriver extends AbstractDriver<HuggingFaceIEDriverOptio
|
|
|
81
81
|
max_new_tokens: options.model_options?.max_tokens,
|
|
82
82
|
},
|
|
83
83
|
});
|
|
84
|
-
|
|
85
84
|
|
|
86
|
-
return transformAsyncIterator(req, (val: TextGenerationStreamOutput) => {
|
|
85
|
+
return transformAsyncIterator(req, (val: TextGenerationStreamOutput): CompletionChunkObject => {
|
|
87
86
|
//special like <s> are not part of the result
|
|
88
|
-
if (val.token.special) return { result:
|
|
87
|
+
if (val.token.special) return { result: [] };
|
|
89
88
|
let finish_reason = val.details?.finish_reason as string;
|
|
90
89
|
if (finish_reason === "eos_token") {
|
|
91
90
|
finish_reason = "stop";
|
|
92
91
|
}
|
|
93
92
|
return {
|
|
94
|
-
result: val.token.text
|
|
93
|
+
result: val.token.text ? [{ type: "text" as const, value: val.token.text }] : [],
|
|
95
94
|
finish_reason: finish_reason,
|
|
96
95
|
token_usage: {
|
|
97
96
|
result: val.details?.generated_tokens ?? 0,
|
|
98
97
|
}
|
|
99
|
-
}
|
|
98
|
+
};
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
async requestTextCompletion(prompt: string, options: ExecutionOptions) {
|
|
104
103
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
105
|
-
this.logger.warn(
|
|
104
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
106
105
|
}
|
|
107
106
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
108
|
-
|
|
107
|
+
|
|
109
108
|
const executor = await this.getExecutor(options.model);
|
|
110
109
|
const res = await executor.textGeneration({
|
|
111
110
|
inputs: prompt,
|
|
@@ -120,7 +119,7 @@ export class HuggingFaceIEDriver extends AbstractDriver<HuggingFaceIEDriverOptio
|
|
|
120
119
|
finish_reason = "stop";
|
|
121
120
|
}
|
|
122
121
|
return {
|
|
123
|
-
result: res.generated_text,
|
|
122
|
+
result: [{ type: "text" as const, value: res.generated_text }],
|
|
124
123
|
finish_reason: finish_reason,
|
|
125
124
|
token_usage: {
|
|
126
125
|
result: res.details?.generated_tokens
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
export * from "./azure/azure_foundry.js";
|
|
1
2
|
export * from "./bedrock/index.js";
|
|
2
3
|
export * from "./groq/index.js";
|
|
3
4
|
export * from "./huggingface_ie.js";
|
|
4
5
|
export * from "./mistral/index.js";
|
|
5
6
|
export * from "./openai/azure_openai.js";
|
|
6
|
-
export * from "./azure/azure_foundry.js";
|
|
7
7
|
export * from "./openai/openai.js";
|
|
8
8
|
export * from "./replicate.js";
|
|
9
|
-
export * from "./test/index.js";
|
|
9
|
+
export * from "./test-driver/index.js";
|
|
10
10
|
export * from "./togetherai/index.js";
|
|
11
11
|
export * from "./vertexai/index.js";
|
|
12
12
|
export * from "./watsonx/index.js";
|
package/src/mistral/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AIModel, AbstractDriver, Completion,
|
|
1
|
+
import { AIModel, AbstractDriver, Completion, CompletionChunkObject, DriverOptions, EmbeddingsOptions, EmbeddingsResult, ExecutionOptions, PromptSegment, TextFallbackOptions } from "@llumiverse/core";
|
|
2
2
|
import { transformSSEStream } from "@llumiverse/core/async";
|
|
3
3
|
import { getJSONSafetyNotice } from "@llumiverse/core/formatters";
|
|
4
4
|
import { formatOpenAILikeTextPrompt, OpenAITextMessage } from "../openai/openai_format.js";
|
|
@@ -64,7 +64,7 @@ export class MistralAIDriver extends AbstractDriver<MistralAIDriverOptions, Open
|
|
|
64
64
|
|
|
65
65
|
async requestTextCompletion(messages: OpenAITextMessage[], options: ExecutionOptions): Promise<Completion> {
|
|
66
66
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
67
|
-
this.logger.warn(
|
|
67
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
68
68
|
}
|
|
69
69
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
70
70
|
|
|
@@ -82,7 +82,7 @@ export class MistralAIDriver extends AbstractDriver<MistralAIDriverOptions, Open
|
|
|
82
82
|
const result = choice.message.content;
|
|
83
83
|
|
|
84
84
|
return {
|
|
85
|
-
result: result,
|
|
85
|
+
result: result ? [{ type: "text", value: result }] : [],
|
|
86
86
|
token_usage: {
|
|
87
87
|
prompt: res.usage.prompt_tokens,
|
|
88
88
|
result: res.usage.completion_tokens,
|
|
@@ -93,9 +93,9 @@ export class MistralAIDriver extends AbstractDriver<MistralAIDriverOptions, Open
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async requestTextCompletionStream(messages: OpenAITextMessage[], options: ExecutionOptions): Promise<AsyncIterable<
|
|
96
|
+
async requestTextCompletionStream(messages: OpenAITextMessage[], options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
97
97
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
98
|
-
this.logger.warn(
|
|
98
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
99
99
|
}
|
|
100
100
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
101
101
|
|
|
@@ -115,8 +115,9 @@ export class MistralAIDriver extends AbstractDriver<MistralAIDriverOptions, Open
|
|
|
115
115
|
|
|
116
116
|
return transformSSEStream(stream, (data: string) => {
|
|
117
117
|
const json = JSON.parse(data);
|
|
118
|
+
const content = json.choices[0]?.delta.content;
|
|
118
119
|
return {
|
|
119
|
-
result:
|
|
120
|
+
result: content ? [{ type: "text", value: content }] : [],
|
|
120
121
|
finish_reason: json.choices[0]?.finish_reason, //Uses expected "stop" , "length" format
|
|
121
122
|
token_usage: {
|
|
122
123
|
prompt: json.usage?.prompt_tokens,
|
|
@@ -152,7 +153,7 @@ export class MistralAIDriver extends AbstractDriver<MistralAIDriverOptions, Open
|
|
|
152
153
|
const r = await this.client.post('/v1/embeddings', {
|
|
153
154
|
payload: {
|
|
154
155
|
model,
|
|
155
|
-
input: [
|
|
156
|
+
input: [text],
|
|
156
157
|
encoding_format: "float"
|
|
157
158
|
},
|
|
158
159
|
});
|
|
@@ -9,7 +9,7 @@ export interface AzureOpenAIDriverOptions extends DriverOptions {
|
|
|
9
9
|
* The credentials to use to access Azure OpenAI
|
|
10
10
|
*/
|
|
11
11
|
azureADTokenProvider?: any; //type with azure credentials
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
apiKey?: string;
|
|
14
14
|
|
|
15
15
|
endpoint?: string;
|
|
@@ -41,7 +41,7 @@ export class AzureOpenAIDriver extends BaseOpenAIDriver {
|
|
|
41
41
|
|
|
42
42
|
this.service = new AzureOpenAI({
|
|
43
43
|
apiKey: opts.apiKey,
|
|
44
|
-
azureADTokenProvider: opts.azureADTokenProvider,
|
|
44
|
+
azureADTokenProvider: opts.azureADTokenProvider,
|
|
45
45
|
endpoint: opts.endpoint,
|
|
46
46
|
apiVersion: opts.apiVersion ?? "2024-10-21",
|
|
47
47
|
deployment: opts.deployment
|
|
@@ -56,7 +56,7 @@ export class AzureOpenAIDriver extends BaseOpenAIDriver {
|
|
|
56
56
|
const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope);
|
|
57
57
|
return azureADTokenProvider;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
async listModels(): Promise<AIModel[]> {
|
|
61
61
|
return this._listModels();
|
|
62
62
|
}
|
|
@@ -65,7 +65,7 @@ export class AzureOpenAIDriver extends BaseOpenAIDriver {
|
|
|
65
65
|
if (!this.service.deploymentName) {
|
|
66
66
|
throw new Error("A specific deployment is not set. Azure OpenAI cannot list deployments. Update your endpoint URL to include the deployment name, e.g., https://your-resource.openai.azure.com/openai/deployments/your-deployment/chat/completions");
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
//Do a test execution to check if the model works and to get the model ID.
|
|
70
70
|
let modelID = this.service.deploymentName;
|
|
71
71
|
try {
|
|
@@ -76,7 +76,7 @@ export class AzureOpenAIDriver extends BaseOpenAIDriver {
|
|
|
76
76
|
});
|
|
77
77
|
modelID = testResponse.model;
|
|
78
78
|
} catch (error) {
|
|
79
|
-
this.logger.error("Failed to test model for Azure OpenAI listing :"
|
|
79
|
+
this.logger.error({ error }, "Failed to test model for Azure OpenAI listing :");
|
|
80
80
|
}
|
|
81
81
|
const modelCapability = getModelCapabilities(modelID, "openai");
|
|
82
82
|
return [{
|
package/src/openai/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
AbstractDriver,
|
|
4
4
|
Completion,
|
|
5
5
|
CompletionChunkObject,
|
|
6
|
+
CompletionResult,
|
|
6
7
|
DataSource,
|
|
7
8
|
DriverOptions,
|
|
8
9
|
EmbeddingsOptions,
|
|
@@ -28,7 +29,12 @@ import OpenAI, { AzureOpenAI } from "openai";
|
|
|
28
29
|
import { ChatCompletionMessageParam } from "openai/resources/chat/completions";
|
|
29
30
|
import { Stream } from "openai/streaming";
|
|
30
31
|
|
|
31
|
-
//
|
|
32
|
+
// Helper function to convert string to CompletionResult[]
|
|
33
|
+
function textToCompletionResult(text: string): CompletionResult[] {
|
|
34
|
+
return text ? [{ type: "text", value: text }] : [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//TODO: Do we need a list?, replace with if statements and modernize?
|
|
32
38
|
const supportFineTunning = new Set([
|
|
33
39
|
"gpt-3.5-turbo-1106",
|
|
34
40
|
"gpt-3.5-turbo-0613",
|
|
@@ -70,21 +76,21 @@ export abstract class BaseOpenAIDriver extends AbstractDriver<
|
|
|
70
76
|
const data = choice.message.content ?? undefined;
|
|
71
77
|
|
|
72
78
|
if (!data && !tools) {
|
|
73
|
-
this.logger
|
|
79
|
+
this.logger.error({ result }, "[OpenAI] Response is not valid");
|
|
74
80
|
throw new Error("Response is not valid: no data");
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
return {
|
|
78
|
-
result: data,
|
|
84
|
+
result: textToCompletionResult(data || ''),
|
|
79
85
|
token_usage: tokenInfo,
|
|
80
86
|
finish_reason: openAiFinishReason(choice.finish_reason),
|
|
81
87
|
tool_use: tools,
|
|
82
88
|
};
|
|
83
89
|
}
|
|
84
90
|
|
|
85
|
-
async requestTextCompletionStream(prompt: ChatCompletionMessageParam[], options: ExecutionOptions): Promise<AsyncIterable<
|
|
91
|
+
async requestTextCompletionStream(prompt: ChatCompletionMessageParam[], options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
86
92
|
if (options.model_options?._option_id !== "openai-text" && options.model_options?._option_id !== "openai-thinking") {
|
|
87
|
-
this.logger.warn(
|
|
93
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
const toolDefs = getToolDefinitions(options.tools);
|
|
@@ -99,7 +105,7 @@ export abstract class BaseOpenAIDriver extends AbstractDriver<
|
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
return {
|
|
102
|
-
result: result,
|
|
108
|
+
result: textToCompletionResult(result),
|
|
103
109
|
finish_reason: openAiFinishReason(chunk.choices[0]?.finish_reason ?? undefined), //Uses expected "stop" , "length" format
|
|
104
110
|
token_usage: {
|
|
105
111
|
prompt: chunk.usage?.prompt_tokens,
|
|
@@ -135,8 +141,6 @@ export abstract class BaseOpenAIDriver extends AbstractDriver<
|
|
|
135
141
|
reasoning_effort: model_options?.reasoning_effort,
|
|
136
142
|
temperature: model_options?.temperature,
|
|
137
143
|
top_p: model_options?.top_p,
|
|
138
|
-
//top_logprobs: options.top_logprobs, //Logprobs output currently not supported
|
|
139
|
-
//logprobs: options.top_logprobs ? true : false,
|
|
140
144
|
presence_penalty: model_options?.presence_penalty,
|
|
141
145
|
frequency_penalty: model_options?.frequency_penalty,
|
|
142
146
|
n: 1,
|
|
@@ -159,7 +163,7 @@ export abstract class BaseOpenAIDriver extends AbstractDriver<
|
|
|
159
163
|
|
|
160
164
|
async requestTextCompletion(prompt: ChatCompletionMessageParam[], options: ExecutionOptions): Promise<Completion> {
|
|
161
165
|
if (options.model_options?._option_id !== "openai-text" && options.model_options?._option_id !== "openai-thinking") {
|
|
162
|
-
this.logger.warn(
|
|
166
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
163
167
|
}
|
|
164
168
|
|
|
165
169
|
convertRoles(prompt, options.model);
|
|
@@ -192,8 +196,6 @@ export abstract class BaseOpenAIDriver extends AbstractDriver<
|
|
|
192
196
|
reasoning_effort: model_options?.reasoning_effort,
|
|
193
197
|
temperature: model_options?.temperature,
|
|
194
198
|
top_p: model_options?.top_p,
|
|
195
|
-
//top_logprobs: options.top_logprobs, //Logprobs output currently not supported
|
|
196
|
-
//logprobs: options.top_logprobs ? true : false,
|
|
197
199
|
presence_penalty: model_options?.presence_penalty,
|
|
198
200
|
frequency_penalty: model_options?.frequency_penalty,
|
|
199
201
|
n: 1,
|
|
@@ -291,7 +293,7 @@ export abstract class BaseOpenAIDriver extends AbstractDriver<
|
|
|
291
293
|
//Some of these use the completions API instead of the chat completions API.
|
|
292
294
|
//Others are for non-text input modalities. Therefore common to both.
|
|
293
295
|
const wordBlacklist = ["embed", "whisper", "transcribe", "audio", "moderation", "tts",
|
|
294
|
-
"realtime", "dall-e", "babbage", "davinci", "codex", "o1-pro"];
|
|
296
|
+
"realtime", "dall-e", "babbage", "davinci", "codex", "o1-pro", "computer-use", "sora"];
|
|
295
297
|
|
|
296
298
|
|
|
297
299
|
//OpenAI has very little information, filtering based on name.
|
|
@@ -302,11 +304,15 @@ export abstract class BaseOpenAIDriver extends AbstractDriver<
|
|
|
302
304
|
const models = filter ? result.filter(filter) : result;
|
|
303
305
|
const aiModels = models.map((m) => {
|
|
304
306
|
const modelCapability = getModelCapabilities(m.id, "openai");
|
|
307
|
+
let owner = m.owned_by;
|
|
308
|
+
if (owner == "system") {
|
|
309
|
+
owner = "openai";
|
|
310
|
+
}
|
|
305
311
|
return {
|
|
306
312
|
id: m.id,
|
|
307
313
|
name: m.id,
|
|
308
314
|
provider: this.provider,
|
|
309
|
-
owner:
|
|
315
|
+
owner: owner,
|
|
310
316
|
type: m.object === "model" ? ModelType.Text : ModelType.Unknown,
|
|
311
317
|
can_stream: true,
|
|
312
318
|
is_multimodal: m.id.includes("gpt-4"),
|