Skip to content

Commit

Permalink
Initial push
Browse files Browse the repository at this point in the history
  • Loading branch information
futureHQ committed May 14, 2023
1 parent 0925420 commit 40aa834
Show file tree
Hide file tree
Showing 10 changed files with 1,783 additions and 0 deletions.
31 changes: 31 additions & 0 deletions LLMTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const openai = require('openai');

openai.apiKey = 'YOUR_OPENAI_API_KEY';

class LLMTask {
constructor(prompt, ws = null) {
this.prompt = prompt;
this.ws = ws;
}

async perform() {
const response = await openai.Completion.create({
engine: 'text-davinci-002',
prompt: this.prompt,
max_tokens: 60
});

const instruction = JSON.parse(response.choices[0].text);

console.log('Instruction:', instruction);

// If WebSocket connection is available, send the instruction to the client
if (this.ws && this.ws.readyState === this.ws.OPEN) {
this.ws.send(`Instruction: ${JSON.stringify(instruction)}`);
}

return instruction;
}
}

module.exports = LLMTask;
10 changes: 10 additions & 0 deletions agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class BasicAgent {
async run(tasks) {
// execute tasks sequentially
for (const task of tasks) {
await task.perform();
}
}
}

module.exports = BasicAgent;
29 changes: 29 additions & 0 deletions browseTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const puppeteer = require('puppeteer');

class BrowseTask {
constructor(url, headless = "new", ws = null) {
this.url = url;
this.headless = headless;
this.ws = ws;
}

async perform() {
const browser = await puppeteer.launch({ headless: this.headless });
const page = await browser.newPage();
await page.goto(this.url, { waitUntil: 'networkidle2' }); // waits until all network requests are finished
const content = await page.content();

await browser.close();

console.log('Content:', content);

// If WebSocket connection is available, send the content to the client
if (this.ws && this.ws.readyState === this.ws.OPEN) {
this.ws.send(`Content: ${content}`);
}

return content;
}
}

module.exports = BrowseTask;
19 changes: 19 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const BasicAgent = require('./agent');
const TerminalTask = require('./task');
const BrowseTask = require('./browseTask');
const TaskQueue = require('./taskQueue');

const taskQueue = new TaskQueue();
taskQueue.addTask(new TerminalTask('ls'));
taskQueue.addTask(new BrowseTask('https://example.com'));

// const agent = new BasicAgent();
// agent.run([new TerminalTask('ls')]);
// agent.run([new TerminalTask('pwd')]);
// const agent = new BasicAgent();
// agent.run([new BrowseTask('https://example.com')]);

const agent = new BasicAgent();
agent.run(taskQueue.queue).then(() => {
console.log('All tasks have been executed');
});
Loading

0 comments on commit 40aa834

Please sign in to comment.