@genkit-ai/compat-oai 0.0.2
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/LICENSE +203 -0
- package/README.md +201 -0
- package/lib/audio.d.mts +77 -0
- package/lib/audio.d.ts +77 -0
- package/lib/audio.js +185 -0
- package/lib/audio.js.map +1 -0
- package/lib/audio.mjs +159 -0
- package/lib/audio.mjs.map +1 -0
- package/lib/deepseek/deepseek.d.mts +96 -0
- package/lib/deepseek/deepseek.d.ts +96 -0
- package/lib/deepseek/deepseek.js +62 -0
- package/lib/deepseek/deepseek.js.map +1 -0
- package/lib/deepseek/deepseek.mjs +38 -0
- package/lib/deepseek/deepseek.mjs.map +1 -0
- package/lib/deepseek/index.d.mts +67 -0
- package/lib/deepseek/index.d.ts +67 -0
- package/lib/deepseek/index.js +93 -0
- package/lib/deepseek/index.js.map +1 -0
- package/lib/deepseek/index.mjs +64 -0
- package/lib/deepseek/index.mjs.map +1 -0
- package/lib/embedder.d.mts +41 -0
- package/lib/embedder.d.ts +41 -0
- package/lib/embedder.js +51 -0
- package/lib/embedder.js.map +1 -0
- package/lib/embedder.mjs +27 -0
- package/lib/embedder.mjs.map +1 -0
- package/lib/image.d.mts +68 -0
- package/lib/image.d.ts +68 -0
- package/lib/image.js +105 -0
- package/lib/image.js.map +1 -0
- package/lib/image.mjs +79 -0
- package/lib/image.mjs.map +1 -0
- package/lib/index.d.mts +66 -0
- package/lib/index.d.ts +66 -0
- package/lib/index.js +56 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +32 -0
- package/lib/index.mjs.map +1 -0
- package/lib/model.d.mts +144 -0
- package/lib/model.d.ts +144 -0
- package/lib/model.js +349 -0
- package/lib/model.js.map +1 -0
- package/lib/model.mjs +315 -0
- package/lib/model.mjs.map +1 -0
- package/lib/openai/dalle.d.mts +51 -0
- package/lib/openai/dalle.d.ts +51 -0
- package/lib/openai/dalle.js +43 -0
- package/lib/openai/dalle.js.map +1 -0
- package/lib/openai/dalle.mjs +21 -0
- package/lib/openai/dalle.mjs.map +1 -0
- package/lib/openai/embedder.d.mts +79 -0
- package/lib/openai/embedder.d.ts +79 -0
- package/lib/openai/embedder.js +82 -0
- package/lib/openai/embedder.js.map +1 -0
- package/lib/openai/embedder.mjs +53 -0
- package/lib/openai/embedder.mjs.map +1 -0
- package/lib/openai/gpt.d.mts +1207 -0
- package/lib/openai/gpt.d.ts +1207 -0
- package/lib/openai/gpt.js +326 -0
- package/lib/openai/gpt.js.map +1 -0
- package/lib/openai/gpt.mjs +286 -0
- package/lib/openai/gpt.mjs.map +1 -0
- package/lib/openai/index.d.mts +77 -0
- package/lib/openai/index.d.ts +77 -0
- package/lib/openai/index.js +195 -0
- package/lib/openai/index.js.map +1 -0
- package/lib/openai/index.mjs +182 -0
- package/lib/openai/index.mjs.map +1 -0
- package/lib/openai/tts.d.mts +96 -0
- package/lib/openai/tts.d.ts +96 -0
- package/lib/openai/tts.js +83 -0
- package/lib/openai/tts.js.map +1 -0
- package/lib/openai/tts.mjs +54 -0
- package/lib/openai/tts.mjs.map +1 -0
- package/lib/openai/whisper.d.mts +441 -0
- package/lib/openai/whisper.d.ts +441 -0
- package/lib/openai/whisper.js +83 -0
- package/lib/openai/whisper.js.map +1 -0
- package/lib/openai/whisper.mjs +55 -0
- package/lib/openai/whisper.mjs.map +1 -0
- package/lib/xai/grok-image.d.mts +66 -0
- package/lib/xai/grok-image.d.ts +66 -0
- package/lib/xai/grok-image.js +43 -0
- package/lib/xai/grok-image.js.map +1 -0
- package/lib/xai/grok-image.mjs +21 -0
- package/lib/xai/grok-image.mjs.map +1 -0
- package/lib/xai/grok.d.mts +192 -0
- package/lib/xai/grok.d.ts +192 -0
- package/lib/xai/grok.js +61 -0
- package/lib/xai/grok.js.map +1 -0
- package/lib/xai/grok.mjs +37 -0
- package/lib/xai/grok.mjs.map +1 -0
- package/lib/xai/index.d.mts +70 -0
- package/lib/xai/index.d.ts +70 -0
- package/lib/xai/index.js +118 -0
- package/lib/xai/index.js.map +1 -0
- package/lib/xai/index.mjs +93 -0
- package/lib/xai/index.mjs.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { modelRef } from "genkit/model";
|
|
2
|
+
import { ChatCompletionCommonConfigSchema } from "../model";
|
|
3
|
+
const deepseekChat = modelRef({
|
|
4
|
+
name: "deepseek/deepseek-chat",
|
|
5
|
+
info: {
|
|
6
|
+
label: "DeepSeek - DeepSeek Chat",
|
|
7
|
+
supports: {
|
|
8
|
+
multiturn: true,
|
|
9
|
+
tools: true,
|
|
10
|
+
media: false,
|
|
11
|
+
systemRole: true,
|
|
12
|
+
output: ["text", "json"]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
configSchema: ChatCompletionCommonConfigSchema
|
|
16
|
+
});
|
|
17
|
+
const deepseekReasoner = modelRef({
|
|
18
|
+
name: "deepseek/deepseek-reasoner",
|
|
19
|
+
info: {
|
|
20
|
+
label: "DeepSeek - DeepSeek Reasoner",
|
|
21
|
+
supports: {
|
|
22
|
+
multiturn: true,
|
|
23
|
+
tools: true,
|
|
24
|
+
media: false,
|
|
25
|
+
systemRole: true,
|
|
26
|
+
output: ["text", "json"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
configSchema: ChatCompletionCommonConfigSchema
|
|
30
|
+
});
|
|
31
|
+
const SUPPORTED_DEEPSEEK_MODELS = {
|
|
32
|
+
"deepseek-reasoner": deepseekReasoner,
|
|
33
|
+
"deepseek-chat": deepseekChat
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
SUPPORTED_DEEPSEEK_MODELS
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=deepseek.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/deepseek/deepseek.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { modelRef } from 'genkit/model';\nimport { ChatCompletionCommonConfigSchema } from '../model';\n\nconst deepseekChat = modelRef({\n name: 'deepseek/deepseek-chat',\n info: {\n label: 'DeepSeek - DeepSeek Chat',\n supports: {\n multiturn: true,\n tools: true,\n media: false,\n systemRole: true,\n output: ['text', 'json'],\n },\n },\n configSchema: ChatCompletionCommonConfigSchema,\n});\n\nconst deepseekReasoner = modelRef({\n name: 'deepseek/deepseek-reasoner',\n info: {\n label: 'DeepSeek - DeepSeek Reasoner',\n supports: {\n multiturn: true,\n tools: true,\n media: false,\n systemRole: true,\n output: ['text', 'json'],\n },\n },\n configSchema: ChatCompletionCommonConfigSchema,\n});\n\nexport const SUPPORTED_DEEPSEEK_MODELS = {\n 'deepseek-reasoner': deepseekReasoner,\n 'deepseek-chat': deepseekChat,\n};\n"],"mappings":"AAgBA,SAAS,gBAAgB;AACzB,SAAS,wCAAwC;AAEjD,MAAM,eAAe,SAAS;AAAA,EAC5B,MAAM;AAAA,EACN,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,UAAU;AAAA,MACR,WAAW;AAAA,MACX,OAAO;AAAA,MACP,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,QAAQ,CAAC,QAAQ,MAAM;AAAA,IACzB;AAAA,EACF;AAAA,EACA,cAAc;AAChB,CAAC;AAED,MAAM,mBAAmB,SAAS;AAAA,EAChC,MAAM;AAAA,EACN,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,UAAU;AAAA,MACR,WAAW;AAAA,MACX,OAAO;AAAA,MACP,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,QAAQ,CAAC,QAAQ,MAAM;AAAA,IACzB;AAAA,EACF;AAAA,EACA,cAAc;AAChB,CAAC;AAEM,MAAM,4BAA4B;AAAA,EACvC,qBAAqB;AAAA,EACrB,iBAAiB;AACnB;","names":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z, ModelReference } from 'genkit';
|
|
2
|
+
import { GenkitPlugin } from 'genkit/plugin';
|
|
3
|
+
import { PluginOptions } from '../index.mjs';
|
|
4
|
+
import { ChatCompletionCommonConfigSchema } from '../model.mjs';
|
|
5
|
+
import { SUPPORTED_DEEPSEEK_MODELS } from './deepseek.mjs';
|
|
6
|
+
import 'genkit/registry';
|
|
7
|
+
import 'openai';
|
|
8
|
+
import 'genkit/model';
|
|
9
|
+
import 'openai/resources/index.mjs';
|
|
10
|
+
import 'zod';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright 2024 Google LLC
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License.
|
|
17
|
+
* You may obtain a copy of the License at
|
|
18
|
+
*
|
|
19
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
22
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
23
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
|
+
* See the License for the specific language governing permissions and
|
|
25
|
+
* limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;
|
|
29
|
+
declare function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin;
|
|
30
|
+
type DeepSeekPlugin = {
|
|
31
|
+
(params?: DeepSeekPluginOptions): GenkitPlugin;
|
|
32
|
+
model(name: keyof typeof SUPPORTED_DEEPSEEK_MODELS, config?: z.infer<typeof ChatCompletionCommonConfigSchema>): ModelReference<typeof ChatCompletionCommonConfigSchema>;
|
|
33
|
+
model(name: string, config?: any): ModelReference<z.ZodTypeAny>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* This module provides an interface to the DeepSeek models through the Genkit
|
|
37
|
+
* plugin system. It allows users to interact with various models by providing
|
|
38
|
+
* an API key and optional configuration.
|
|
39
|
+
*
|
|
40
|
+
* The main export is the `deepseek` plugin, which can be configured with an API
|
|
41
|
+
* key either directly or through environment variables. It initializes the
|
|
42
|
+
* OpenAI client and makes available the models for use.
|
|
43
|
+
*
|
|
44
|
+
* Exports:
|
|
45
|
+
* - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI
|
|
46
|
+
* compatible API.
|
|
47
|
+
*
|
|
48
|
+
* Usage: To use the models, initialize the deepseek plugin inside
|
|
49
|
+
* `configureGenkit` and pass the configuration options. If no API key is
|
|
50
|
+
* provided in the options, the environment variable `OPENAI_API_KEY` must be
|
|
51
|
+
* set.
|
|
52
|
+
*
|
|
53
|
+
* Example:
|
|
54
|
+
* ```
|
|
55
|
+
* import { deepSeek } from '@genkit-ai/compat-oai/deepseek';
|
|
56
|
+
*
|
|
57
|
+
* export default configureGenkit({
|
|
58
|
+
* plugins: [
|
|
59
|
+
* deepSeek()
|
|
60
|
+
* ... // other plugins
|
|
61
|
+
* ]
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare const deepSeek: DeepSeekPlugin;
|
|
66
|
+
|
|
67
|
+
export { type DeepSeekPlugin, type DeepSeekPluginOptions, deepSeek, deepSeekPlugin, deepSeek as default };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z, ModelReference } from 'genkit';
|
|
2
|
+
import { GenkitPlugin } from 'genkit/plugin';
|
|
3
|
+
import { PluginOptions } from '../index.js';
|
|
4
|
+
import { ChatCompletionCommonConfigSchema } from '../model.js';
|
|
5
|
+
import { SUPPORTED_DEEPSEEK_MODELS } from './deepseek.js';
|
|
6
|
+
import 'genkit/registry';
|
|
7
|
+
import 'openai';
|
|
8
|
+
import 'genkit/model';
|
|
9
|
+
import 'openai/resources/index.mjs';
|
|
10
|
+
import 'zod';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright 2024 Google LLC
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License.
|
|
17
|
+
* You may obtain a copy of the License at
|
|
18
|
+
*
|
|
19
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
22
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
23
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
|
+
* See the License for the specific language governing permissions and
|
|
25
|
+
* limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;
|
|
29
|
+
declare function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin;
|
|
30
|
+
type DeepSeekPlugin = {
|
|
31
|
+
(params?: DeepSeekPluginOptions): GenkitPlugin;
|
|
32
|
+
model(name: keyof typeof SUPPORTED_DEEPSEEK_MODELS, config?: z.infer<typeof ChatCompletionCommonConfigSchema>): ModelReference<typeof ChatCompletionCommonConfigSchema>;
|
|
33
|
+
model(name: string, config?: any): ModelReference<z.ZodTypeAny>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* This module provides an interface to the DeepSeek models through the Genkit
|
|
37
|
+
* plugin system. It allows users to interact with various models by providing
|
|
38
|
+
* an API key and optional configuration.
|
|
39
|
+
*
|
|
40
|
+
* The main export is the `deepseek` plugin, which can be configured with an API
|
|
41
|
+
* key either directly or through environment variables. It initializes the
|
|
42
|
+
* OpenAI client and makes available the models for use.
|
|
43
|
+
*
|
|
44
|
+
* Exports:
|
|
45
|
+
* - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI
|
|
46
|
+
* compatible API.
|
|
47
|
+
*
|
|
48
|
+
* Usage: To use the models, initialize the deepseek plugin inside
|
|
49
|
+
* `configureGenkit` and pass the configuration options. If no API key is
|
|
50
|
+
* provided in the options, the environment variable `OPENAI_API_KEY` must be
|
|
51
|
+
* set.
|
|
52
|
+
*
|
|
53
|
+
* Example:
|
|
54
|
+
* ```
|
|
55
|
+
* import { deepSeek } from '@genkit-ai/compat-oai/deepseek';
|
|
56
|
+
*
|
|
57
|
+
* export default configureGenkit({
|
|
58
|
+
* plugins: [
|
|
59
|
+
* deepSeek()
|
|
60
|
+
* ... // other plugins
|
|
61
|
+
* ]
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare const deepSeek: DeepSeekPlugin;
|
|
66
|
+
|
|
67
|
+
export { type DeepSeekPlugin, type DeepSeekPluginOptions, deepSeek, deepSeekPlugin, deepSeek as default };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var deepseek_exports = {};
|
|
30
|
+
__export(deepseek_exports, {
|
|
31
|
+
deepSeek: () => deepSeek,
|
|
32
|
+
deepSeekPlugin: () => deepSeekPlugin,
|
|
33
|
+
default: () => deepseek_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(deepseek_exports);
|
|
36
|
+
var import_genkit = require("genkit");
|
|
37
|
+
var import_logging = require("genkit/logging");
|
|
38
|
+
var import__ = __toESM(require("../index.js"));
|
|
39
|
+
var import_model = require("../model.js");
|
|
40
|
+
var import_deepseek = require("./deepseek.js");
|
|
41
|
+
const resolver = async (ai, client, actionType, actionName) => {
|
|
42
|
+
if (actionType === "model") {
|
|
43
|
+
(0, import_model.defineCompatOpenAIModel)({
|
|
44
|
+
ai,
|
|
45
|
+
name: `deepseek/${actionName}`,
|
|
46
|
+
client
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
import_logging.logger.warn("Only model actions are supported by the DeepSeek plugin");
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const listActions = async (client) => {
|
|
53
|
+
return await client.models.list().then(
|
|
54
|
+
(response) => response.data.filter((model2) => model2.object === "model").map((model2) => {
|
|
55
|
+
return (0, import_genkit.modelActionMetadata)({
|
|
56
|
+
name: `deepseek/${model2.id}`,
|
|
57
|
+
configSchema: import_model.ChatCompletionCommonConfigSchema,
|
|
58
|
+
info: import_deepseek.SUPPORTED_DEEPSEEK_MODELS[model2.id]?.info
|
|
59
|
+
});
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
function deepSeekPlugin(options) {
|
|
64
|
+
return (0, import__.default)({
|
|
65
|
+
name: "deepseek",
|
|
66
|
+
baseURL: "https://api.deepseek.com",
|
|
67
|
+
...options,
|
|
68
|
+
initializer: async (ai, client) => {
|
|
69
|
+
Object.values(import_deepseek.SUPPORTED_DEEPSEEK_MODELS).forEach(
|
|
70
|
+
(modelRef2) => (0, import_model.defineCompatOpenAIModel)({ ai, name: modelRef2.name, client, modelRef: modelRef2 })
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
resolver,
|
|
74
|
+
listActions
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const model = (name, config) => {
|
|
78
|
+
return (0, import_genkit.modelRef)({
|
|
79
|
+
name: `deepseek/${name}`,
|
|
80
|
+
config,
|
|
81
|
+
configSchema: import_model.ChatCompletionCommonConfigSchema
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const deepSeek = Object.assign(deepSeekPlugin, {
|
|
85
|
+
model
|
|
86
|
+
});
|
|
87
|
+
var deepseek_default = deepSeek;
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
deepSeek,
|
|
91
|
+
deepSeekPlugin
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/deepseek/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n modelActionMetadata,\n modelRef,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport {\n ChatCompletionCommonConfigSchema,\n defineCompatOpenAIModel,\n} from '../model.js';\nimport { SUPPORTED_DEEPSEEK_MODELS } from './deepseek.js';\n\nexport type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n defineCompatOpenAIModel({\n ai,\n name: `deepseek/${actionName}`,\n client,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n return modelActionMetadata({\n name: `deepseek/${model.id}`,\n configSchema: ChatCompletionCommonConfigSchema,\n info: SUPPORTED_DEEPSEEK_MODELS[model.id]?.info,\n });\n })\n );\n};\n\nexport function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin {\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_DEEPSEEK_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({ ai, name: modelRef.name, client, modelRef })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_DEEPSEEK_MODELS,\n config?: z.infer<typeof ChatCompletionCommonConfigSchema>\n ): ModelReference<typeof ChatCompletionCommonConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n return modelRef({\n name: `deepseek/${name}`,\n config,\n configSchema: ChatCompletionCommonConfigSchema,\n });\n}) as DeepSeekPlugin['model'];\n\n/**\n * This module provides an interface to the DeepSeek models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `deepseek` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the deepseek plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { deepSeek } from '@genkit-ai/compat-oai/deepseek';\n *\n * export default configureGenkit({\n * plugins: [\n * deepSeek()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const deepSeek: DeepSeekPlugin = Object.assign(deepSeekPlugin, {\n model,\n});\n\nexport default deepSeek;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAOO;AACP,qBAAuB;AAIvB,eAAgD;AAChD,mBAGO;AACP,sBAA0C;AAI1C,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,SAAS;AAC1B,8CAAwB;AAAA,MACtB;AAAA,MACA,MAAM,YAAY,UAAU;AAAA,MAC5B;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,0BAAO,KAAK,yDAAyD;AAAA,EACvE;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,iBAAO,mCAAoB;AAAA,QACzB,MAAM,YAAYA,OAAM,EAAE;AAAA,QAC1B,cAAc;AAAA,QACd,MAAM,0CAA0BA,OAAM,EAAE,GAAG;AAAA,MAC7C,CAAC;AAAA,IACH,CAAC;AAAA,EACL;AACF;AAEO,SAAS,eAAe,SAA+C;AAC5E,aAAO,SAAAC,SAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,GAAG;AAAA,IACH,aAAa,OAAO,IAAI,WAAW;AACjC,aAAO,OAAO,yCAAyB,EAAE;AAAA,QAAQ,CAACC,kBAChD,sCAAwB,EAAE,IAAI,MAAMA,UAAS,MAAM,QAAQ,UAAAA,UAAS,CAAC;AAAA,MACvE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAWA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,aAAO,wBAAS;AAAA,IACd,MAAM,YAAY,IAAI;AAAA,IACtB;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model","openAICompatible","modelRef"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
modelActionMetadata,
|
|
3
|
+
modelRef
|
|
4
|
+
} from "genkit";
|
|
5
|
+
import { logger } from "genkit/logging";
|
|
6
|
+
import openAICompatible from "../index.js";
|
|
7
|
+
import {
|
|
8
|
+
ChatCompletionCommonConfigSchema,
|
|
9
|
+
defineCompatOpenAIModel
|
|
10
|
+
} from "../model.js";
|
|
11
|
+
import { SUPPORTED_DEEPSEEK_MODELS } from "./deepseek.js";
|
|
12
|
+
const resolver = async (ai, client, actionType, actionName) => {
|
|
13
|
+
if (actionType === "model") {
|
|
14
|
+
defineCompatOpenAIModel({
|
|
15
|
+
ai,
|
|
16
|
+
name: `deepseek/${actionName}`,
|
|
17
|
+
client
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
logger.warn("Only model actions are supported by the DeepSeek plugin");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const listActions = async (client) => {
|
|
24
|
+
return await client.models.list().then(
|
|
25
|
+
(response) => response.data.filter((model2) => model2.object === "model").map((model2) => {
|
|
26
|
+
return modelActionMetadata({
|
|
27
|
+
name: `deepseek/${model2.id}`,
|
|
28
|
+
configSchema: ChatCompletionCommonConfigSchema,
|
|
29
|
+
info: SUPPORTED_DEEPSEEK_MODELS[model2.id]?.info
|
|
30
|
+
});
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
function deepSeekPlugin(options) {
|
|
35
|
+
return openAICompatible({
|
|
36
|
+
name: "deepseek",
|
|
37
|
+
baseURL: "https://api.deepseek.com",
|
|
38
|
+
...options,
|
|
39
|
+
initializer: async (ai, client) => {
|
|
40
|
+
Object.values(SUPPORTED_DEEPSEEK_MODELS).forEach(
|
|
41
|
+
(modelRef2) => defineCompatOpenAIModel({ ai, name: modelRef2.name, client, modelRef: modelRef2 })
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
resolver,
|
|
45
|
+
listActions
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const model = (name, config) => {
|
|
49
|
+
return modelRef({
|
|
50
|
+
name: `deepseek/${name}`,
|
|
51
|
+
config,
|
|
52
|
+
configSchema: ChatCompletionCommonConfigSchema
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const deepSeek = Object.assign(deepSeekPlugin, {
|
|
56
|
+
model
|
|
57
|
+
});
|
|
58
|
+
var deepseek_default = deepSeek;
|
|
59
|
+
export {
|
|
60
|
+
deepSeek,
|
|
61
|
+
deepSeekPlugin,
|
|
62
|
+
deepseek_default as default
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/deepseek/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ActionMetadata,\n Genkit,\n modelActionMetadata,\n modelRef,\n ModelReference,\n z,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { GenkitPlugin } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport OpenAI from 'openai';\nimport openAICompatible, { PluginOptions } from '../index.js';\nimport {\n ChatCompletionCommonConfigSchema,\n defineCompatOpenAIModel,\n} from '../model.js';\nimport { SUPPORTED_DEEPSEEK_MODELS } from './deepseek.js';\n\nexport type DeepSeekPluginOptions = Omit<PluginOptions, 'name' | 'baseURL'>;\n\nconst resolver = async (\n ai: Genkit,\n client: OpenAI,\n actionType: ActionType,\n actionName: string\n) => {\n if (actionType === 'model') {\n defineCompatOpenAIModel({\n ai,\n name: `deepseek/${actionName}`,\n client,\n });\n } else {\n logger.warn('Only model actions are supported by the DeepSeek plugin');\n }\n};\n\nconst listActions = async (client: OpenAI): Promise<ActionMetadata[]> => {\n return await client.models.list().then((response) =>\n response.data\n .filter((model) => model.object === 'model')\n .map((model: OpenAI.Model) => {\n return modelActionMetadata({\n name: `deepseek/${model.id}`,\n configSchema: ChatCompletionCommonConfigSchema,\n info: SUPPORTED_DEEPSEEK_MODELS[model.id]?.info,\n });\n })\n );\n};\n\nexport function deepSeekPlugin(options?: DeepSeekPluginOptions): GenkitPlugin {\n return openAICompatible({\n name: 'deepseek',\n baseURL: 'https://api.deepseek.com',\n ...options,\n initializer: async (ai, client) => {\n Object.values(SUPPORTED_DEEPSEEK_MODELS).forEach((modelRef) =>\n defineCompatOpenAIModel({ ai, name: modelRef.name, client, modelRef })\n );\n },\n resolver,\n listActions,\n });\n}\n\nexport type DeepSeekPlugin = {\n (params?: DeepSeekPluginOptions): GenkitPlugin;\n model(\n name: keyof typeof SUPPORTED_DEEPSEEK_MODELS,\n config?: z.infer<typeof ChatCompletionCommonConfigSchema>\n ): ModelReference<typeof ChatCompletionCommonConfigSchema>;\n model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nconst model = ((name: string, config?: any): ModelReference<z.ZodTypeAny> => {\n return modelRef({\n name: `deepseek/${name}`,\n config,\n configSchema: ChatCompletionCommonConfigSchema,\n });\n}) as DeepSeekPlugin['model'];\n\n/**\n * This module provides an interface to the DeepSeek models through the Genkit\n * plugin system. It allows users to interact with various models by providing\n * an API key and optional configuration.\n *\n * The main export is the `deepseek` plugin, which can be configured with an API\n * key either directly or through environment variables. It initializes the\n * OpenAI client and makes available the models for use.\n *\n * Exports:\n * - deepSeek: The main plugin function to interact with DeepSeek, via OpenAI\n * compatible API.\n *\n * Usage: To use the models, initialize the deepseek plugin inside\n * `configureGenkit` and pass the configuration options. If no API key is\n * provided in the options, the environment variable `OPENAI_API_KEY` must be\n * set.\n *\n * Example:\n * ```\n * import { deepSeek } from '@genkit-ai/compat-oai/deepseek';\n *\n * export default configureGenkit({\n * plugins: [\n * deepSeek()\n * ... // other plugins\n * ]\n * });\n * ```\n */\nexport const deepSeek: DeepSeekPlugin = Object.assign(deepSeekPlugin, {\n model,\n});\n\nexport default deepSeek;\n"],"mappings":"AAgBA;AAAA,EAGE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,cAAc;AAIvB,OAAO,sBAAyC;AAChD;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;AAI1C,MAAM,WAAW,OACf,IACA,QACA,YACA,eACG;AACH,MAAI,eAAe,SAAS;AAC1B,4BAAwB;AAAA,MACtB;AAAA,MACA,MAAM,YAAY,UAAU;AAAA,MAC5B;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,WAAO,KAAK,yDAAyD;AAAA,EACvE;AACF;AAEA,MAAM,cAAc,OAAO,WAA8C;AACvE,SAAO,MAAM,OAAO,OAAO,KAAK,EAAE;AAAA,IAAK,CAAC,aACtC,SAAS,KACN,OAAO,CAACA,WAAUA,OAAM,WAAW,OAAO,EAC1C,IAAI,CAACA,WAAwB;AAC5B,aAAO,oBAAoB;AAAA,QACzB,MAAM,YAAYA,OAAM,EAAE;AAAA,QAC1B,cAAc;AAAA,QACd,MAAM,0BAA0BA,OAAM,EAAE,GAAG;AAAA,MAC7C,CAAC;AAAA,IACH,CAAC;AAAA,EACL;AACF;AAEO,SAAS,eAAe,SAA+C;AAC5E,SAAO,iBAAiB;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,GAAG;AAAA,IACH,aAAa,OAAO,IAAI,WAAW;AACjC,aAAO,OAAO,yBAAyB,EAAE;AAAA,QAAQ,CAACC,cAChD,wBAAwB,EAAE,IAAI,MAAMA,UAAS,MAAM,QAAQ,UAAAA,UAAS,CAAC;AAAA,MACvE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAWA,MAAM,QAAS,CAAC,MAAc,WAA+C;AAC3E,SAAO,SAAS;AAAA,IACd,MAAM,YAAY,IAAI;AAAA,IACtB;AAAA,IACA,cAAc;AAAA,EAChB,CAAC;AACH;AAgCO,MAAM,WAA2B,OAAO,OAAO,gBAAgB;AAAA,EACpE;AACF,CAAC;AAED,IAAO,mBAAQ;","names":["model","modelRef"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Genkit, EmbedderReference, EmbedderAction } from 'genkit';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright 2024 The Fire Company
|
|
6
|
+
* Copyright 2024 Google LLC
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Method to define a new Genkit Embedder that is compatibale with the Open AI
|
|
23
|
+
* Embeddings API.
|
|
24
|
+
*
|
|
25
|
+
* @param params An object containing parameters for defining the OpenAI embedder.
|
|
26
|
+
* @param params.ai The Genkit AI instance.
|
|
27
|
+
* @param params.name The name of the embedder.
|
|
28
|
+
* @param params.client The OpenAI client instance.
|
|
29
|
+
* @param params.embedderRef Optional reference to the embedder's configuration and
|
|
30
|
+
* custom options.
|
|
31
|
+
|
|
32
|
+
* @returns the created {@link EmbedderAction}
|
|
33
|
+
*/
|
|
34
|
+
declare function defineCompatOpenAIEmbedder(params: {
|
|
35
|
+
ai: Genkit;
|
|
36
|
+
name: string;
|
|
37
|
+
client: OpenAI;
|
|
38
|
+
embedderRef?: EmbedderReference;
|
|
39
|
+
}): EmbedderAction;
|
|
40
|
+
|
|
41
|
+
export { defineCompatOpenAIEmbedder };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Genkit, EmbedderReference, EmbedderAction } from 'genkit';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright 2024 The Fire Company
|
|
6
|
+
* Copyright 2024 Google LLC
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Method to define a new Genkit Embedder that is compatibale with the Open AI
|
|
23
|
+
* Embeddings API.
|
|
24
|
+
*
|
|
25
|
+
* @param params An object containing parameters for defining the OpenAI embedder.
|
|
26
|
+
* @param params.ai The Genkit AI instance.
|
|
27
|
+
* @param params.name The name of the embedder.
|
|
28
|
+
* @param params.client The OpenAI client instance.
|
|
29
|
+
* @param params.embedderRef Optional reference to the embedder's configuration and
|
|
30
|
+
* custom options.
|
|
31
|
+
|
|
32
|
+
* @returns the created {@link EmbedderAction}
|
|
33
|
+
*/
|
|
34
|
+
declare function defineCompatOpenAIEmbedder(params: {
|
|
35
|
+
ai: Genkit;
|
|
36
|
+
name: string;
|
|
37
|
+
client: OpenAI;
|
|
38
|
+
embedderRef?: EmbedderReference;
|
|
39
|
+
}): EmbedderAction;
|
|
40
|
+
|
|
41
|
+
export { defineCompatOpenAIEmbedder };
|
package/lib/embedder.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var embedder_exports = {};
|
|
20
|
+
__export(embedder_exports, {
|
|
21
|
+
defineCompatOpenAIEmbedder: () => defineCompatOpenAIEmbedder
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(embedder_exports);
|
|
24
|
+
function defineCompatOpenAIEmbedder(params) {
|
|
25
|
+
const { ai, name, client, embedderRef } = params;
|
|
26
|
+
const model = name.split("/").pop();
|
|
27
|
+
return ai.defineEmbedder(
|
|
28
|
+
{
|
|
29
|
+
name,
|
|
30
|
+
configSchema: embedderRef?.configSchema,
|
|
31
|
+
...embedderRef?.info
|
|
32
|
+
},
|
|
33
|
+
async (input, options) => {
|
|
34
|
+
const { encodingFormat: encoding_format, ...restOfConfig } = options;
|
|
35
|
+
const embeddings = await client.embeddings.create({
|
|
36
|
+
model,
|
|
37
|
+
input: input.map((d) => d.text),
|
|
38
|
+
encoding_format,
|
|
39
|
+
...restOfConfig
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
embeddings: embeddings.data.map((d) => ({ embedding: d.embedding }))
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
defineCompatOpenAIEmbedder
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=embedder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/embedder.ts"],"sourcesContent":["/**\n * Copyright 2024 The Fire Company\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// import { defineEmbedder, embedderRef } from '@genkit-ai/ai/embedder';\n\nimport type { EmbedderAction, EmbedderReference, Genkit } from 'genkit';\nimport OpenAI from 'openai';\n\n/**\n * Method to define a new Genkit Embedder that is compatibale with the Open AI\n * Embeddings API. \n *\n * @param params An object containing parameters for defining the OpenAI embedder.\n * @param params.ai The Genkit AI instance.\n * @param params.name The name of the embedder.\n * @param params.client The OpenAI client instance.\n * @param params.embedderRef Optional reference to the embedder's configuration and\n * custom options.\n\n * @returns the created {@link EmbedderAction}\n */\nexport function defineCompatOpenAIEmbedder(params: {\n ai: Genkit;\n name: string;\n client: OpenAI;\n embedderRef?: EmbedderReference;\n}): EmbedderAction {\n const { ai, name, client, embedderRef } = params;\n const model = name.split('/').pop();\n return ai.defineEmbedder(\n {\n name,\n configSchema: embedderRef?.configSchema,\n ...embedderRef?.info,\n },\n async (input, options) => {\n const { encodingFormat: encoding_format, ...restOfConfig } = options;\n const embeddings = await client.embeddings.create({\n model: model!,\n input: input.map((d) => d.text),\n encoding_format,\n ...restOfConfig,\n });\n return {\n embeddings: embeddings.data.map((d) => ({ embedding: d.embedding })),\n };\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCO,SAAS,2BAA2B,QAKxB;AACjB,QAAM,EAAE,IAAI,MAAM,QAAQ,YAAY,IAAI;AAC1C,QAAM,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAClC,SAAO,GAAG;AAAA,IACR;AAAA,MACE;AAAA,MACA,cAAc,aAAa;AAAA,MAC3B,GAAG,aAAa;AAAA,IAClB;AAAA,IACA,OAAO,OAAO,YAAY;AACxB,YAAM,EAAE,gBAAgB,iBAAiB,GAAG,aAAa,IAAI;AAC7D,YAAM,aAAa,MAAM,OAAO,WAAW,OAAO;AAAA,QAChD;AAAA,QACA,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,QAC9B;AAAA,QACA,GAAG;AAAA,MACL,CAAC;AACD,aAAO;AAAA,QACL,YAAY,WAAW,KAAK,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/lib/embedder.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function defineCompatOpenAIEmbedder(params) {
|
|
2
|
+
const { ai, name, client, embedderRef } = params;
|
|
3
|
+
const model = name.split("/").pop();
|
|
4
|
+
return ai.defineEmbedder(
|
|
5
|
+
{
|
|
6
|
+
name,
|
|
7
|
+
configSchema: embedderRef?.configSchema,
|
|
8
|
+
...embedderRef?.info
|
|
9
|
+
},
|
|
10
|
+
async (input, options) => {
|
|
11
|
+
const { encodingFormat: encoding_format, ...restOfConfig } = options;
|
|
12
|
+
const embeddings = await client.embeddings.create({
|
|
13
|
+
model,
|
|
14
|
+
input: input.map((d) => d.text),
|
|
15
|
+
encoding_format,
|
|
16
|
+
...restOfConfig
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
embeddings: embeddings.data.map((d) => ({ embedding: d.embedding }))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
defineCompatOpenAIEmbedder
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=embedder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/embedder.ts"],"sourcesContent":["/**\n * Copyright 2024 The Fire Company\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// import { defineEmbedder, embedderRef } from '@genkit-ai/ai/embedder';\n\nimport type { EmbedderAction, EmbedderReference, Genkit } from 'genkit';\nimport OpenAI from 'openai';\n\n/**\n * Method to define a new Genkit Embedder that is compatibale with the Open AI\n * Embeddings API. \n *\n * @param params An object containing parameters for defining the OpenAI embedder.\n * @param params.ai The Genkit AI instance.\n * @param params.name The name of the embedder.\n * @param params.client The OpenAI client instance.\n * @param params.embedderRef Optional reference to the embedder's configuration and\n * custom options.\n\n * @returns the created {@link EmbedderAction}\n */\nexport function defineCompatOpenAIEmbedder(params: {\n ai: Genkit;\n name: string;\n client: OpenAI;\n embedderRef?: EmbedderReference;\n}): EmbedderAction {\n const { ai, name, client, embedderRef } = params;\n const model = name.split('/').pop();\n return ai.defineEmbedder(\n {\n name,\n configSchema: embedderRef?.configSchema,\n ...embedderRef?.info,\n },\n async (input, options) => {\n const { encodingFormat: encoding_format, ...restOfConfig } = options;\n const embeddings = await client.embeddings.create({\n model: model!,\n input: input.map((d) => d.text),\n encoding_format,\n ...restOfConfig,\n });\n return {\n embeddings: embeddings.data.map((d) => ({ embedding: d.embedding })),\n };\n }\n );\n}\n"],"mappings":"AAmCO,SAAS,2BAA2B,QAKxB;AACjB,QAAM,EAAE,IAAI,MAAM,QAAQ,YAAY,IAAI;AAC1C,QAAM,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAClC,SAAO,GAAG;AAAA,IACR;AAAA,MACE;AAAA,MACA,cAAc,aAAa;AAAA,MAC3B,GAAG,aAAa;AAAA,IAClB;AAAA,IACA,OAAO,OAAO,YAAY;AACxB,YAAM,EAAE,gBAAgB,iBAAiB,GAAG,aAAa,IAAI;AAC7D,YAAM,aAAa,MAAM,OAAO,WAAW,OAAO;AAAA,QAChD;AAAA,QACA,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,QAC9B;AAAA,QACA,GAAG;AAAA,MACL,CAAC;AACD,aAAO;AAAA,QACL,YAAY,WAAW,KAAK,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/lib/image.d.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z, Genkit, ModelReference } from 'genkit';
|
|
2
|
+
import { ModelInfo, ModelAction } from 'genkit/model';
|
|
3
|
+
import OpenAI from 'openai';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyright 2024 The Fire Company
|
|
7
|
+
* Copyright 2024 Google LLC
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
declare const IMAGE_GENERATION_MODEL_INFO: ModelInfo;
|
|
23
|
+
declare const ImageGenerationCommonConfigSchema: z.ZodObject<{
|
|
24
|
+
size: z.ZodOptional<z.ZodEnum<["1024x1024", "1792x1024", "1024x1792"]>>;
|
|
25
|
+
style: z.ZodOptional<z.ZodEnum<["vivid", "natural"]>>;
|
|
26
|
+
user: z.ZodOptional<z.ZodString>;
|
|
27
|
+
n: z.ZodDefault<z.ZodNumber>;
|
|
28
|
+
quality: z.ZodOptional<z.ZodEnum<["standard", "hd"]>>;
|
|
29
|
+
response_format: z.ZodOptional<z.ZodEnum<["b64_json", "url"]>>;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
n: number;
|
|
32
|
+
size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
|
|
33
|
+
style?: "vivid" | "natural" | undefined;
|
|
34
|
+
user?: string | undefined;
|
|
35
|
+
quality?: "standard" | "hd" | undefined;
|
|
36
|
+
response_format?: "b64_json" | "url" | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
size?: "1024x1024" | "1792x1024" | "1024x1792" | undefined;
|
|
39
|
+
style?: "vivid" | "natural" | undefined;
|
|
40
|
+
user?: string | undefined;
|
|
41
|
+
n?: number | undefined;
|
|
42
|
+
quality?: "standard" | "hd" | undefined;
|
|
43
|
+
response_format?: "b64_json" | "url" | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Method to define a new Genkit Model that is compatible with Open AI
|
|
47
|
+
* Images API.
|
|
48
|
+
*
|
|
49
|
+
* These models are to be used to create images from a user prompt.
|
|
50
|
+
*
|
|
51
|
+
* @param params An object containing parameters for defining the OpenAI
|
|
52
|
+
* image model.
|
|
53
|
+
* @param params.ai The Genkit AI instance.
|
|
54
|
+
* @param params.name The name of the model.
|
|
55
|
+
* @param params.client The OpenAI client instance.
|
|
56
|
+
* @param params.modelRef Optional reference to the model's configuration and
|
|
57
|
+
* custom options.
|
|
58
|
+
|
|
59
|
+
* @returns the created {@link ModelAction}
|
|
60
|
+
*/
|
|
61
|
+
declare function defineCompatOpenAIImageModel<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny>(params: {
|
|
62
|
+
ai: Genkit;
|
|
63
|
+
name: string;
|
|
64
|
+
client: OpenAI;
|
|
65
|
+
modelRef?: ModelReference<CustomOptions>;
|
|
66
|
+
}): ModelAction<CustomOptions>;
|
|
67
|
+
|
|
68
|
+
export { IMAGE_GENERATION_MODEL_INFO, ImageGenerationCommonConfigSchema, defineCompatOpenAIImageModel };
|