Skip to content

Commit

Permalink
Docs (#1)
Browse files Browse the repository at this point in the history
* Install types for mongodb

* Create README

* Init docs

* Copy README to docs site

* Downgrade nuxt because of color theme error

nuxt-modules/color-mode#190

* Add architecture
  • Loading branch information
d0rich authored Apr 12, 2023
1 parent 90e033f commit 91920de
Show file tree
Hide file tree
Showing 14 changed files with 22,353 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .docs/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default defineAppConfig({
d0xigen: {
title: 'tweetst0rm',
description: '🐔 Simple app that uses GPT-3 for generating tweets.',
url: 'https://tweetst0rm.d0rich.me',
social: {
github: 'https://github.com/d0rich/tweetst0rm'
},
seo: {
keywords: ['twitter', 'ai', 'gpt', 'back-end', 'typescript', 'oauth2']
},
features: {
gtag: {
id: 'G-HJJ3E4PKZB'
}
},
d0richIndex: {
complexity: 2,
tags: ['ai', 'twitter', 'back-end']
},
}
})
21 changes: 21 additions & 0 deletions .docs/content/1.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
navigation.title: "Getting started"
---

# Welcome to tweetst0rm 🐔

tweetst0rm is a simple app that uses GPT-3 for generating tweets.

## Download program

Clone repository with source code:

```bash
git clone https://github.com/d0rich/tweetst0rm.git
```

Install dependencies:

```bash
npm install
```
71 changes: 71 additions & 0 deletions .docs/content/2.configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Configuration

Create `.env` file in root directory to define environment variables:

```bash [.env]
MONGODB_HOST=XXXXXXXX
MONGODB_USER=XXXXXXXX
MONGODB_PASSWORD=XXXXXXXX

TWITTER_CLIENT_ID=XXXXXXXX
TWITTER_CLIENT_SECRET=XXXXXXXX

OPENAI_ORG=XXXXXXXX
OPENAI_KEY=XXXXXXXX

CHANCE=0.5
```

## MongoDB

tweetst0rm uses MongoDB for storing OAuth tokens for accessing Twitter API. As free solution you can use [MongoDB Atlas](https://www.mongodb.com/cloud/atlas). In order to configure MongoDB connection you need to define following environment variables:

- `MONGODB_HOST` - MongoDB host
- `MONGODB_USER` - MongoDB user
- `MONGODB_PASSWORD` - MongoDB password

## Twitter

tweetst0rm uses Twitter API for posting tweets. In order to configure Twitter API you need to create [Twitter app](https://developer.twitter.com/en/apps) and define following environment variables:

- `TWITTER_CLIENT_ID` - Twitter app client ID
- `TWITTER_CLIENT_SECRET` - Twitter app client secret

## OpenAI

tweetst0rm uses GPT-3 model via OpenAI API for generating tweets. In order to configure OpenAI API you need to create [OpenAI API key](https://beta.openai.com/account/api-keys) and define following environment variables:

- `OPENAI_ORG` - OpenAI organization ID
- `OPENAI_KEY` - OpenAI API key

## Customization

Script `publish-post-random` can succeed with probability defined by `CHANCE` environment variable. By default it is set to `0.5` which means that script will succeed with 50% probability.

## Tweets content

In order to customize tweets content you need to edit `prompts.ts` file in root directory. It contains following arrays:

- `sentenceTypes` - array of sentence types
- `topics` - array of topics
- `wildcards` - list additional actions here

```ts [prompts.ts]
export const sentenceTypes: string[] = [
'something',
'funny fact',
'concern'

]

export const topics: string[] = [
'Vuejs',
'React is bad',
'Vue is better than React'
]

export const wildcards: string[] = [
'use a lot of emojis',
'ask people to follow your account'
]
```
42 changes: 42 additions & 0 deletions .docs/content/3.usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Usage

You can run permanent process which will generate and publish tweets in random moments during day:

Build project:

```bash
npm run build
```

Run process:

```bash
npm run start
```

Keep in mind that you need to authorize with OAuth. For that go to `http://localhost:3000/auth` and follow instructions. Reminder about authorization will be also displayed in terminal.

> As OAuth token is stored in MongoDB you need to authorize only once and it will also work in different scripts.
## Scripts

You also can configure some cron jobs to run scripts in specific moments of day.

Before configuring cron jobs you need to authorize in Twitter with OAuth. For that run `npm run auth` and go to `http://localhost:3000/auth`.

```bash
npm run auth
```

`publish-post` - generates and publishes tweet:

```bash
npm run publish-post
```

`publish-post-random` - generates and publishes tweet with probability defined by `CHANCE` environment variable:

```bash
npm run publish-post-random
```

19 changes: 19 additions & 0 deletions .docs/content/4.architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Architecture

tweetst0rm uses several APIs in order to work. The following diagram shows the architecture of the application.

```plantuml
component "twitter" as twitter
component "tweetst0rm" as tweetst0rm
component "MongoDB" as mongodb
component "OpenAI" as openai
tweetst0rm ..> twitter : OAuth2.0
tweetst0rm ..> twitter : Post tweet
tweetst0rm .u.> mongodb : Store/get OAuth token
tweetst0rm .u.> openai : Generate text
```

- [twitter](https://developer.twitter.com/en/docs) is used to post tweets and to get the OAuth tokens.
- MongoDB is used to store the OAuth tokens.
- OpenAI is used to generate the text.
3 changes: 3 additions & 0 deletions .docs/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default defineNuxtConfig({
extends: ['d0xigen']
})
Loading

0 comments on commit 91920de

Please sign in to comment.