Skip to content

Commit

Permalink
Create new admin-operator flow (#2)
Browse files Browse the repository at this point in the history
* Create new admin-operator flow

* Move ui-builder/admin-operator from old data directory to new packages/node-red-data

* Format dummy-sse-app.js

* Rename dummy-sse-app.js to dummy-sse-app.cjs

* Install express and body-parser dev dependencies

* Archive March session of experimenting with ubuntu commands

* Update dummy-see-app response with tags for testing admin-op

* Add host.docker.internal.local domain name that points to process IP address

* Update flows.json with bug fixes for the admin-op flow, currently working
  • Loading branch information
JoshuaCWebDeveloper authored Jun 13, 2024
1 parent dfbdaa0 commit 136b83e
Show file tree
Hide file tree
Showing 49 changed files with 3,946 additions and 247 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"files": ["*.js", "*.jsx", "*.cjs", "*.mjs"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
},
Expand Down
2 changes: 1 addition & 1 deletion administrator.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ When a goal is too complex or you lack the requisite abilities for you to accomp

In addition to requests from the User, Operators may also send you messages or requests. Unlike requests from the User, you may choose whether and how to respond to messages and requests from Operators.

End all responses with an <end /> tag.
Every response must conclude with an <end /> tag.

## Commands

Expand Down
90 changes: 90 additions & 0 deletions dummy-sse-app.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 8080;

const responseTextBase =
"To elicit a more detailed and specific response from BigStar, you could alter Lilly's prompt as follows:\n\n<prompt>I have $10,000 in savings currently in an investment account. My goal is to earn a passive income of $10,000 per month within the next 6-12 months. Please provide a comprehensive step-by-step plan that outlines clear actions and resources for meeting this goal. The plan should include information on high-yield savings accounts, their interest rates, minimum balance requirements, and any other relevant details. Additionally, please consider providing examples of other investment strategies or financial products that could help me achieve my goal.</prompt>\n\nThis prompt is more detailed and specific, which would encourage BigStar to provide a more thorough response with actionable steps and resources for achieving Lilly's goal";

const responseText = `${responseTextBase}
<operator-api>
{
"method": "POST",
"path": "/operators",
"body": {
"id": "06f86c9a-1fe6-4c74-8939-30e64cb1edbb",
"name": "My First Operator"
}
}
</operator-api>
<operator-api>
{
"method": "POST",
"path": "/operators/06f86c9a-1fe6-4c74-8939-30e64cb1edbb/messages",
"body": {
"content": "Sign up for an account at the following website: https://www.example.com"
}
}
</operator-api>
<operator-message>When I tried to access the website, I got a 404 Not Found error.</operator-message>
`;

app.use(bodyParser.json());

app.post('/v1/chat/completions', async (req, res) => {
const parts = chooseBetween(40, 60);
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
});
countdown(res, parts, parts);
});

const chooseBetween = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;

function countdown(res, parts, count) {
const timeout = chooseBetween(50, 300);

const chunkSize = Math.ceil(responseText.length / parts);

res.write(
'data: ' +
JSON.stringify({
choices: [
{
delta: {
content: responseText.slice(
(parts - count) * chunkSize,
(parts - count + 1) * chunkSize
),
},
},
],
}) +
'\n\n'
);
if (count) setTimeout(() => countdown(res, parts, count - 1), timeout);
else res.end();
}

app.post('/embedding', async (req, res) => {
const dimensions = 5120;
res.writeHead(200, {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
});
res.write(
JSON.stringify({
embedding: new Array(dimensions).fill(0).map(() => Math.random()),
})
);
res.end();
});

app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
2 changes: 1 addition & 1 deletion node-red.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
docker run --rm -it -p 1880:1880 -v $(pwd)/packages/node-red-data:/data --name mynodered nodered/node-red:3.1.3-18
docker run --rm -it --add-host host.docker.internal.local=$(hostname -I | awk '{print $1}') -p 1880:1880 -v $(pwd)/packages/node-red-data:/data --name mynodered nodered/node-red:3.1.3-18
read -n 1 -s -r -p "Press any key to continue"
Loading

0 comments on commit 136b83e

Please sign in to comment.