Skip to content

Commit b4d451d

Browse files
authored
Merge pull request #142 from danny-avila/feat-endpoint-style-structure
Endpoint style structure and more customize of all model.
2 parents 0ec68bf + 97e39b8 commit b4d451d

File tree

106 files changed

+6121
-9433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+6121
-9433
lines changed

LOCAL_INSTALL.md

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,82 @@
11
### Local
2+
23
- **Install the prerequisites**
3-
- **Download chatgpt-clone**
4-
- Download the latest release here: https://github.com/danny-avila/chatgpt-clone/releases/
5-
- Or by clicking on the green code button in the top of the page and selecting "Download ZIP"
6-
- Or (Recommended if you have Git installed) pull the latest release from the main branch
7-
- If you downloaded a zip file, extract the content in "C:/chatgpt-clone/"
8-
-**IMPORTANT : If you install the files somewhere else modify the instructions accordingly**
9-
10-
- **To enable the Conversation search feature:**
11-
-IF YOU DON'T WANT THIS FEATURE YOU CAN SKIP THIS STEP
12-
- Download MeileSearch latest release from : https://github.com/meilisearch/meilisearch/releases
13-
- Copy it to "C:/chatgpt-clone/"
14-
- Rename the file to "meilisearch.exe"
15-
- Open it by double clicking on it
16-
- Copy the generated Master Key and save it somewhere (You will need it later)
17-
18-
- **Download and Install Node.js**
19-
- Navigate to https://nodejs.org/en/download and to download the latest Node.js version for your OS (The Node.js installer includes the NPM package manager.)
20-
21-
- **Create a MongoDB database**
22-
- Navigate to https://www.mongodb.com/ and Sign In or Create an account
23-
- Create a new project
24-
- Build a Database using the free plan and name the cluster (example: chatgpt-clone)
25-
- Use the "Username and Password" method for authentication
26-
- Add your current IP to the access list
27-
- Then in the Database Deployment tab click on Connect
28-
- In "Choose a connection method" select "Connect your application"
29-
- Driver = Node.js / Version = 4.1 or later
30-
- Copy the connection string and save it somewhere(you will need it later)
31-
32-
- **Get your OpenAI API key** here: https://platform.openai.com/account/api-keys and save it somewhere safe (you will need it later)
33-
34-
- **Get your Bing Access Token**
35-
- Using MS Edge, navigate to bing.com
36-
- Make sure you are logged in
37-
- Open the DevTools by pressing F12 on your keyboard
38-
- Click on the tab "Application" (On the left of the DevTools)
39-
- Expand the "Cookies" (Under "Storage")
40-
- You need to copy the value of the "_U" cookie, save it somewhere, you will need it later
41-
4+
5+
- **Download chatgpt-clone**
6+
- Download the latest release here: https://github.com/danny-avila/chatgpt-clone/releases/
7+
- Or by clicking on the green code button in the top of the page and selecting "Download ZIP"
8+
- Or (Recommended if you have Git installed) pull the latest release from the main branch
9+
- If you downloaded a zip file, extract the content in "C:/chatgpt-clone/" -**IMPORTANT : If you install the files somewhere else modify the instructions accordingly**
10+
- **To enable the Conversation search feature:**
11+
-IF YOU DON'T WANT THIS FEATURE YOU CAN SKIP THIS STEP
12+
13+
- Download MeileSearch latest release from : https://github.com/meilisearch/meilisearch/releases
14+
- Copy it to "C:/chatgpt-clone/"
15+
- Rename the file to "meilisearch.exe"
16+
- Open it by double clicking on it
17+
- Copy the generated Master Key and save it somewhere (You will need it later)
18+
19+
- **Download and Install Node.js**
20+
- Navigate to https://nodejs.org/en/download and to download the latest Node.js version for your OS (The Node.js installer includes the NPM package manager.)
21+
- **Create a MongoDB database**
22+
- Navigate to https://www.mongodb.com/ and Sign In or Create an account
23+
- Create a new project
24+
- Build a Database using the free plan and name the cluster (example: chatgpt-clone)
25+
- Use the "Username and Password" method for authentication
26+
- Add your current IP to the access list
27+
- Then in the Database Deployment tab click on Connect
28+
- In "Choose a connection method" select "Connect your application"
29+
- Driver = Node.js / Version = 4.1 or later
30+
- Copy the connection string and save it somewhere(you will need it later)
31+
- **Get your OpenAI API key** here: https://platform.openai.com/account/api-keys and save it somewhere safe (you will need it later)
32+
33+
- **Get your Bing Access Token**
34+
- Using MS Edge, navigate to bing.com
35+
- Make sure you are logged in
36+
- Open the DevTools by pressing F12 on your keyboard
37+
- Click on the tab "Application" (On the left of the DevTools)
38+
- Expand the "Cookies" (Under "Storage")
39+
- You need to copy the value of the "\_U" cookie, save it somewhere, you will need it later
40+
4241
- **Create the ".env" File** You will need all your credentials, (API keys, access tokens, and Mongo Connection String, MeileSearch Master Key)
43-
- Open "C:/chatgpt-clone/api/.env.example" in a text editor
44-
- At this line **MONGO_URI="mongodb://127.0.0.1:27017/chatgpt-clone"**
45-
Replace mongodb://127.0.0.1:27017/chatgpt-clone with the MondoDB connection string you saved earlier, **remove "&w=majority" at the end**
46-
- It should look something like this: "MONGO_URI="mongodb+srv://username:[email protected]/?retryWrites=true"
47-
- At this line **OPENAI_KEY=** you need to add your openai API key
48-
- Add your Bing token to this line **BING_TOKEN=** (needed for BingChat & Sydney)
49-
- If you want to enable Search, **SEARCH=TRUE** if you do not want to enable search **SEARCH=FALSE**
50-
- Add your previously saved MeiliSearch Master key to this line **MEILI_MASTER_KEY=** (the key is needed if search is enabled even on local install or you may encounter errors)
51-
- Save the file as **"C:/chatgpt-clone/api/.env"**
42+
- Open "C:/chatgpt-clone/api/.env.example" in a text editor
43+
- At this line **MONGO_URI="mongodb://127.0.0.1:27017/chatgpt-clone"**
44+
Replace mongodb://127.0.0.1:27017/chatgpt-clone with the MondoDB connection string you saved earlier, **remove "&w=majority" at the end**
45+
- It should look something like this: "MONGO_URI="mongodb+srv://username:password@chatgpt-clone.lfbcwz3.mongodb.net/?retryWrites=true"
46+
- At this line **OPENAI_KEY=** you need to add your openai API key
47+
- Add your Bing token to this line **BINGAI_TOKEN=** (needed for BingChat & Sydney)
48+
- If you want to enable Search, **SEARCH=TRUE** if you do not want to enable search **SEARCH=FALSE**
49+
- Add your previously saved MeiliSearch Master key to this line **MEILI_MASTER_KEY=** (the key is needed if search is enabled even on local install or you may encounter errors)
50+
- Save the file as **"C:/chatgpt-clone/api/.env"**
5251

5352
**DO THIS ONCE AFTER EVERY UPDATE**
53+
5454
- **Run** `npm ci` in the "C:/chatgpt-clone/api" directory
5555
- **Run** `npm ci` in the "C:/chatgpt-clone/client" directory
5656
- **Run** `npm run build` in the "C:/chatgpt-clone/client"
5757

5858
**DO THIS EVERY TIME YOU WANT TO START CHATGPT-CLONE**
59+
5960
- **Run** `"meilisearch --master-key put_your_meilesearch_Master_Key_here"` in the "C:/chatgpt-clone" directory (Only if SEARCH=TRUE)
60-
- **Run** `npm start` in the "C:/chatgpt-clone/api" directory
61+
- **Run** `npm start` in the "C:/chatgpt-clone/api" directory
6162

6263
- **Visit** http://localhost:3080 (default port) & enjoy
6364

64-
6565
OPTIONAL BUT RECOMMENDED
66+
6667
- **Make a batch file to automate the starting process**
67-
- Open a text editor
68-
- Paste the following code in a new document
69-
- Put your MeiliSearch master key instead of "your_master_key_goes_here"
70-
- Save the file as "C:/chatgpt-clone/chatgpt-clone.bat"
71-
- you can make a shortcut of this batch file and put it anywhere
68+
- Open a text editor
69+
- Paste the following code in a new document
70+
- Put your MeiliSearch master key instead of "your_master_key_goes_here"
71+
- Save the file as "C:/chatgpt-clone/chatgpt-clone.bat"
72+
- you can make a shortcut of this batch file and put it anywhere
7273

7374
```
7475
REM the meilisearch executable needs to be at the root of the chatgpt-clone directory
7576
7677
start "MeiliSearch" cmd /k "meilisearch --master-key your_master_key_goes_here
7778
78-
REM ↑↑↑ meilisearch is the name of the meilisearch executable, put your own master key there
79+
REM ↑↑↑ meilisearch is the name of the meilisearch executable, put your own master key there
7980
8081
start "ChatGPT-Clone" cmd /k "cd api && npm start"
8182

api/.env.example

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,68 @@ NODE_ENV=development
1515
# Change this to your MongoDB URI if different and I recommend appending chatgpt-clone
1616
MONGO_URI="mongodb://127.0.0.1:27017/chatgpt-clone"
1717

18-
# API key configuration.
19-
# Leave blank if you don't want them.
18+
19+
#############################
20+
# Endpoint OpenAI:
21+
#############################
22+
23+
# Access key from OpenAI platform
24+
# Leave it blank to disable this endpoint
2025
OPENAI_KEY=
2126

22-
# Default ChatGPT API Model, options: 'gpt-4', 'text-davinci-003', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0301'
23-
# you will have errors if you don't have access to a model like 'gpt-4', defaults to turbo if left empty/excluded.
24-
DEFAULT_API_GPT=gpt-3.5-turbo
27+
# Identify the available models, sperate by comma, and not space in it
28+
# Leave it blank to use internal settings.
29+
# OPENAI_MODELS=gpt-4,text-davinci-003,gpt-3.5-turbo,gpt-3.5-turbo-0301
30+
31+
# Reverse proxy setting for OpenAI
32+
# https://github.com/waylaidwanderer/node-chatgpt-api#using-a-reverse-proxy
33+
# OPENAI_REVERSE_PROXY=<YOUR REVERSE PROXY>
34+
35+
36+
#############################
37+
# Endpoint BingAI (Also jailbreak Sydney):
38+
#############################
39+
40+
# BingAI Tokens: the "_U" cookies value from bing.com
41+
# Leave it and BINGAI_USER_TOKEN blank to disable this endpoint.
42+
BINGAI_TOKEN=
43+
44+
# BingAI User defined Token
45+
# Allow user to set their own token by client
46+
# Uncomment this to enable this feature.
47+
# (Not implemented yet.)
48+
# BINGAI_USER_TOKEN=1
2549

26-
# _U Cookies Value from bing.com
27-
BING_TOKEN=
50+
51+
#############################
52+
# Endpoint chatGPT:
53+
#############################
2854

2955
# ChatGPT Browser Client (free but use at your own risk)
3056
# Access token from https://chat.openai.com/api/auth/session
31-
# Exposes your access token to a 3rd party
57+
# Exposes your access token to CHATGPT_REVERSE_PROXY
58+
# Leave it blank to disable this endpoint
3259
CHATGPT_TOKEN=
33-
# If you have access to other models on the official site, you can use them here.
34-
# Defaults to 'text-davinci-002-render-sha' if left empty.
35-
# options: gpt-4, text-davinci-002-render, text-davinci-002-render-paid, or text-davinci-002-render-sha
36-
# You cannot use a model that your account does not have access to. You can check
37-
# which ones you have access to by opening DevTools and going to the Network tab.
38-
# Refresh the page and look at the response body for https://chat.openai.com/backend-api/models.
39-
BROWSER_MODEL=
60+
61+
# Identify the available models, sperate by comma, and not space in it
62+
# Leave it blank to use internal settings.
63+
# CHATGPT_MODELS=text-davinci-002-render-sha,text-davinci-002-render-paid,gpt-4
64+
65+
# Reverse proxy setting for OpenAI
66+
# https://github.com/waylaidwanderer/node-chatgpt-api#using-a-reverse-proxy
67+
# By default it will use the node-chatgpt-api recommended proxy, (it's a third party server)
68+
# CHATGPT_REVERSE_PROXY=<YOUR REVERSE PROXY>
69+
70+
71+
#############################
72+
# Search:
73+
#############################
4074

4175
# ENABLING SEARCH MESSAGES/CONVOS
4276
# Requires installation of free self-hosted Meilisearch or Paid Remote Plan (Remote not tested)
4377
# The easiest setup for this is through docker-compose, which takes care of it for you.
44-
# SEARCH=TRUE
45-
SEARCH=TRUE
78+
# SEARCH=1
79+
SEARCH=1
4680

4781
# REQUIRED FOR SEARCH: MeiliSearch Host, mainly for api server to connect to the search server.
4882
# must replace '0.0.0.0' with 'meilisearch' if serving meilisearch with docker-compose
@@ -63,8 +97,11 @@ MEILI_HTTP_ADDR='0.0.0.0:7700' # <-- local/remote
6397
MEILI_MASTER_KEY=JKMW-hGc7v_D1FkJVdbRSDNFLZcUv3S75yrxXP0SmcU # <-- ready made secure key for docker-compose
6498

6599

100+
#############################
66101
# User System
67-
# global enable/disable the sample user system.
102+
#############################
103+
104+
# Enable the user system.
68105
# this is not a ready to use user system.
69106
# dont't use it, unless you can write your own code.
70107
# ENABLE_USER_SYSTEM= # <-- make sure you don't comment this back in if you're not using your own user system

api/app/clients/bingai.js

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
11
require('dotenv').config();
22
const { KeyvFile } = require('keyv-file');
33

4-
const askBing = async ({ text, onProgress, convo }) => {
4+
const askBing = async ({
5+
text,
6+
parentMessageId,
7+
conversationId,
8+
jailbreak,
9+
jailbreakConversationId,
10+
context,
11+
systemMessage,
12+
conversationSignature,
13+
clientId,
14+
invocationId,
15+
toneStyle,
16+
onProgress
17+
}) => {
518
const { BingAIClient } = await import('@waylaidwanderer/chatgpt-api');
19+
const store = {
20+
store: new KeyvFile({ filename: './data/cache.json' })
21+
};
622

723
const bingAIClient = new BingAIClient({
824
// "_U" cookie from bing.com
9-
userToken: process.env.BING_TOKEN,
25+
userToken: process.env.BINGAI_TOKEN,
1026
// If the above doesn't work, provide all your cookies as a string instead
1127
// cookies: '',
1228
debug: false,
13-
cache: { store: new KeyvFile({ filename: './data/cache.json' }) },
29+
cache: store,
1430
proxy: process.env.PROXY || null
1531
});
1632

17-
let options = { onProgress };
18-
if (convo) {
19-
options = { ...options, ...convo };
20-
}
33+
let options = {};
2134

22-
if (options?.jailbreakConversationId == 'false') {
23-
options.jailbreakConversationId = false;
35+
if (jailbreakConversationId == 'false') {
36+
jailbreakConversationId = false;
2437
}
2538

26-
if (convo.toneStyle) {
27-
options.toneStyle = convo.toneStyle;
39+
if (jailbreak)
40+
options = {
41+
jailbreakConversationId: jailbreakConversationId || jailbreak,
42+
context,
43+
systemMessage,
44+
parentMessageId,
45+
toneStyle,
46+
onProgress
47+
};
48+
else {
49+
options = {
50+
conversationId,
51+
context,
52+
systemMessage,
53+
parentMessageId,
54+
toneStyle,
55+
onProgress
56+
};
57+
58+
// don't give those parameters for new conversation
59+
// for new conversation, conversationSignature always is null
60+
if (conversationSignature) {
61+
options.conversationSignature = conversationSignature;
62+
options.clientId = clientId;
63+
options.invocationId = invocationId;
64+
}
2865
}
2966

3067
console.log('bing options', options);
@@ -33,30 +70,8 @@ const askBing = async ({ text, onProgress, convo }) => {
3370

3471
return res;
3572

36-
// Example response for reference
37-
// {
38-
// conversationSignature: 'wwZ2GC/qRgEqP3VSNIhbPGwtno5RcuBhzZFASOM+Sxg=',
39-
// conversationId: '51D|BingProd|026D3A4017554DE6C446798144B6337F4D47D5B76E62A31F31D0B1D0A95ED868',
40-
// clientId: '914800201536527',
41-
// invocationId: 1,
42-
// conversationExpiryTime: '2023-02-15T21:48:46.2892088Z',
43-
// response: 'Hello, this is Bing. Nice to meet you. 😊',
44-
// details: {
45-
// text: 'Hello, this is Bing. Nice to meet you. 😊',
46-
// author: 'bot',
47-
// createdAt: '2023-02-15T15:48:43.0631898+00:00',
48-
// timestamp: '2023-02-15T15:48:43.0631898+00:00',
49-
// messageId: '9d0c9a80-91b1-49ab-b9b1-b457dc3fe247',
50-
// requestId: '5b252ef8-4f09-4c08-b6f5-4499d2e12fba',
51-
// offense: 'None',
52-
// adaptiveCards: [ [Object] ],
53-
// sourceAttributions: [],
54-
// feedback: { tag: null, updatedOn: null, type: 'None' },
55-
// contentOrigin: 'DeepLeo',
56-
// privacy: null,
57-
// suggestedResponses: [ [Object], [Object], [Object] ]
58-
// }
59-
// }
73+
// for reference:
74+
// https://github.com/waylaidwanderer/node-chatgpt-api/blob/main/demos/use-bing-client.js
6075
};
6176

6277
module.exports = { askBing };

0 commit comments

Comments
 (0)