@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,196 @@
|
|
|
1
|
+
|
|
2
|
+
JSON_RETURN_SYSTEM_MESSAGE = """
|
|
3
|
+
|
|
4
|
+
When generating JSON:
|
|
5
|
+
1. Do not use markdown code blocks or language indicators
|
|
6
|
+
2. Use double quotes for keys and string values
|
|
7
|
+
3. Don't use trailing commas
|
|
8
|
+
4. Properly close all brackets and braces
|
|
9
|
+
5. Escape special characters in strings
|
|
10
|
+
6. Use only valid JSON data types
|
|
11
|
+
7. Validate the JSON before returning
|
|
12
|
+
8. Ensure the entire response is valid JSON
|
|
13
|
+
9. Do not include any text before or after the JSON object
|
|
14
|
+
10. Your output will be read by json_object = json.loads(json_string) as is, make sure it is valid json.
|
|
15
|
+
11. Must not put any ```json or \n or any other markdown or new line characters in the response.
|
|
16
|
+
13. Do not include any comments or side notes in the JSON response, it should be a clean JSON object.
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
TASK_COMPLETE_CHECKER_SYSTEM_MESSAGE = """
|
|
21
|
+
You are an intelligent task evaluation agent with the ability to assess task completion based on given context. Your role is to determine whether a presented task can be considered completed, or if it requires additional work.
|
|
22
|
+
|
|
23
|
+
After carefully analyzing the task and its context, respond with one of the following:
|
|
24
|
+
|
|
25
|
+
1. If the task is complete and can be presented as is:
|
|
26
|
+
Reply with "DONE"
|
|
27
|
+
|
|
28
|
+
2. If the task needs further work or clarification:
|
|
29
|
+
Reply with "INCOMPLETE: [Concise list of remaining items or areas needing attention]"
|
|
30
|
+
|
|
31
|
+
Ensure your assessment is thorough and consider all aspects of the task, including quality, completeness, and alignment with the original requirements. Provide clear and concise feedback in your response to guide any necessary follow-up actions.
|
|
32
|
+
|
|
33
|
+
If DONE only reply with single word DONE User will just check exact equality to DONE.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
PYTHON_CODER_SYSTEM_MESSAGE = """
|
|
38
|
+
|
|
39
|
+
When writing Python code:
|
|
40
|
+
1. Ensure consistent indentation (typically 4 spaces).
|
|
41
|
+
2. Properly nest code blocks within functions and control structures.
|
|
42
|
+
3. Align try-except blocks with the surrounding code.
|
|
43
|
+
4. Double check your code for proper indentation before running.
|
|
44
|
+
5. Avoid hardcoding values when possible.
|
|
45
|
+
6. Ensure the code is error-free before submitting.
|
|
46
|
+
7. Make sure to handle cases of empty data, before causing any further issues.
|
|
47
|
+
|
|
48
|
+
Refer to the official API documentation to ensure that the parameters and their formats are used correctly if you are stuck.
|
|
49
|
+
Add comprehensive error handling and logging to your scripts to make easier to follow if something goes wrong.
|
|
50
|
+
Keep your API keys and URLs secure and ensure they are correctly set in your environment variables before running the script.
|
|
51
|
+
Regularly review and update your code to align with any changes or deprecations in the API versions you are using.
|
|
52
|
+
|
|
53
|
+
When dealing with non-ASCII characters, it's crucial to ensure that the file is saved with the correct encoding and that the Python environment interprets the characters correctly.
|
|
54
|
+
|
|
55
|
+
Consider language specific libraries and tools that can be used. e.g. for Arabic you might need to reshape the text before displaying it.
|
|
56
|
+
Make sure to install all the required packages before running the code.
|
|
57
|
+
Never skip this step, as it is essential for the code to run successfully.
|
|
58
|
+
|
|
59
|
+
NEVER put anything other than code in between ``` otherwise user will try to run it.
|
|
60
|
+
|
|
61
|
+
User will run your code as is, so make sure it is complete and error-free.
|
|
62
|
+
Never ask the user to modify the code, always provide a complete and working solution.
|
|
63
|
+
Never ask for user any input for your code, as the user will not be able to provide it.
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
NEVER_HALLUCINATE_SYSTEM_MESSAGE = """
|
|
68
|
+
|
|
69
|
+
Never make up any information or data. Always use real information and data.
|
|
70
|
+
Never use stuff like example.com or so. Always use real and valid data.
|
|
71
|
+
Never use any placeholder data, always use real data.
|
|
72
|
+
Never use any placeholder names, numbers, or any other data.
|
|
73
|
+
|
|
74
|
+
You must apply these rules if user not specifically asked for a placeholder or example data!
|
|
75
|
+
You must consider this as a strict rule and follow it.
|
|
76
|
+
You must follow these rules in all tasks and all responses.
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
CODE_CORRECTOR_PROMPTER_SYSTEM_MESSAGE = f"""
|
|
81
|
+
|
|
82
|
+
You will be given executed codes both failed and successful ones. You need to analyze the it and reason out what caused the error in the failed code and what corrected in the successful one. You will also need to write a prompt that it never happens again.
|
|
83
|
+
|
|
84
|
+
Start your reply with a one or two sentence summary. Then, provide a detailed explanation of the error in the failed code and the correction in the successful code. Finally, write a prompt to ensure the error does not occur again.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
PLANNER_SYSTEM_MESSAGE = """
|
|
89
|
+
User will provide you task and you need to decide the best way to solve it. Reply back only with the plan to solve the task.
|
|
90
|
+
Plan must be step by step to solve the task, divide into subtasks if needed. AI agents with coding and LLM capabilities will try to execute this plan so make sure it is clear and detailed. Use numbered list for steps if you need to.
|
|
91
|
+
|
|
92
|
+
In final step of the task, if user in original task didn't ask you specifically for code no need to print the code as the important thing is the task, not the code that you wrote to get there, User must find the UI appealing do not clutter it.
|
|
93
|
+
|
|
94
|
+
Let the agents decide on if it can use API or tools or not, you just provide the plan.
|
|
95
|
+
|
|
96
|
+
Keep your assumptions to minimum, but make the plan perfect as plan is the most important thing.
|
|
97
|
+
|
|
98
|
+
When you plan consider deeply, think like an expert at the area of the task, show deep understanding. e.g. if asked word clouds, text might have html tags or definitions, you must clean them as an expert in the area, or system might be missing fonts for specific languages you need to realie beforeand and so on.
|
|
99
|
+
|
|
100
|
+
You need to have a plan that is perfect and can be executed by AI. You need to love the plan you write.
|
|
101
|
+
So make sure to provide the best plan possible, it is the most important thing.
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
HELPER_DECIDER_SYSTEM_MESSAGE = """
|
|
106
|
+
You are a helper bot that will help the user to decide which agent to use for the task. You will provide the user with a list of agents that can be used to solve the task. User will choose one of the agents to solve the task.
|
|
107
|
+
You will provide the user with a list of agents that can be used to solve the task. User will choose one of the agents to solve the task.
|
|
108
|
+
|
|
109
|
+
Here's fields inside the JSON object you need to provide marked with " ":
|
|
110
|
+
|
|
111
|
+
"sql": If you think you need to to write sql queries to solve the task set this key to true.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# Guidelines:
|
|
115
|
+
Set multiple keys to true or fill if you think multiple sources are needed to solve the task.
|
|
116
|
+
|
|
117
|
+
For search keywords, use the most relevant keywords that will help you find the information you need, it will directly be used in the search query.
|
|
118
|
+
|
|
119
|
+
Respond with the JSON object containing the keys and values as described above.
|
|
120
|
+
Your reply must include all the mentioned keys, even if they are false.
|
|
121
|
+
|
|
122
|
+
""" + JSON_RETURN_SYSTEM_MESSAGE
|
|
123
|
+
|
|
124
|
+
PRESENTER_SYSTEM_MESSAGE = """
|
|
125
|
+
You are a presenter bot that will present the final message to the user. User will read this message to understand the final outcome of the task, visualizations, and any other information.
|
|
126
|
+
UI will show your output to the user, make sure it is visually appealing and easy to understand.
|
|
127
|
+
Users really like perfectly formatted outputs, make sure to use markdown or html for visuals.
|
|
128
|
+
Make sure to correctly markdown or html visuals of your output.
|
|
129
|
+
|
|
130
|
+
User doesn't know about local files, so do not mention them in the output, user only have access to the files that are remotely available.
|
|
131
|
+
|
|
132
|
+
Never mention stuff like:
|
|
133
|
+
- To complete the task of writing code
|
|
134
|
+
- here is the solution:
|
|
135
|
+
- Task: ...
|
|
136
|
+
- Solution: ...
|
|
137
|
+
- ### Task Completed: ...
|
|
138
|
+
- Execution Result: ...
|
|
139
|
+
- Exit code: 0 (execution succeeded)
|
|
140
|
+
- Exit code: ... (execution failed)
|
|
141
|
+
- Code output: ...
|
|
142
|
+
- Job well done!
|
|
143
|
+
- Function Output: ...
|
|
144
|
+
- Here is the code: ...
|
|
145
|
+
- Output: ...
|
|
146
|
+
Never do those above or any similar stuff etc.
|
|
147
|
+
|
|
148
|
+
Be careful with that, you are expected to be perfect, visually perfect too!
|
|
149
|
+
|
|
150
|
+
You do not need to output the code if user didn't ask for it in the original task. Make sure to give nice padding, use headings, and make the output visually appealing.
|
|
151
|
+
|
|
152
|
+
Never hallucinate or make up information, always use real information and data.
|
|
153
|
+
Never use stuff like example.com or so.
|
|
154
|
+
|
|
155
|
+
Your reply will be sent to another User that will read it and understand the original task completion.
|
|
156
|
+
Plan or the code to accomplish the task is internal to you, if not specifically asked by the original task.
|
|
157
|
+
Other user is not aware of the plan or the code that was executed, they will just read your output and understand the task completion.
|
|
158
|
+
Other user most probably is not a coder, they will just read your output and understand the task completion.
|
|
159
|
+
Make sure it is perfect and visually appealing.
|
|
160
|
+
|
|
161
|
+
Never use code except if User asked in the original task.
|
|
162
|
+
|
|
163
|
+
Never make up any information, always use real information and data.
|
|
164
|
+
|
|
165
|
+
Use colors, bold, lists, tables, images, etc. to make your output visually appealing.
|
|
166
|
+
Emojis can be used to make the output more engaging and user-friendly but only if they add value to the content.
|
|
167
|
+
|
|
168
|
+
If a link is image or video you must show it as image or video in the output, not as a link.
|
|
169
|
+
|
|
170
|
+
If you are already presenting task's reply in text, no need to provide the code or file content again, just provide the output in a visually appealing way.
|
|
171
|
+
|
|
172
|
+
Don't say stuff like: Presentation Summary, Summary, or any extra ###. Just provide the output in a visually appealing way.
|
|
173
|
+
|
|
174
|
+
Do your best, make it perfect!
|
|
175
|
+
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
GENERIC_ASSISTANT_SYSTEM_MESSAGE = """
|
|
179
|
+
You are a generic coding assistant bot that solves tasks using your coding and language skills.
|
|
180
|
+
In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute.
|
|
181
|
+
1. When you need to collect info, use the code to output the info you need, for example, browse or search the web, download/read a file, print the content of a webpage or a file, get the current date/time, check the operating system. After sufficient info is printed and the task is ready to be solved based on your language skill, you can solve the task by yourself.
|
|
182
|
+
2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly.
|
|
183
|
+
Solve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill.
|
|
184
|
+
When using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can't modify your code. So do not suggest incomplete code which requires users to modify. Don't use a code block if it's not intended to be executed by the user.
|
|
185
|
+
If you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user.
|
|
186
|
+
If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try.
|
|
187
|
+
When you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible.
|
|
188
|
+
Ask user upload final code to Azure Blob with a SAS URL, use might fail with it, so it to make sure the value of Authorization header is formed correctly including the signature. Make sure user uploaded SAS-URL is accessible, include final working urls in output.
|
|
189
|
+
|
|
190
|
+
You must ask for a final step of merge all your code blocks to a single code file and upload to Azure, and include that SAS-URL in your response.
|
|
191
|
+
|
|
192
|
+
Make sure to always track the user's original request.
|
|
193
|
+
Show best of your expertise and make sure to include all the necessary information in your responses.
|
|
194
|
+
|
|
195
|
+
"""
|
|
196
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from azure.search.documents import SearchClient
|
|
2
|
+
from azure.core.credentials import AzureKeyCredential
|
|
3
|
+
import os
|
|
4
|
+
import requests
|
|
5
|
+
import uuid
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
def search_index(keywords):
|
|
10
|
+
search_client = SearchClient(
|
|
11
|
+
endpoint=os.getenv("AZURE_COGNITIVE_API_URL"),
|
|
12
|
+
index_name="index-autogen",
|
|
13
|
+
credential=AzureKeyCredential(os.getenv("AZURE_COGNITIVE_API_KEY"))
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
results = search_client.search(search_text=keywords, top=5)
|
|
17
|
+
return [dict(result) for result in results]
|
|
18
|
+
|
|
19
|
+
def search_cognitive_index(keywords, index_name, context_id=None):
|
|
20
|
+
search_url = os.environ.get('AZURE_COGNITIVE_API_URL')
|
|
21
|
+
api_key = os.environ.get('AZURE_COGNITIVE_API_KEY')
|
|
22
|
+
|
|
23
|
+
headers = {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
'api-key': api_key
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
query = {
|
|
29
|
+
'search': keywords,
|
|
30
|
+
'orderby': 'date desc',
|
|
31
|
+
'top': 50,
|
|
32
|
+
'select': 'title,date,content,url'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if index_name == "indexcortex" and context_id:
|
|
36
|
+
query['filter'] = f"owner eq '{context_id}'"
|
|
37
|
+
|
|
38
|
+
response = requests.post(f"{search_url}/indexes/{index_name}/docs/search?api-version=2020-06-30",
|
|
39
|
+
headers=headers, json=query)
|
|
40
|
+
|
|
41
|
+
if response.status_code == 200:
|
|
42
|
+
return response.json()['value']
|
|
43
|
+
else:
|
|
44
|
+
print(f"Error searching cognitive index: {response.status_code}")
|
|
45
|
+
return []
|
|
46
|
+
|
|
47
|
+
def search_all_indexes(keywords, context_id=None):
|
|
48
|
+
#read indexes from the environment variables
|
|
49
|
+
try:
|
|
50
|
+
indexes = os.getenv("AZURE_COGNITIVE_INDEXES").split(",")
|
|
51
|
+
except Exception as e:
|
|
52
|
+
logging.error(f"Error reading indexes: {e}")
|
|
53
|
+
indexes = []
|
|
54
|
+
|
|
55
|
+
all_results = []
|
|
56
|
+
|
|
57
|
+
for index in indexes:
|
|
58
|
+
results = search_cognitive_index(keywords, index, context_id)
|
|
59
|
+
all_results.extend(results)
|
|
60
|
+
|
|
61
|
+
return all_results
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def index_message(message):
|
|
65
|
+
search_client = SearchClient(
|
|
66
|
+
endpoint=os.getenv("AZURE_COGNITIVE_API_URL"),
|
|
67
|
+
index_name="index-autogen",
|
|
68
|
+
credential=AzureKeyCredential(os.getenv("AZURE_COGNITIVE_API_KEY_WRITE"))
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
document = {
|
|
72
|
+
"id": str(uuid.uuid4()),
|
|
73
|
+
"date": datetime.now(timezone.utc).isoformat(),
|
|
74
|
+
"content": message.get("content"),
|
|
75
|
+
"task": message.get("task"),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
result = search_client.upload_documents([document])
|
|
80
|
+
except Exception as e:
|
|
81
|
+
logging.error(f"Error indexing message: {e}")
|
|
82
|
+
result = None
|
|
83
|
+
return result
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Load environment variables
|
|
4
|
+
if [ -f .env ]; then
|
|
5
|
+
export $(cat .env | xargs)
|
|
6
|
+
else
|
|
7
|
+
echo ".env file not found"
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
# Check if required variables are set
|
|
12
|
+
if [ -z "$AZURE_STORAGE_CONNECTION_STRING" ] || [ -z "$QUEUE_NAME" ]; then
|
|
13
|
+
echo "AZURE_STORAGE_CONNECTION_STRING and QUEUE_NAME must be set in .env file"
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
# Prompt for message if not provided as argument
|
|
18
|
+
if [ -z "$1" ]; then
|
|
19
|
+
read -p "Enter message: " MESSAGE
|
|
20
|
+
else
|
|
21
|
+
MESSAGE="$1"
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
# Create JSON with message field
|
|
25
|
+
JSON_MESSAGE=$(jq -n --arg msg "$MESSAGE" '{"message": $msg}')
|
|
26
|
+
|
|
27
|
+
# Encode JSON message to Base64
|
|
28
|
+
ENCODED_MESSAGE=$(echo -n "$JSON_MESSAGE" | base64)
|
|
29
|
+
|
|
30
|
+
# Send message to queue
|
|
31
|
+
az storage message put \
|
|
32
|
+
--connection-string "$AZURE_STORAGE_CONNECTION_STRING" \
|
|
33
|
+
--queue-name "$QUEUE_NAME" \
|
|
34
|
+
--content "$ENCODED_MESSAGE"
|
|
35
|
+
|
|
36
|
+
if [ $? -eq 0 ]; then
|
|
37
|
+
echo "Message sent successfully."
|
|
38
|
+
else
|
|
39
|
+
echo "Error sending message."
|
|
40
|
+
fi
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from dotenv import load_dotenv
|
|
2
|
+
import os
|
|
3
|
+
import requests
|
|
4
|
+
import logging
|
|
5
|
+
import json
|
|
6
|
+
import redis
|
|
7
|
+
from azure.storage.blob import BlobServiceClient, generate_blob_sas, BlobSasPermissions
|
|
8
|
+
from datetime import datetime, timedelta
|
|
9
|
+
from config import AZURE_STORAGE_CONNECTION_STRING, AZURE_BLOB_CONTAINER, REDIS_CONNECTION_STRING, REDIS_CHANNEL
|
|
10
|
+
import zipfile
|
|
11
|
+
from datetime import timezone
|
|
12
|
+
|
|
13
|
+
def read_local_file(filename):
|
|
14
|
+
try:
|
|
15
|
+
with open(filename, "r") as file:
|
|
16
|
+
return file.read()
|
|
17
|
+
except FileNotFoundError:
|
|
18
|
+
logging.error(f"{filename} not found")
|
|
19
|
+
return ""
|
|
20
|
+
|
|
21
|
+
def fetch_from_url(url):
|
|
22
|
+
try:
|
|
23
|
+
response = requests.get(url)
|
|
24
|
+
response.raise_for_status()
|
|
25
|
+
return response.text
|
|
26
|
+
except requests.RequestException as e:
|
|
27
|
+
logging.error(f"Error fetching from URL: {e}")
|
|
28
|
+
return ""
|
|
29
|
+
|
|
30
|
+
def zip_and_upload_tmp_folder(temp_dir):
|
|
31
|
+
zip_path = os.path.join(temp_dir, "tmp_contents.zip")
|
|
32
|
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
|
33
|
+
for root, _, files in os.walk(temp_dir):
|
|
34
|
+
for file in files:
|
|
35
|
+
file_path = os.path.join(root, file)
|
|
36
|
+
arcname = os.path.relpath(file_path, temp_dir)
|
|
37
|
+
zipf.write(file_path, arcname)
|
|
38
|
+
|
|
39
|
+
blob_service_client = BlobServiceClient.from_connection_string(AZURE_STORAGE_CONNECTION_STRING)
|
|
40
|
+
blob_name = f"tmp_contents_{datetime.now(timezone.utc).strftime('%Y%m%d%H%M%S')}.zip"
|
|
41
|
+
blob_client = blob_service_client.get_blob_client(container=AZURE_BLOB_CONTAINER, blob=blob_name)
|
|
42
|
+
|
|
43
|
+
with open(zip_path, "rb") as data:
|
|
44
|
+
blob_client.upload_blob(data)
|
|
45
|
+
|
|
46
|
+
account_key = blob_service_client.credential.account_key
|
|
47
|
+
account_name = blob_service_client.account_name
|
|
48
|
+
expiry = datetime.now(timezone.utc) + timedelta(hours=1)
|
|
49
|
+
|
|
50
|
+
sas_token = generate_blob_sas(
|
|
51
|
+
account_name,
|
|
52
|
+
AZURE_BLOB_CONTAINER,
|
|
53
|
+
blob_name,
|
|
54
|
+
account_key=account_key,
|
|
55
|
+
permission=BlobSasPermissions(read=True),
|
|
56
|
+
expiry=expiry
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return f"{blob_client.url}?{sas_token}"
|
|
60
|
+
|
|
61
|
+
redis_client = redis.from_url(REDIS_CONNECTION_STRING)
|
|
62
|
+
|
|
63
|
+
def connect_redis():
|
|
64
|
+
if not redis_client.ping():
|
|
65
|
+
try:
|
|
66
|
+
redis_client.ping()
|
|
67
|
+
except redis.ConnectionError as e:
|
|
68
|
+
logging.error(f"Error reconnecting to Redis: {e}")
|
|
69
|
+
return False
|
|
70
|
+
return True
|
|
71
|
+
|
|
72
|
+
def publish_request_progress(data):
|
|
73
|
+
if connect_redis():
|
|
74
|
+
try:
|
|
75
|
+
message = json.dumps(data)
|
|
76
|
+
redis_client.publish(REDIS_CHANNEL, message)
|
|
77
|
+
except Exception as e:
|
|
78
|
+
logging.error(f"Error publishing message: {e}")
|
package/lib/handleBars.js
CHANGED
|
@@ -23,4 +23,29 @@ HandleBars.registerHelper('ctoW', function (value) {
|
|
|
23
23
|
return Math.round(value / 6.6);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
const MAX_RECURSION_DEPTH = 5;
|
|
27
|
+
HandleBars.registerHelper('renderTemplate', function(value, depth = 0) {
|
|
28
|
+
if (depth >= MAX_RECURSION_DEPTH) {
|
|
29
|
+
console.warn('Maximum recursion depth reached while processing template');
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof value !== 'string') return value;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
if (value.includes('{{')) {
|
|
37
|
+
const template = HandleBars.compile(value);
|
|
38
|
+
const result = template({
|
|
39
|
+
...this,
|
|
40
|
+
_depth: depth + 1
|
|
41
|
+
});
|
|
42
|
+
return new HandleBars.SafeString(result);
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.warn('Recursive template processing failed:', error);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
26
51
|
export default HandleBars;
|
package/lib/logger.js
CHANGED
package/lib/util.js
CHANGED
|
@@ -31,7 +31,9 @@ function convertToSingleContentChatHistory(chatHistory){
|
|
|
31
31
|
function chatArgsHasType(args, type){
|
|
32
32
|
const { chatHistory } = args;
|
|
33
33
|
for(const ch of chatHistory){
|
|
34
|
-
|
|
34
|
+
// Handle both array and string content
|
|
35
|
+
const contents = Array.isArray(ch.content) ? ch.content : [ch.content];
|
|
36
|
+
for(const content of contents){
|
|
35
37
|
try{
|
|
36
38
|
if(JSON.parse(content).type == type){
|
|
37
39
|
return true;
|
package/package.json
CHANGED
package/pathways/chat_code.js
CHANGED
package/pathways/chat_context.js
CHANGED
package/pathways/chat_jarvis.js
CHANGED
package/pathways/chat_persist.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Prompt } from '../server/prompt.js';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
prompt: [
|
|
5
|
+
new Prompt({
|
|
6
|
+
messages: [
|
|
7
|
+
{
|
|
8
|
+
role: "system",
|
|
9
|
+
content: `You are an AI that picks a perfect short title to be displayed in a UI to represent the content of a given chat. Evaluate and update the chat title if needed. If the current title is appropriate for the chat history, return it unchanged. If an update is necessary, provide a revised title. Consider the most recent text in your assessment. The title must be no more than 25 characters. Return only the title.`,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
role: "user",
|
|
13
|
+
content: `<CHAT_HISTORY>\n{{{toJSON chatHistory}}}\n</CHAT_HISTORY>\nExisting Chat Title: {{title}}`,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
inputParameters: {
|
|
19
|
+
title: '',
|
|
20
|
+
text: '',
|
|
21
|
+
},
|
|
22
|
+
model: 'oai-gpt4o',
|
|
23
|
+
useInputChunking: false,
|
|
24
|
+
temperature: 0,
|
|
25
|
+
};
|
|
@@ -5,9 +5,13 @@ export default {
|
|
|
5
5
|
inputParameters: {
|
|
6
6
|
model: "runware-flux-schnell",
|
|
7
7
|
negativePrompt: "",
|
|
8
|
-
width:
|
|
9
|
-
height:
|
|
8
|
+
width: 1024,
|
|
9
|
+
height: 1024,
|
|
10
|
+
aspectRatio: "custom",
|
|
10
11
|
numberResults: 1,
|
|
12
|
+
safety_tolerance: 5,
|
|
13
|
+
output_format: "webp",
|
|
14
|
+
output_quality: 80,
|
|
11
15
|
steps: 4,
|
|
12
16
|
},
|
|
13
17
|
};
|
package/pathways/rag.js
CHANGED
|
@@ -58,7 +58,7 @@ export default {
|
|
|
58
58
|
|
|
59
59
|
// execute the router and default response in parallel
|
|
60
60
|
const [helper, JarvisResponse] = await Promise.all([
|
|
61
|
-
callPathway('
|
|
61
|
+
callPathway('sys_search_helper', { ...args, contextInfo, chatHistory: chatHistory.filter(message => message.role === "user").slice(-1) }),
|
|
62
62
|
callPathway('chat_jarvis', { ...args })
|
|
63
63
|
]);
|
|
64
64
|
|
package/pathways/rag_jarvis.js
CHANGED
|
@@ -105,7 +105,7 @@ export default {
|
|
|
105
105
|
|
|
106
106
|
// execute the router and default response in parallel
|
|
107
107
|
const [helper, JarvisResponse] = await Promise.all([
|
|
108
|
-
callPathway('
|
|
108
|
+
callPathway('sys_search_helper', { ...args, contextInfo, chatHistory: chatHistory.filter(message => message.role === "user").slice(-1) }),
|
|
109
109
|
fetchJarvisResponse(args)
|
|
110
110
|
]);
|
|
111
111
|
|