Skip to content

Commit

Permalink
feat(): add a max lorem sentence number env var
Browse files Browse the repository at this point in the history
  • Loading branch information
piyook committed May 23, 2024
1 parent f2f7415 commit 4258aac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ SERVER_PORT=8000
USE_API_URL_PREFIX=chatgpt/chat
## MOCK_GPT_MODE can be 'lorem' or 'stored'
MOCK_GPT_MODE=lorem
MAX_LOREM_PARAS=8
DEBUG=*
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,37 @@ By default this is set to 8000 but can be changed by setting the SERVER_PORT in
```
SERVER_PORT=1234
```

### Return stored responses

Set the following environment variable to 'stored' to use responses stored int the data/data.json file:

```
MOCK_GPT_MODE=stored
```

The responses increment for each http request and restart as the beginning once all have been used.

### Return randomly generated lorem ipsum responses

Set the following environment variable to 'lorem' to use responses stored in the data/data.json file:

```
MOCK_GPT_MODE=lorem
```

A random number of sentences are generated in the response and the maximum sentence number can be set with:

```
MAX_LOREM_PARAS=8
```

### Debugging

You can toggle the detailed debug mode that shows more detail on each request and response by setting:

```
DEBUG=*
```

set to FALSE to remove debugging details
5 changes: 4 additions & 1 deletion src/api/completions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const mockGPTResponse = () => {

switch (process.env?.MOCK_GPT_MODE) {
case 'lorem': {
content = faker.lorem.paragraphs({ min: 1, max: 10 });
content = faker.lorem.sentences({
min: 1,
max: Number.parseInt(process.env?.MAX_LOREM_PARAS ?? '5', 10),
});
break;
}

Expand Down

0 comments on commit 4258aac

Please sign in to comment.