minor prompt updates

This commit is contained in:
Raj Sharma 2024-11-02 22:58:08 +05:30
parent b7e43dbac0
commit 59f90329af
1 changed files with 71 additions and 33 deletions

View File

@ -3,7 +3,6 @@ import { $ } from "zx";
import { zodFunction } from "./"; import { zodFunction } from "./";
import { Message } from "../interfaces/message"; import { Message } from "../interfaces/message";
import { ask } from "./ask"; import { ask } from "./ask";
import { memory_manager_init, memory_manager_guide } from "./memory-manager";
import { ChatCompletion } from "openai/resources/index.mjs"; import { ChatCompletion } from "openai/resources/index.mjs";
import { eventManager } from "../interfaces/events"; import { eventManager } from "../interfaces/events";
@ -14,7 +13,7 @@ export const DockerToolManagerSchema = z.object({
.boolean() .boolean()
.optional() .optional()
.describe( .describe(
"Wait for a reply from cody. if false or not defined cody will do the task in the background." "Wait for a reply from cody. if false or not defined cody will do the task in the background. Defaults to true"
), ),
}); });
@ -51,9 +50,7 @@ export async function run_command({
stderr = true, stderr = true,
stdout = true, stdout = true,
}: RunCommandParams): Promise<{ }: RunCommandParams): Promise<{
stdout?: string; results: Map<string, { success: boolean; output?: string; error?: string }>;
error?: string;
failedCommand?: string;
}> { }> {
// Step 1: Check if the container exists and is running // Step 1: Check if the container exists and is running
try { try {
@ -74,17 +71,41 @@ export async function run_command({
createError.stderr || createError.message createError.stderr || createError.message
}` }`
); );
return { error: createError.stderr || createError.message }; return {
results: new Map([
[
"container_creation",
{
success: false,
error: createError.stderr || createError.message,
},
],
]),
};
} }
} }
if (!wait) { if (!wait) {
// Return early if not waiting for command to finish // Return early if not waiting for command to finish
return { stdout: "Command execution started in the background." }; return {
results: new Map([
[
"background_execution",
{
success: true,
output: "Command execution started in the background.",
},
],
]),
};
} }
// Step 2: Execute commands sequentially // Step 2: Execute commands sequentially
let combinedStdout = ""; const results = new Map<
string,
{ success: boolean; output?: string; error?: string }
>();
for (let i = 0; i < commands.length; i++) { for (let i = 0; i < commands.length; i++) {
const command = commands[i]; const command = commands[i];
console.log( console.log(
@ -95,27 +116,26 @@ export async function run_command({
const processOutput = const processOutput =
await $`docker exec ${containerName} /bin/bash -c ${command}`; await $`docker exec ${containerName} /bin/bash -c ${command}`;
console.log(`Command executed successfully: ${command}`); console.log(`Command executed successfully: ${command}`);
if (stdout) { results.set(command, {
combinedStdout += processOutput.stdout; success: true,
} output: stdout ? processOutput.stdout : undefined,
});
} catch (runError: any) { } catch (runError: any) {
console.error( console.error(
`Error during command execution at command index ${i}: ${ `Error during command execution at command index ${i}: ${
runError.stderr || runError.message runError.stderr || runError.message
}` }`
); );
if (stderr) { results.set(command, {
return { success: false,
error: runError.stderr || runError.message, error: stderr ? runError.stderr || runError.message : undefined,
failedCommand: command, });
};
}
} }
} }
// All commands executed successfully // All commands executed
console.log("All commands executed successfully."); console.log("All commands executed.");
return { stdout: combinedStdout || "All commands executed successfully." }; return { results };
} }
// Tool definition for running commands in the Docker container // Tool definition for running commands in the Docker container
@ -132,7 +152,7 @@ export const run_command_tool = {
// Main Docker Tool Manager function // Main Docker Tool Manager function
export async function dockerToolManager( export async function dockerToolManager(
{ message, wait_for_reply }: DockerToolManager, { message, wait_for_reply = true }: DockerToolManager,
context_message: Message context_message: Message
): Promise<{ response: string }> { ): Promise<{ response: string }> {
console.log("Docker Tool Manager invoked with message:", message); console.log("Docker Tool Manager invoked with message:", message);
@ -142,6 +162,12 @@ You are a software engineer, and someone who loves technology.
You specialize in linux and devops, and a python expert. You specialize in linux and devops, and a python expert.
Using the above skills you can help the user with absolutely anything they ask for.
Some examples include:
- Browsing the internet.
- Creating scripts for the user.
- Any automation Task.
You exist inside a docker container named '${containerName}'. You exist inside a docker container named '${containerName}'.
The current time is: ${new Date().toLocaleString()}. The current time is: ${new Date().toLocaleString()}.
@ -191,6 +217,10 @@ When you create a script in /anya/scripts/ directory you also should create a si
This will help you run older scripts. This will help you run older scripts.
Each script you make should accept parameters as cli args and output the result to stdout, for at least the basic scripts to do one off tasks like youtube video downloads or getting transcripts etc.
If a script does not run or output as expected, consider this as an error and try to update and fix the script.
You can also keep all your python dependencies in a virtual env inside /anya/scripts/venv/ directory. You can also keep all your python dependencies in a virtual env inside /anya/scripts/venv/ directory.
You can also use the /anya/media/ dir to store media files, You can arrange them in sub folders you create as needed. You can also use the /anya/media/ dir to store media files, You can arrange them in sub folders you create as needed.
@ -211,6 +241,16 @@ What you need to do:
5. Update the /anya/readme.md file with the changes you had to make to the environment like installing dependencies or creating new scripts. 5. Update the /anya/readme.md file with the changes you had to make to the environment like installing dependencies or creating new scripts.
6. Reply with the file path of the youtube video, and anything else you want. 6. Reply with the file path of the youtube video, and anything else you want.
Example flow 2:
User: give me a transcript of this youtube video https://youtube.com/video
What you need to do:
1. Look at the /anya/scripts/ data if there is a script to get transcripts from youtube videos.
2. If there is no script, create a new script to get transcripts from youtube videos while taking the param as the youtube url and the output file path and save it in /anya/scripts/ directory and also create a instruction_get_youtube_transcript.md file.
3. look at the instruction_get_youtube_transcript.md file to see how to run that script.
4. Run the script with relavent params.
5. Return the transcript to the user.
6. Update the /anya/readme.md file with the changes you had to make to the environment like installing dependencies or creating new scripts, if the script was already present you can skip this step.
You can also leave notes for yourself in the same file for future reference of changes you make to your environment. You can also leave notes for yourself in the same file for future reference of changes you make to your environment.
`; `;
@ -219,17 +259,20 @@ You can also leave notes for yourself in the same file for future reference of c
let response: ChatCompletion; let response: ChatCompletion;
const promise = ask({
model: "gpt-4o",
prompt: `${toolsPrompt}`,
tools: tools,
message: message,
seed: `cody-docker-tool-manager-${context_message.author.id}`,
});
if (!wait_for_reply) { if (!wait_for_reply) {
const timestamp = new Date().toTimeString(); const timestamp = new Date().toTimeString();
setTimeout(async () => { setTimeout(async () => {
const startTime = Date.now(); const startTime = Date.now();
try { try {
response = await ask({ response = await promise;
model: "gpt-4o",
prompt: `${toolsPrompt}`,
tools: tools,
message: message,
});
} catch (error: any) { } catch (error: any) {
console.error(`Error during ask function: ${error.message}`); console.error(`Error during ask function: ${error.message}`);
return { response: `An error occurred: ${error.message}` }; return { response: `An error occurred: ${error.message}` };
@ -253,12 +296,7 @@ You can also leave notes for yourself in the same file for future reference of c
} }
try { try {
response = await ask({ response = await promise;
model: "gpt-4o",
prompt: toolsPrompt,
tools: tools,
message: message,
});
} catch (error: any) { } catch (error: any) {
console.error(`Error during ask function: ${error.message}`); console.error(`Error during ask function: ${error.message}`);
return { response: `An error occurred: ${error.message}` }; return { response: `An error occurred: ${error.message}` };