-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,783 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
Oops, something went wrong.