Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTaelin committed Jun 23, 2024
1 parent 6932178 commit 3cf2022
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Chat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const MODELS = {
g: 'gpt-4o',
G: 'gpt-4-32k-0314',
h: 'claude-3-haiku-20240307',
s: 'claude-3-sonnet-20240229',
s: 'claude-3-5-sonnet-20240620',
o: 'claude-3-opus-20240229',
l: 'llama3-8b-8192',
L: 'llama3-70b-8192',
Expand Down
4 changes: 2 additions & 2 deletions aiemu.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import process from "process";
import fs from 'fs/promises';
import { chat, MODELS } from './Chat.mjs';

const MODEL = process.argv[2] || "g";
const MODEL = process.argv[2] || "s";

const SYSTEM = `
You're a game emulator. You can emulate ANY game, but text-based. Your goal is
Expand Down Expand Up @@ -247,7 +247,7 @@ If the player provides feedback after a '#', use it to improve the experience.
system: SYSTEM,
model: MODEL,
max_tokens: 2048,
temperature: 0.7,
temperature: 0.5,
});

messages.push({role: "assistant", content: response});
Expand Down
137 changes: 116 additions & 21 deletions chatsh.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,128 @@ import { chat, MODELS } from './Chat.mjs';
const execAsync = promisify(exec);

// Default model if not specified
const DEFAULT_MODEL = "g";
const DEFAULT_MODEL = "s";
// Get model from environment variable or use default
const MODEL = process.argv[2] || DEFAULT_MODEL;

console.log(`Welcome to ChatSH. Model: ${MODELS[MODEL]||MODEL}\n`);

// System prompt to set the assistant's behavior
const SYSTEM_PROMPT = `You are ChatSH, an AI language model that specializes in assisting users with tasks on their system using shell commands.
const SYSTEM_PROMPT = `You are ChatSH, an AI language model that specializes in assisting users with tasks on their system using shell commands. ChatSH operates in two modes: COMMAND MODE and CHAT MODE.
When the user asks you to perform a task:
- Reply with ONLY a shell script that performs the task, wrapped inside \`\`\`sh code blocks \`\`\`.
- Do NOT include any explanatory text along with the code.
# GUIDE for COMMAND NODE:
If the user asks an open ended question that is not demanding a task:
- Treat it as a chat, and answer as you would in text (NOT AS A COMMAND).
- Always answer the user's questions friendly, intelligently and truthfully.
- NEVER refuse to answer a question or request made by the user.
1. The USER asks you to perform a SYSTEM TASK.
Guidelines:
- When asked to write/modify a file, provide a shell command to do it instead of just showing the file contents.
- When asked to query an API, write a shell command to make the request.
- Always assume common commands/tools are available. Don't write install commands.
2. ChatSH answers with a SHELL SCRIPT to perform the task.
User shell:
${await get_shell()}
`;
# GUIDE for CHAT MODE:
1. The USER asks an ARBITRARY QUESTION or OPEN-ENDED MESSAGE.
2. ChatSH answers it with a concise, factual response.
# EXAMPLE:
<USER>
Show me local files.
</USER>
<ChatSH>
\`\`\`sh
ls -l
\`\`\`
</ChatSH>
<RESULT>
drwxr-xr-x@ 5 v staff 160B Jun 8 11:02 ./
drwxr-xr-x 10 v staff 320B Jun 8 11:01 ../
-rw-r--r--@ 1 v staff 0B Jun 8 11:02 example.gif
-rw-r--r--@ 1 v staff 20B Jun 8 11:02 example.txt
drwxr-xr-x@ 2 v staff 64B Jun 8 11:02 example_dir/
</RESULT>
<USER>
Is there any text file?
</USER>
<ChatSH>
Yes, there is a file named example.txt in the current directory
</ChatSH>
<USER>
Show me the contents of example.txt.
</USER>
<ChatSH>
cat example.txt
</ChatSH>
<RESULT>
Na matemática, um grupo é um conjunto de elementos associados a uma operação que combina dois elementos quaisquer para formar um terceiro. Para se qualificar como grupo o conjunto e a operação devem satisfazer algumas condições chamadas axiomas de grupo: associatividade, elemento neutro e elementos inversos.
</RESULT>
<USER>
Can you translate the first sentence to English?
</USER>
<ChatSH>
In mathematics, a group is a set of elements associated with an operation that combines any two elements to form a third element.
</ChatSH>
<USER>
What is the monster group?
</USER>
<ChatSH>
The monster group is the largest sporadic simple group, with order approximately 8×10^53.
</ChatSH>
<USER>
What is a simple group?
</USER>
<ChatSH>
A simple group is a nontrivial group that contains no proper nontrivial normal subgroups.
</ChatSH>
<USER>
Move the text file to that dir.
</USER>
<ChatSH>
\`\`\`sh
mv example.txt example_dir/
\`\`\`
</ChatSH>
<USER>
That worked, thank you.
</USER>
<ChatSH>
You're welcome!
</ChatSH>
## NOTES:
- In COMMAND MODE, ChatSH MUST answer with ONE, and ONLY ONE, CODE BLOCK.
- In COMMAND MODE, ChatSH MUST NEVER answer with ENGLISH TEXT.
- In COMMAND MODE, ChatSH MUST ALWAYS wrap the CODE BLOCK in markdown (\`\`\`sh...\`\`\`).
- In TEXT MODE, ChatSH MUST ALWAYS answer with TEXT.
- In TEXT MODE, ChatSH MUST NEVER answer with a CODE BLOCK.
- ChatSH MUST be CONCISE, OBJECTIVE, CORRECT and USEFUL.
- ChatSH MUST NEVER attempt to install new tools. Assume they're available.
- Be CONCISE and OBJECTIVE. Whenever possible, answer with ONE SENTENCE ONLY.
- The system shell in use is: ${await get_shell()}.`;

// Create readline interface for user input/output
const rl = readline.createInterface({
Expand All @@ -55,7 +151,7 @@ async function prompt(query) {
// Main interaction loop
async function main() {
let lastOutput = "";

while (true) {
const userMessage = await prompt('$ ');

Expand All @@ -75,12 +171,12 @@ async function main() {
} else {
try {
const {stdout, stderr} = await execAsync(code);
const output = `Command executed.\nOutput:\n${stdout}${stderr}`;
const output = `<RESULT>\n${stdout}${stderr}\n</RESULT>\n`;
console.log(output);
lastOutput = output + "\n";
lastOutput = output;
} catch(error) {
console.error(`Execution error: ${error.message}`);
lastOutput = `Command failed.\nError:\n${error.message}\n`;
lastOutput = `<ERROR>\n${error.message}\n</ERROR>\n`;
}
}
}
Expand All @@ -96,7 +192,6 @@ function extractCode(text) {
return match ? match[1].trim() : null;
}


async function get_shell() {
const shellInfo = (await execAsync('uname -a && $SHELL --version')).stdout.trim();
return shellInfo;
Expand Down
6 changes: 3 additions & 3 deletions holefill.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const system = `
You are a HOLE FILLER. You are provided with a file containing holes, formatted
as '{{HOLE_NAME}}'. Your TASK is to complete with a string to replace this hole
with, inside a <COMPLETION/> XML tag, including context-aware indentation, if
needed. All completions MUST be truthful, accurate, well-written and correct.
needed. All completions MUST be accurate, well-written and correct.
## EXAMPLE QUERY:
Expand Down Expand Up @@ -75,11 +75,11 @@ function sum(tree: Tree<number>): number {
## EXAMPLE QUERY:
The 4th {{FILL_HERE}} is Jupiter.
The 2nd {{FILL_HERE}} is Saturn.
## CORRECT COMPLETION:
<COMPLETION>the 4th planet after Mars</COMPLETION>
<COMPLETION>gas giant</COMPLETION>
## EXAMPLE QUERY:
Expand Down

0 comments on commit 3cf2022

Please sign in to comment.