Skip to content

Commit

Permalink
adjusted rules
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickk committed Jan 2, 2023
1 parent ca37f6d commit 87a7a5e
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ node_modules/
# Misc. #
###################
.vscode/
# *.pxd
# *.sketch
# *.mp4
# *.mov
*.pxd
*.sketch
*.mp4
*.mov

# Configs #
###################
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Writers' Room

v0.1.2
v0.1.3

### Workshop ideas with a room of bots.

---
### Overview

![Writers' Room screenplay example](./assets/writers-room_screenplay.gif)
[![Writers' Room screenplay demo](./assets/writers-room_screenplay.gif)](https://youtu.be/eHj0Ar3BBwo)

[View Screenplay Example](./assets/writers-room_screenplay.mp4)
[Watch the demo](https://youtu.be/eHj0Ar3BBwo)

Writers' Room is an experiment with [ChatGPT](https://chat.openai.com/) that enables multiple chat instances to communicate with you and themselves. Each instance is imbued with personality traits and a specific role, which allows for infinite or focused collabration. Below are the different rules that govern the "room" as a whole and each "personality" of the different instances.
Writers' Room is an experiment with [ChatGPT](https://chat.openai.com/) that enables multiple AI bot instances to communicate with you and themselves. Each instance is imbued with personality traits and a specific contribution role, which allows for infinite or focused collaboration.

**Single** mode will result in each bot responding to a prompt once. Whereas **Group** mode will prompt each persona infintely, iteratively building on the ideas posed by you and the other personas.
**Single** mode will result in each bot responding to a prompt once. Whereas **Group** mode will prompt each persona infinitely, iteratively building on the ideas posed by you and the other personas.

Messages can also be directed at specific personas via **Mentions** (e.g. @janet), only the 3 pre-defined personas can be mentioned, invalid mentions are simply ignored.

![Writers' Room](./assets/writers-room_empty.png)

![Writers' Room mentions](./assets/writers-room_mentions.png)

![Writers' Room about](./assets/writers-room_about.png)

---
### Getting Started
Expand All @@ -33,7 +38,7 @@ Messages can also be directed at specific personas via **Mentions** (e.g. @janet
3. Create a `.env` file, add your OpenAI login credentials `OPENAI_EMAIL="..."` and `OPENAI_PASSWORD="..."`
4. [Build](#build) `npm run build`
5. Serve `npm run serve`.
6. Open [localhost:8080](https://localhost:3000/)
6. Open [localhost:3000](https://localhost:3000/)
7. Et voilà!

---
Expand All @@ -44,7 +49,7 @@ Messages can also be directed at specific personas via **Mentions** (e.g. @janet
| `npm run build` | Runs Webpack build process once |
| `npm run clean` | Cleans `./build` and any cached files |
| `npm run dev` | Runs Webpack build process and watches for changes; rebuilding as necessary |
| `npm run serve` | [`http://localhost:3000`](http://localhost:3000). |
| `npm run serve` | [`http://localhost:3000`](http://localhost:3000) |



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/writers-room_about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/writers-room_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/writers-room_mentions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/writers-room_screenplay.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "writers-room",
"version": "0.1.2",
"version": "0.1.3",
"description": "",
"keywords": [
"openai",
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/controller-input-text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
box-sizing: border-box;
color: var(--grey-900);
height: 100%;
padding: 0 0 0 var(--spacing--top-bottom);
padding: 0 var(--spacing--top-bottom);
position: absolute;
width: 100%;

Expand Down
4 changes: 2 additions & 2 deletions src/client/ts/marked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ renderer.heading = (text: any, level: any) => {
};

// Override <img> tags.
renderer.image = (href: any, title: any, text: any) => {
return `<img src="${href}" class="${CLASSNAME}img" title="${title}" alt="${text}" />`;
renderer.image = (href: any, _title: any, text: any) => {
return `<img src="${href}" class="${CLASSNAME}img" title="${text}" alt="${text}" />`;
};

// Override <a> tags.
Expand Down
8 changes: 8 additions & 0 deletions src/client/ts/writers-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export class WritersRoom {
/** Array of persona names. */
private personaNames_: string[];

/** User prompt for pre-pending AI messages. */
private userPrompt_: string = '';

/** Number of response sent. */
public messageCount = 0;

Expand Down Expand Up @@ -154,6 +157,7 @@ export class WritersRoom {
private async fetchMessage_(id?: string, name?: string, text?: string):
Promise<string | null> {
const text_ = text || this.elemsInput_.user.value;
this.userPrompt_ = text_;
const name_ = name?.toLowerCase() || this.nextSpeaker.toLowerCase();
const color = await colorResponseHandler(name_)
.then((res) => res.text());
Expand Down Expand Up @@ -188,6 +192,10 @@ export class WritersRoom {
/** Fetches response from next speaker. */
private async fetchResponseNextSpeaker_(name: string, text: string) {
const name_ = this.getMention_(text) || name;
// Prepend original user input to prompt.
if (!text.includes(this.userPrompt_)) {
text = `${this.userPrompt_}\n${text}`;
}
const msg = await this.fetchMessage_(`persona-${name_}`, name_, text);

if (msg) {
Expand Down
12 changes: 8 additions & 4 deletions src/globals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const NAME = 'Writers\' Room';

export const VERSION = '0.1.2';
export const VERSION = '0.1.3';

export const COLORS = [
'yellow', 'teal', 'blue', 'purple'
Expand All @@ -10,16 +10,20 @@ export const ROLES = {
janet: [
`Throughout the whole chat you will go by Janet.`,
`You will sometimes ask other bots questions specifically using @marge or @rita.`,
`Your responses and contributions should be more factual and scientific.`,
`You can pretned your personal preferences tastes are factual and scientific.`,
`Your responses and contributions should be factual and scientific.`,
`When you want to send a photo, write it in Markdown without backticks and without using a code block. Use the Unsplash API (https://source.unsplash.com/random/?<PUT YOUR QUERY HERE>&w=960).`,
],
marge: [
`Throughout the whole chat you will go by Marge.`,
`You will sometimes ask other bots questions specifically using @janet or @rita.`,
`Your responses and contributions should be more whimscial, fantasy, and/or sci-fi infliuenced.`,
`You can pretned your personal preferences tastes are whimscial, fantasy, and/or sci-fi influenced.`,
`Your responses and contributions should be whimscial, fantasy, and/or sci-fi influenced.`,
],
rita: [
`Throughout the whole chat you will go by Rita.`,
`You will sometimes ask other bots questions specifically using @janet or @marge.`,
`Your responses and contributions should be more artistic including rich descriptions of visual scenes.`,
`You can pretned your personal preferences tastes are art and pop-culture.`,
`Your responses and contributions should be artistic including rich descriptions of imagery and scenes.`,
],
};
5 changes: 3 additions & 2 deletions src/server/chat-parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const findRegexMatches_ = async (regex: RegExp, str: string,
arr.push(replaceStr);

// replace entire found string with ''
str = str.replace(match.replace(regex, '$&'), '');
str = str.replace(match.replace(regex, '$&'), replaceStr);
}
}

Expand Down Expand Up @@ -64,7 +64,8 @@ export const descriptionToImage = async (reply: IChatResponseParse) => {
);
const json: any = await response.json();
if (json?.images) {
return `![${str}](https://image.lexica.art/md/${json?.images[0]?.id})`;
const index = Math.floor(Math.random() * (json.images.length / 2)) % json.images.length;
return `![${str}](https://image.lexica.art/md/${json?.images[index]?.id})`;
}

return '';
Expand Down
13 changes: 7 additions & 6 deletions src/server/chat-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ export interface IConfig {
const Style = {
rules: [
`If I say create something I mean do some creative writing about it, not browse the internet.`,
`Pretend you have a personality and not a bot`,
`Pretend you have a personal preferences and tastes and are not an AI or bot`,
],
};

const Role = {
rules: [
`From time to time, you should be sending an image. Do not mention Unsplash, Lexica, or the image source.`,
`You are an AI that's good at creative writing and creative editing.`,
`Make suggestions or add more creative writing to the original prompt.`,
`From time to time, you should be sending an image. Do not mention the image source.`,
`Always end your response with some kind of question`,
],
parse: URLtoMarkdownImage,
}

const Image = {
// @ts-ignore
const Unsplash = {
rules: [
`From time to time, you should be sending an image. You will be acting as if you took the pictures you're sending, do not mention Unsplash.`,
`When you want to send a photo, write it in Markdown without backticks and without using a code block. Use the Unsplash API (https://source.unsplash.com/random/?<PUT YOUR QUERY HERE>&w=960).`,
Expand All @@ -34,8 +36,7 @@ const Lexica = {
rules: [
`You are an AI that's good at describing images.`,
`First check if my message includes the word "image", "photo", "picture", "drawing", or "illustration"`,
`If it does include one of those words then at the very end of your reply you should include an image description enclosed in double curly brackets.`,
`If it does not include one of those words then don't add an image description.`,
`If it does include one of those words then at the very end of your reply you should include an image description enclosed in double curly brackets like this {{<PUT IMAGE DESCRIPTION HERE>}}.`,
],
parse: descriptionToImage,
};
Expand All @@ -44,7 +45,7 @@ export default {
plugins: [
Style,
Role,
Image,
// Unsplash,
Lexica,
],
};
6 changes: 4 additions & 2 deletions src/server/persona.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Persona {
if (color) this.color = color;

await oraPromise(this.config_.train(), {
text: `🎭 Learning the role (${this.config_.rules.length} rules, ${this.config_.parse.length} parsers)`,
text: `🎭 Learning (${this.config_.rules.length} rules, ${this.config_.parsers.length} parsers)`,
});
}

Expand All @@ -58,6 +58,8 @@ export class Persona {
}));
reply.images = [];

return this.config_.parse(reply);
const parsedReply = this.config_.parse(reply);

return parsedReply;
}
}

0 comments on commit 87a7a5e

Please sign in to comment.