@aj-archipelago/cortex 1.3.36 → 1.3.37
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aj-archipelago/cortex",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.37",
|
|
4
4
|
"description": "Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -36,6 +36,10 @@ export default {
|
|
|
36
36
|
timeout: 600,
|
|
37
37
|
|
|
38
38
|
toolCallback: async (args, message, resolver) => {
|
|
39
|
+
if (!args || !message || !resolver) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
const { tool_calls } = message;
|
|
40
44
|
const pathwayResolver = resolver;
|
|
41
45
|
const { entityTools, entityToolsOpenAiFormat } = args;
|
|
@@ -170,11 +174,10 @@ export default {
|
|
|
170
174
|
|
|
171
175
|
args.chatHistory = finalMessages;
|
|
172
176
|
|
|
173
|
-
await pathwayResolver.promptAndParse({
|
|
177
|
+
return await pathwayResolver.promptAndParse({
|
|
174
178
|
...args,
|
|
175
179
|
tools: entityToolsOpenAiFormat,
|
|
176
180
|
tool_choice: "auto",
|
|
177
|
-
stream: true
|
|
178
181
|
});
|
|
179
182
|
}
|
|
180
183
|
},
|
|
@@ -183,7 +186,7 @@ export default {
|
|
|
183
186
|
let pathwayResolver = resolver;
|
|
184
187
|
|
|
185
188
|
// Load input parameters and information into args
|
|
186
|
-
const { entityId, voiceResponse, aiMemorySelfModify } = { ...pathwayResolver.pathway.inputParameters, ...args };
|
|
189
|
+
const { entityId, voiceResponse, aiMemorySelfModify, stream } = { ...pathwayResolver.pathway.inputParameters, ...args };
|
|
187
190
|
|
|
188
191
|
const entityConfig = loadEntityConfig(entityId);
|
|
189
192
|
const { entityTools, entityToolsOpenAiFormat } = getToolsForEntity(entityConfig);
|
|
@@ -267,14 +270,17 @@ export default {
|
|
|
267
270
|
let currentMessages = JSON.parse(JSON.stringify(args.chatHistory));
|
|
268
271
|
|
|
269
272
|
// Run the initial prompt with streaming
|
|
270
|
-
|
|
273
|
+
let response = await runAllPrompts({
|
|
271
274
|
...args,
|
|
272
275
|
chatHistory: currentMessages,
|
|
273
276
|
tools: entityToolsOpenAiFormat,
|
|
274
|
-
tool_choice: "auto"
|
|
275
|
-
stream: true
|
|
277
|
+
tool_choice: "auto"
|
|
276
278
|
});
|
|
277
279
|
|
|
280
|
+
let toolCallback = pathwayResolver.pathway.toolCallback;
|
|
281
|
+
while (response?.tool_calls) {
|
|
282
|
+
response = await toolCallback(args, response, resolver);
|
|
283
|
+
}
|
|
278
284
|
|
|
279
285
|
// Return the final response
|
|
280
286
|
return response;
|
|
@@ -266,7 +266,7 @@ class OpenAIVisionPlugin extends OpenAIChatPlugin {
|
|
|
266
266
|
switch (finishReason.toLowerCase()) {
|
|
267
267
|
case 'tool_calls':
|
|
268
268
|
// Process complete tool calls when we get the finish reason
|
|
269
|
-
if (this.pathwayToolCallback && this.toolCallsBuffer.length > 0) {
|
|
269
|
+
if (this.pathwayToolCallback && this.toolCallsBuffer.length > 0 && pathwayResolver) {
|
|
270
270
|
const toolMessage = {
|
|
271
271
|
role: 'assistant',
|
|
272
272
|
content: delta?.content || '',
|