@aj-archipelago/cortex 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.js +47 -11
- package/helper-apps/cortex-autogen/OAI_CONFIG_LIST +2 -1
- package/helper-apps/cortex-autogen/agents.py +387 -0
- package/helper-apps/cortex-autogen/agents_extra.py +14 -0
- package/helper-apps/cortex-autogen/config.py +18 -0
- package/helper-apps/cortex-autogen/data_operations.py +29 -0
- package/helper-apps/cortex-autogen/function_app.py +6 -3
- package/helper-apps/cortex-autogen/main.py +4 -4
- package/helper-apps/cortex-autogen/prompts.py +196 -0
- package/helper-apps/cortex-autogen/prompts_extra.py +5 -0
- package/helper-apps/cortex-autogen/requirements.txt +2 -1
- package/helper-apps/cortex-autogen/search.py +83 -0
- package/helper-apps/cortex-autogen/test.sh +40 -0
- package/helper-apps/cortex-autogen/utils.py +78 -0
- package/lib/handleBars.js +25 -0
- package/lib/logger.js +2 -0
- package/lib/util.js +3 -1
- package/package.json +1 -1
- package/pathways/chat_code.js +1 -1
- package/pathways/chat_context.js +1 -1
- package/pathways/chat_jarvis.js +1 -1
- package/pathways/chat_persist.js +1 -1
- package/pathways/chat_title.js +25 -0
- package/pathways/{flux_image.js → image_flux.js} +6 -2
- package/pathways/image_recraft.js +10 -0
- package/pathways/rag.js +1 -1
- package/pathways/rag_jarvis.js +1 -1
- package/pathways/rag_search_helper.js +1 -1
- package/pathways/system/entity/memory/sys_memory_manager.js +71 -0
- package/pathways/system/entity/memory/sys_memory_required.js +21 -0
- package/pathways/system/entity/memory/sys_memory_update.js +190 -0
- package/pathways/system/entity/memory/sys_read_memory.js +37 -0
- package/pathways/system/entity/memory/sys_save_memory.js +60 -0
- package/pathways/system/entity/shared/sys_entity_constants.js +24 -0
- package/pathways/system/entity/sys_entity_continue.js +57 -0
- package/pathways/system/entity/sys_entity_start.js +218 -0
- package/pathways/system/entity/sys_generator_error.js +20 -0
- package/pathways/system/entity/sys_generator_expert.js +26 -0
- package/pathways/system/entity/sys_generator_image.js +127 -0
- package/pathways/system/entity/sys_generator_quick.js +19 -0
- package/pathways/system/entity/sys_generator_reasoning.js +27 -0
- package/pathways/system/entity/sys_generator_results.js +304 -0
- package/pathways/system/entity/sys_generator_video_vision.js +27 -0
- package/pathways/system/entity/sys_image_prompt_builder.js +35 -0
- package/pathways/system/entity/sys_query_builder.js +101 -0
- package/pathways/system/entity/sys_router_code.js +37 -0
- package/pathways/system/entity/sys_router_tool.js +64 -0
- package/pathways/{sys_claude_35_sonnet.js → system/rest_streaming/sys_claude_35_sonnet.js} +1 -1
- package/pathways/{sys_claude_3_haiku.js → system/rest_streaming/sys_claude_3_haiku.js} +1 -1
- package/pathways/{sys_google_chat.js → system/rest_streaming/sys_google_chat.js} +1 -1
- package/pathways/{sys_google_code_chat.js → system/rest_streaming/sys_google_code_chat.js} +1 -1
- package/pathways/{sys_google_gemini_chat.js → system/rest_streaming/sys_google_gemini_chat.js} +1 -1
- package/pathways/{sys_openai_chat.js → system/rest_streaming/sys_openai_chat.js} +1 -1
- package/pathways/{sys_openai_chat_16.js → system/rest_streaming/sys_openai_chat_16.js} +1 -1
- package/pathways/{sys_openai_chat_gpt4.js → system/rest_streaming/sys_openai_chat_gpt4.js} +1 -1
- package/pathways/{sys_openai_chat_gpt4_32.js → system/rest_streaming/sys_openai_chat_gpt4_32.js} +1 -1
- package/pathways/{sys_openai_chat_gpt4_turbo.js → system/rest_streaming/sys_openai_chat_gpt4_turbo.js} +1 -1
- package/pathways/{sys_parse_numbered_object_list.js → system/sys_parse_numbered_object_list.js} +2 -2
- package/pathways/{sys_repair_json.js → system/sys_repair_json.js} +1 -1
- package/pathways/{run_claude35_sonnet.js → system/workspaces/run_claude35_sonnet.js} +1 -1
- package/pathways/{run_claude3_haiku.js → system/workspaces/run_claude3_haiku.js} +1 -1
- package/pathways/{run_gpt35turbo.js → system/workspaces/run_gpt35turbo.js} +1 -1
- package/pathways/{run_gpt4.js → system/workspaces/run_gpt4.js} +1 -1
- package/pathways/{run_gpt4_32.js → system/workspaces/run_gpt4_32.js} +1 -1
- package/server/parser.js +6 -1
- package/server/pathwayResolver.js +62 -10
- package/server/plugins/azureCognitivePlugin.js +14 -1
- package/server/plugins/claude3VertexPlugin.js +25 -15
- package/server/plugins/gemini15ChatPlugin.js +1 -1
- package/server/plugins/geminiChatPlugin.js +1 -1
- package/server/plugins/modelPlugin.js +10 -1
- package/server/plugins/openAiChatPlugin.js +4 -3
- package/server/plugins/openAiDallE3Plugin.js +12 -4
- package/server/plugins/openAiVisionPlugin.js +1 -2
- package/server/plugins/replicateApiPlugin.js +46 -12
- package/tests/multimodal_conversion.test.js +6 -8
- package/helper-apps/cortex-autogen/myautogen.py +0 -317
- package/helper-apps/cortex-autogen/prompt.txt +0 -0
- package/helper-apps/cortex-autogen/prompt_summary.txt +0 -37
- package/pathways/index.js +0 -152
- /package/pathways/{sys_openai_completion.js → system/rest_streaming/sys_openai_completion.js} +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// sys_entity_start.js
|
|
2
|
+
// Beginning of the rag workflow for Jarvis
|
|
3
|
+
import { callPathway } from '../../../lib/pathwayTools.js';
|
|
4
|
+
import logger from '../../../lib/logger.js';
|
|
5
|
+
import { chatArgsHasImageUrl } from '../../../lib/util.js';
|
|
6
|
+
import { QueueServiceClient } from '@azure/storage-queue';
|
|
7
|
+
import entityConstants from './shared/sys_entity_constants.js';
|
|
8
|
+
|
|
9
|
+
const TOKEN_RATIO = 0.75;
|
|
10
|
+
|
|
11
|
+
const connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING;
|
|
12
|
+
let queueClient;
|
|
13
|
+
|
|
14
|
+
if (connectionString) {
|
|
15
|
+
const queueName = process.env.AUTOGEN_MESSAGE_QUEUE || "autogen-message-queue";
|
|
16
|
+
const queueClientService = QueueServiceClient.fromConnectionString(connectionString);
|
|
17
|
+
queueClient = queueClientService.getQueueClient(queueName);
|
|
18
|
+
} else {
|
|
19
|
+
logger.warn("Azure Storage connection string is not provided. Queue operations will be unavailable.");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function sendMessageToQueue(data) {
|
|
23
|
+
try {
|
|
24
|
+
if(!queueClient){
|
|
25
|
+
logger.warn("Azure Storage connection string is not provided. Queue operations will be unavailable.");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const encodedMessage = Buffer.from(JSON.stringify(data)).toString('base64');
|
|
29
|
+
const result = await queueClient.sendMessage(encodedMessage);
|
|
30
|
+
logger.info(`Message added to queue: ${JSON.stringify(result)}`);
|
|
31
|
+
return result.messageId;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error("Error sending message:", error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
useInputChunking: false,
|
|
39
|
+
enableDuplicateRequests: false,
|
|
40
|
+
model: 'oai-gpt4o',
|
|
41
|
+
anthropicModel: 'claude-35-sonnet-vertex',
|
|
42
|
+
openAIModel: 'oai-gpt4o',
|
|
43
|
+
inputParameters: {
|
|
44
|
+
privateData: false,
|
|
45
|
+
chatHistory: [{role: '', content: []}],
|
|
46
|
+
contextId: ``,
|
|
47
|
+
indexName: ``,
|
|
48
|
+
semanticConfiguration: ``,
|
|
49
|
+
roleInformation: ``,
|
|
50
|
+
calculateEmbeddings: false,
|
|
51
|
+
dataSources: ["mydata", "aja", "aje", "wires", "bing"],
|
|
52
|
+
language: "English",
|
|
53
|
+
aiName: "Jarvis",
|
|
54
|
+
aiMemorySelfModify: true,
|
|
55
|
+
aiStyle: "OpenAI",
|
|
56
|
+
title: ``,
|
|
57
|
+
},
|
|
58
|
+
timeout: 600,
|
|
59
|
+
tokenRatio: TOKEN_RATIO,
|
|
60
|
+
...entityConstants,
|
|
61
|
+
|
|
62
|
+
executePathway: async ({args, resolver}) => {
|
|
63
|
+
let title = null;
|
|
64
|
+
let codeRequestId = null;
|
|
65
|
+
|
|
66
|
+
args = {
|
|
67
|
+
...args,
|
|
68
|
+
...entityConstants
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Limit the chat history to 20 messages to speed up processing
|
|
72
|
+
args.chatHistory = (args.messages || args.chatHistory).slice(-20);
|
|
73
|
+
const pathwayResolver = resolver;
|
|
74
|
+
const { anthropicModel, openAIModel } = pathwayResolver.pathway;
|
|
75
|
+
|
|
76
|
+
const styleModel = args.aiStyle === "Anthropic" ? anthropicModel : openAIModel;
|
|
77
|
+
|
|
78
|
+
// if the model has been overridden, make sure to use it
|
|
79
|
+
if (pathwayResolver.modelName) {
|
|
80
|
+
args.model = pathwayResolver.modelName;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const fetchChatResponse = async (args) => {
|
|
84
|
+
const [chatResponse, chatTitleResponse] = await Promise.all([
|
|
85
|
+
callPathway('sys_generator_quick', {...args, model: styleModel}),
|
|
86
|
+
callPathway('chat_title', { ...args }),
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
title = chatTitleResponse;
|
|
90
|
+
|
|
91
|
+
return chatResponse;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const { chatHistory } = args;
|
|
95
|
+
|
|
96
|
+
// start fetching the default response - we may need it later
|
|
97
|
+
const fetchChatResponsePromise = fetchChatResponse({ ...args });
|
|
98
|
+
|
|
99
|
+
const visionContentPresent = chatArgsHasImageUrl(args);
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
// Get tool routing response
|
|
103
|
+
const toolRequiredResponse = await callPathway('sys_router_tool', {
|
|
104
|
+
...args,
|
|
105
|
+
chatHistory: chatHistory.slice(-4)
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Asynchronously manage memory for this context
|
|
109
|
+
if (args.aiMemorySelfModify) {
|
|
110
|
+
callPathway('sys_memory_manager', { ...args })
|
|
111
|
+
.catch(error => logger.error(error?.message || "Error in sys_memory_manager pathway"));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const { toolRequired, toolMessage, toolFunction } = JSON.parse(toolRequiredResponse || '{}');
|
|
115
|
+
let toolCallbackName, toolCallbackId, toolCallbackMessage;
|
|
116
|
+
|
|
117
|
+
logger.info(`toolRequired: ${toolRequired}, toolFunction: ${toolFunction}`);
|
|
118
|
+
|
|
119
|
+
if (toolRequired && toolFunction) {
|
|
120
|
+
switch (toolFunction.toLowerCase()) {
|
|
121
|
+
case "codeexecution":
|
|
122
|
+
{
|
|
123
|
+
const codingRequiredResponse = await callPathway('sys_router_code', { ...args });
|
|
124
|
+
let parsedCodingRequiredResponse;
|
|
125
|
+
try {
|
|
126
|
+
parsedCodingRequiredResponse = JSON.parse(codingRequiredResponse || "{}");
|
|
127
|
+
} catch (error) {
|
|
128
|
+
logger.error(`Error parsing codingRequiredResponse: ${error.message}, codingRequiredResponse was: ${codingRequiredResponse}`);
|
|
129
|
+
parsedCodingRequiredResponse = {};
|
|
130
|
+
}
|
|
131
|
+
const { codingRequired } = parsedCodingRequiredResponse;
|
|
132
|
+
if (codingRequired) {
|
|
133
|
+
const { codingMessage, codingTask, codingTaskKeywords } = parsedCodingRequiredResponse;
|
|
134
|
+
const message = typeof codingTask === 'string'
|
|
135
|
+
? codingTask
|
|
136
|
+
: JSON.stringify(codingTask);
|
|
137
|
+
const { contextId } = args;
|
|
138
|
+
logger.info(`Sending task message coding agent: ${message}`);
|
|
139
|
+
codeRequestId = await sendMessageToQueue({ message, contextId, keywords: codingTaskKeywords });
|
|
140
|
+
|
|
141
|
+
toolCallbackId = codeRequestId;
|
|
142
|
+
toolCallbackName = "coding";
|
|
143
|
+
toolCallbackMessage = codingMessage;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
case "image":
|
|
149
|
+
toolCallbackName = 'sys_generator_image';
|
|
150
|
+
toolCallbackMessage = toolMessage;
|
|
151
|
+
break;
|
|
152
|
+
case "vision":
|
|
153
|
+
case "video":
|
|
154
|
+
case "audio":
|
|
155
|
+
case "pdf":
|
|
156
|
+
if (visionContentPresent) {
|
|
157
|
+
toolCallbackName = 'sys_generator_video_vision';
|
|
158
|
+
toolCallbackMessage = toolMessage;
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
case "code":
|
|
162
|
+
case "write":
|
|
163
|
+
toolCallbackName = 'sys_generator_expert';
|
|
164
|
+
toolCallbackMessage = toolMessage;
|
|
165
|
+
break;
|
|
166
|
+
case "reason":
|
|
167
|
+
toolCallbackName = 'sys_generator_reasoning';
|
|
168
|
+
toolCallbackMessage = toolMessage;
|
|
169
|
+
break;
|
|
170
|
+
case "search":
|
|
171
|
+
toolCallbackName = 'sys_generator_results';
|
|
172
|
+
toolCallbackId = null;
|
|
173
|
+
toolCallbackMessage = toolMessage;
|
|
174
|
+
break;
|
|
175
|
+
case "document":
|
|
176
|
+
toolCallbackName = 'sys_generator_document';
|
|
177
|
+
toolCallbackId = null;
|
|
178
|
+
toolCallbackMessage = toolMessage;
|
|
179
|
+
break;
|
|
180
|
+
case "clarify":
|
|
181
|
+
toolCallbackName = null;
|
|
182
|
+
toolCallbackId = null;
|
|
183
|
+
toolCallbackMessage = toolMessage;
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
toolCallbackName = null;
|
|
187
|
+
toolCallbackId = null;
|
|
188
|
+
toolCallbackMessage = null;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (toolCallbackMessage) {
|
|
194
|
+
pathwayResolver.tool = JSON.stringify({
|
|
195
|
+
hideFromModel: toolCallbackName ? true : false,
|
|
196
|
+
toolCallbackName,
|
|
197
|
+
title,
|
|
198
|
+
search: toolCallbackName === 'sys_generator_results' ? true : false,
|
|
199
|
+
coding: toolCallbackName === 'coding' ? true : false,
|
|
200
|
+
codeRequestId,
|
|
201
|
+
toolCallbackId
|
|
202
|
+
});
|
|
203
|
+
return toolCallbackMessage || "One moment please.";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const chatResponse = await fetchChatResponsePromise;
|
|
207
|
+
pathwayResolver.tool = JSON.stringify({ search: false, title })
|
|
208
|
+
return chatResponse;
|
|
209
|
+
|
|
210
|
+
} catch (e) {
|
|
211
|
+
pathwayResolver.logError(e);
|
|
212
|
+
const chatResponse = await fetchChatResponsePromise;
|
|
213
|
+
pathwayResolver.tool = JSON.stringify({ search: false, title });
|
|
214
|
+
return chatResponse;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Prompt } from '../../../server/prompt.js';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
prompt:
|
|
5
|
+
[
|
|
6
|
+
new Prompt({ messages: [
|
|
7
|
+
{"role": "system", "content": `{{renderTemplate AI_DIRECTIVES}}\n\n{{renderTemplate AI_COMMON_INSTRUCTIONS}}\n\n{{renderTemplate AI_EXPERTISE}}\n\nThe user has requested information that you have already determined can be found in the indexes that you can search, and you were trying to search for it, but encountered the following error: {{{text}}}. Your response should be concise, fit the rest of the conversation, include detail appropriate for the technical level of the user if you can determine it, and be appropriate for the context. You cannot resolve this error.`},
|
|
8
|
+
"{{chatHistory}}",
|
|
9
|
+
]}),
|
|
10
|
+
],
|
|
11
|
+
inputParameters: {
|
|
12
|
+
chatHistory: [{role: '', content: []}],
|
|
13
|
+
contextId: ``,
|
|
14
|
+
text: '',
|
|
15
|
+
aiName: "Jarvis",
|
|
16
|
+
language: "English",
|
|
17
|
+
},
|
|
18
|
+
model: 'oai-gpt4o',
|
|
19
|
+
useInputChunking: false,
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Prompt } from '../../../server/prompt.js';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
prompt:
|
|
5
|
+
[
|
|
6
|
+
new Prompt({ messages: [
|
|
7
|
+
{"role": "system", "content": `{{renderTemplate AI_COMMON_INSTRUCTIONS}}\n{{renderTemplate AI_EXPERTISE}}\n{{renderTemplate AI_DIRECTIVES}}`},
|
|
8
|
+
"{{chatHistory}}",
|
|
9
|
+
]}),
|
|
10
|
+
],
|
|
11
|
+
inputParameters: {
|
|
12
|
+
chatHistory: [{role: '', content: []}],
|
|
13
|
+
contextId: ``,
|
|
14
|
+
aiName: "Jarvis",
|
|
15
|
+
language: "English",
|
|
16
|
+
},
|
|
17
|
+
model: 'oai-gpt4o',
|
|
18
|
+
useInputChunking: false,
|
|
19
|
+
enableDuplicateRequests: false,
|
|
20
|
+
timeout: 600,
|
|
21
|
+
executePathway: async ({args, runAllPrompts, resolver}) => {
|
|
22
|
+
const result = await runAllPrompts({ ...args });
|
|
23
|
+
resolver.tool = JSON.stringify({ toolUsed: "writing" });
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// sys_generator_image.js
|
|
2
|
+
// Entity module that creates and shows images to the user
|
|
3
|
+
import { callPathway } from '../../../lib/pathwayTools.js';
|
|
4
|
+
import { Prompt } from '../../../server/prompt.js';
|
|
5
|
+
import logger from '../../../lib/logger.js';
|
|
6
|
+
import { getUniqueId } from '../../../lib/util.js';
|
|
7
|
+
|
|
8
|
+
const TOKEN_RATIO = 1.0;
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
prompt: [],
|
|
12
|
+
useInputChunking: false,
|
|
13
|
+
enableDuplicateRequests: false,
|
|
14
|
+
inputParameters: {
|
|
15
|
+
privateData: false,
|
|
16
|
+
useMemory: true,
|
|
17
|
+
chatHistory: [{role: '', content: []}],
|
|
18
|
+
aiName: "Jarvis",
|
|
19
|
+
contextId: ``,
|
|
20
|
+
indexName: ``,
|
|
21
|
+
semanticConfiguration: ``,
|
|
22
|
+
roleInformation: ``,
|
|
23
|
+
calculateEmbeddings: false,
|
|
24
|
+
language: "English",
|
|
25
|
+
chatId: ``,
|
|
26
|
+
model: 'oai-gpt4o',
|
|
27
|
+
},
|
|
28
|
+
timeout: 300,
|
|
29
|
+
tokenRatio: TOKEN_RATIO,
|
|
30
|
+
|
|
31
|
+
executePathway: async ({args, runAllPrompts, resolver}) => {
|
|
32
|
+
|
|
33
|
+
const { chatHistory } = args;
|
|
34
|
+
|
|
35
|
+
let pathwayResolver = resolver;
|
|
36
|
+
|
|
37
|
+
const useMemory = args.useMemory || pathwayResolver.pathway.inputParameters.useMemory;
|
|
38
|
+
|
|
39
|
+
pathwayResolver.pathwayPrompt =
|
|
40
|
+
[
|
|
41
|
+
new Prompt({ messages: [
|
|
42
|
+
{
|
|
43
|
+
"role": "system",
|
|
44
|
+
"content": `{{renderTemplate AI_COMMON_INSTRUCTIONS}}
|
|
45
|
+
|
|
46
|
+
{{renderTemplate AI_DIRECTIVES}}
|
|
47
|
+
|
|
48
|
+
Instructions: As part of a conversation with the user, you have been asked to create one or more images, photos, pictures, selfies, drawings, or other visual content for the user. You have already written the prompts and created the images - links to them are in the most recent tool calls in the chat history. You should display the images in a way that is most pleasing to the user. You can use markdown or HTML and img tags to display and format the images - the UI will render either. If there are no tool results, it means you didn't successfully create any images - in that case, don't show any images and tell the user you weren't able to create images.`
|
|
49
|
+
},
|
|
50
|
+
"{{chatHistory}}",
|
|
51
|
+
]}),
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
// function to add tool_calls to the chatHistory
|
|
55
|
+
const addToolCalls= (chatHistory, imagePrompt, toolCallId) => {
|
|
56
|
+
const toolCall = {
|
|
57
|
+
"role": "assistant",
|
|
58
|
+
"tool_calls": [
|
|
59
|
+
{
|
|
60
|
+
"id": toolCallId,
|
|
61
|
+
"type": "function",
|
|
62
|
+
"function": {
|
|
63
|
+
"arguments": JSON.stringify(imagePrompt),
|
|
64
|
+
"name": "generate_image"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
};
|
|
69
|
+
chatHistory.push(toolCall);
|
|
70
|
+
return chatHistory;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// function to add tool_results to the chatHistory
|
|
74
|
+
const addToolResults = (chatHistory, imageResults, toolCallId) => {
|
|
75
|
+
const toolResult = {
|
|
76
|
+
"role": "tool",
|
|
77
|
+
"content": imageResults,
|
|
78
|
+
"tool_call_id": toolCallId
|
|
79
|
+
};
|
|
80
|
+
chatHistory.push(toolResult);
|
|
81
|
+
return chatHistory;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
|
|
86
|
+
// figure out what the user wants us to do
|
|
87
|
+
const contextInfo = chatHistory.filter(message => message.role === "user").slice(0, -1).map(message => message.content).join("\n");
|
|
88
|
+
|
|
89
|
+
const helper = await callPathway('sys_image_prompt_builder', { ...args, stream: false, useMemory, contextInfo });
|
|
90
|
+
logger.debug(`Image prompt builder response: ${helper}`);
|
|
91
|
+
const parsedHelper = JSON.parse(helper);
|
|
92
|
+
|
|
93
|
+
//parsedHelper should always be an array of objects, but in case it's a single object, we'll wrap it in an array
|
|
94
|
+
const imagePrompts = Array.isArray(parsedHelper) ? parsedHelper : [parsedHelper];
|
|
95
|
+
|
|
96
|
+
//for each image prompt, create the images
|
|
97
|
+
const imageResults = await Promise.all(imagePrompts.map(async (imagePrompt) => {
|
|
98
|
+
const { prompt, numberResults, negativePrompt, renderText, draft } = imagePrompt;
|
|
99
|
+
if (!prompt) return null;
|
|
100
|
+
|
|
101
|
+
let model = "replicate-flux-11-pro";
|
|
102
|
+
if (numberResults > 1 || draft) {
|
|
103
|
+
model = "replicate-flux-1-schnell";
|
|
104
|
+
}
|
|
105
|
+
if (renderText) {
|
|
106
|
+
return await callPathway('image_recraft', {...args, text: prompt });
|
|
107
|
+
} else {
|
|
108
|
+
return await callPathway('image_flux', {...args, text: prompt, negativePrompt, numberResults, model });
|
|
109
|
+
}
|
|
110
|
+
})).then(results => results.filter(r => r !== null));
|
|
111
|
+
|
|
112
|
+
// add the tool_calls and tool_results to the chatHistory
|
|
113
|
+
imageResults.forEach((imageResult, index) => {
|
|
114
|
+
const toolCallId = getUniqueId();
|
|
115
|
+
addToolCalls(chatHistory, imagePrompts[index], toolCallId);
|
|
116
|
+
addToolResults(chatHistory, imageResult, toolCallId);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const result = await runAllPrompts({ ...args });
|
|
120
|
+
pathwayResolver.tool = JSON.stringify({ toolUsed: "image" });
|
|
121
|
+
return result;
|
|
122
|
+
} catch (e) {
|
|
123
|
+
pathwayResolver.logError(e.message ?? e);
|
|
124
|
+
return await callPathway('sys_generator_error', { ...args, text: e.message }, pathwayResolver);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Prompt } from '../../../server/prompt.js';
|
|
2
|
+
export default {
|
|
3
|
+
prompt:
|
|
4
|
+
[
|
|
5
|
+
new Prompt({ messages: [
|
|
6
|
+
{"role": "system", "content": `{{renderTemplate AI_MEMORY}}\n\n{{renderTemplate AI_COMMON_INSTRUCTIONS}}\nThe UI also has dedicated tabs to help with document translation (translate), article writing assistance including generating headlines, summaries and doing copy editing (write), video and audio transcription (transcribe), and programming and writing code (code). If the user asks about something related to a dedicated tab, you will tell them that the tab exists and the interface will give the user the option to swap to that tab.\n{{renderTemplate AI_EXPERTISE}}\nYou have those capabilities but you have already decided it is not necessary to do any of those things to respond in this turn of the conversation.\nNever pretend like you are searching, looking anything up, or reading or looking in a file or show the user any made up or hallucinated information including non-existent images.\n{{renderTemplate AI_MEMORY_INSTRUCTIONS}}`},
|
|
7
|
+
"{{chatHistory}}",
|
|
8
|
+
]}),
|
|
9
|
+
],
|
|
10
|
+
inputParameters: {
|
|
11
|
+
chatHistory: [{role: '', content: []}],
|
|
12
|
+
contextId: ``,
|
|
13
|
+
aiName: "Jarvis",
|
|
14
|
+
language: "English",
|
|
15
|
+
model: "oai-gpt4o",
|
|
16
|
+
},
|
|
17
|
+
useInputChunking: false,
|
|
18
|
+
enableDuplicateRequests: false
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Prompt } from '../../../server/prompt.js';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
prompt:
|
|
5
|
+
[
|
|
6
|
+
new Prompt({ messages: [
|
|
7
|
+
{"role": "system", "content": `{{renderTemplate AI_COMMON_INSTRUCTIONS}}\n{{renderTemplate AI_EXPERTISE}}\n{{renderTemplate AI_DIRECTIVES}}\nUse all of the information in your memory and the chat history to reason about the user's request and provide a response. Often this information will be more current than your knowledge cutoff.`},
|
|
8
|
+
"{{chatHistory}}",
|
|
9
|
+
]}),
|
|
10
|
+
],
|
|
11
|
+
inputParameters: {
|
|
12
|
+
chatHistory: [{role: '', content: []}],
|
|
13
|
+
contextId: ``,
|
|
14
|
+
aiName: "Jarvis",
|
|
15
|
+
language: "English",
|
|
16
|
+
},
|
|
17
|
+
model: 'oai-o1-mini',
|
|
18
|
+
useInputChunking: false,
|
|
19
|
+
enableDuplicateRequests: false,
|
|
20
|
+
timeout: 600,
|
|
21
|
+
executePathway: async ({args, runAllPrompts, resolver}) => {
|
|
22
|
+
const result = await runAllPrompts({ ...args });
|
|
23
|
+
resolver.tool = JSON.stringify({ toolUsed: "reasoning" });
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|