@crewdle/mist-connector-openai 1.0.6 → 1.0.7
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.
|
@@ -31,11 +31,62 @@ export class OpenAIGenerativeAIWorkerConnector {
|
|
|
31
31
|
if (!options || !this.models.has(options.model.id)) {
|
|
32
32
|
throw new Error('Model not initialized');
|
|
33
33
|
}
|
|
34
|
+
if (options.model.outputType === 'vector') {
|
|
35
|
+
const response = await this.client.embeddings.create({
|
|
36
|
+
model: options.model.id,
|
|
37
|
+
input: parameters.prompt,
|
|
38
|
+
dimensions: 1024,
|
|
39
|
+
});
|
|
40
|
+
if (!response.data || response.data.length !== 1) {
|
|
41
|
+
throw new Error('No response data');
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
type: 'prompt',
|
|
45
|
+
output: response.data[0].embedding,
|
|
46
|
+
inputTokens: response.usage?.prompt_tokens ?? 0,
|
|
47
|
+
outputTokens: 0,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
let responseFormat;
|
|
51
|
+
if (parameters.grammar) {
|
|
52
|
+
if (parameters.grammar === 'json') {
|
|
53
|
+
responseFormat = { type: 'json_object' };
|
|
54
|
+
}
|
|
55
|
+
else if (parameters.grammar === 'if_else') {
|
|
56
|
+
responseFormat = {
|
|
57
|
+
type: 'json_schema',
|
|
58
|
+
json_schema: {
|
|
59
|
+
name: 'router_response',
|
|
60
|
+
schema: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
'condition_result': {
|
|
64
|
+
type: 'boolean',
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
required: ['result'],
|
|
68
|
+
additionalProperties: false,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else if (parameters.grammar !== 'default') {
|
|
74
|
+
responseFormat = {
|
|
75
|
+
type: 'json_schema',
|
|
76
|
+
json_schema: {
|
|
77
|
+
name: 'custom_response',
|
|
78
|
+
schema: parameters.grammar,
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const messages = this.getMessages(parameters);
|
|
34
84
|
const response = await this.client.chat.completions.create({
|
|
35
85
|
model: options.model.id,
|
|
36
|
-
messages
|
|
86
|
+
messages,
|
|
37
87
|
max_completion_tokens: parameters.maxTokens,
|
|
38
88
|
temperature: parameters.temperature,
|
|
89
|
+
response_format: responseFormat,
|
|
39
90
|
});
|
|
40
91
|
return {
|
|
41
92
|
type: 'prompt',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewdle/mist-connector-openai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dist/"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@crewdle/web-sdk-types": "^1.0.
|
|
18
|
+
"@crewdle/web-sdk-types": "^1.0.37",
|
|
19
19
|
"@types/node": "^22.13.9",
|
|
20
20
|
"typescript": "^5.8.2"
|
|
21
21
|
},
|