Added documentaAdded more docs and added settings configuration endpointstion

This commit is contained in:
ParisNeo 2023-05-05 01:50:43 +02:00
parent c1860cccfc
commit e1e92ce278
12 changed files with 181 additions and 15 deletions

View File

@ -5,6 +5,7 @@
![GitHub stars](https://img.shields.io/github/stars/nomic-ai/GPT4All-ui)
![GitHub forks](https://img.shields.io/github/forks/nomic-ai/GPT4All-ui)
[![Discord](https://img.shields.io/discord/1092918764925882418?color=7289da&label=Discord&logo=discord&logoColor=ffffff)](https://discord.gg/4rR282WJb6)
[![Twitter Follow](https://img.shields.io/twitter/follow/SpaceNerduino?style=social)](https://twitter.com/SpaceNerduino)
This is a Flask web application that provides a chat UI for interacting with [llamacpp](https://github.com/ggerganov/llama.cpp), gpt-j, gpt-q as well as Hugging face based language models uch as [GPT4all](https://github.com/nomic-ai/gpt4all), vicuna etc...
@ -195,7 +196,7 @@ On Linux/MacOS more details can be found [here](docs/Linux_Osx_Usage.md)
* `--top-p`: the cumulative probability threshold for top-p sampling (default: 0.90)
* `--repeat-penalty`: the penalty to apply for repeated n-grams (default: 1.3)
* `--repeat-last-n`: the number of tokens to use for detecting repeated n-grams (default: 64)
* `--ctx-size`: the maximum context size to use for generating responses (default: 2048)
* `--ctx-size`: the maximum context size to use for generating responses (default: 512)
Note: All options are optional and have default values.

91
app.py
View File

@ -203,7 +203,83 @@ class Gpt4AllWebUI(GPT4AllAPI):
tpe = threading.Thread(target=self.parse_to_prompt_stream, args=(message, message_id))
tpe.start()
# Settings (data: {"setting_name":<the setting name>,"setting_value":<the setting value>})
@socketio.on('update_setting')
def update_setting(data):
setting_name = int(data['setting_name'])
if setting_name== "temperature":
self.config["temperature"]=float(data['setting_value'])
elif setting_name== "top_k":
self.config["top_k"]=int(data['setting_value'])
elif setting_name== "top_p":
self.config["top_p"]=float(data['setting_value'])
elif setting_name== "n_predict":
self.config["n_predict"]=int(data['setting_value'])
elif setting_name== "n_threads":
self.config["n_threads"]=int(data['setting_value'])
elif setting_name== "ctx_size":
self.config["ctx_size"]=int(data['setting_value'])
elif setting_name== "repeat_penalty":
self.config["repeat_penalty"]=float(data['setting_value'])
elif setting_name== "repeat_last_n":
self.config["repeat_last_n"]=int(data['setting_value'])
elif setting_name== "language":
self.config["language"]=data['setting_value']
elif setting_name== "personality_language":
self.config["personality_language"]=data['setting_value']
elif setting_name== "personality_category":
self.config["personality_category"]=data['setting_value']
elif setting_name== "personality":
self.config["personality"]=data['setting_value']
elif setting_name== "model":
self.config["model"]=data['setting_value']
print("New model selected")
# Build chatbot
self.chatbot_bindings = self.create_chatbot()
elif setting_name== "backend":
print("New backend selected")
if self.config['backend']!= data['setting_value']:
print("New backend selected")
self.config["backend"]=data['setting_value']
backend_ =self.load_backend(self.BACKENDS_LIST[self.config["backend"]])
models = backend_.list_models(self.config)
if len(models)>0:
self.backend = backend_
self.config['model'] = models[0]
# Build chatbot
self.chatbot_bindings = self.create_chatbot()
self.socketio.emit('update_setting', {'setting_name': data['setting_name'], "status":True});
return
else:
self.socketio.emit('update_setting', {'setting_name': data['setting_name'], "status":False});
return
else:
self.socketio.emit('update_setting', {'setting_name': data['setting_name'], "status":False});
return
# Tell that the setting was changed
self.socketio.emit('update_setting', {'setting_name': data['setting_name'], "status":True});
# Settings (data: {"setting_name":<the setting name>,"setting_value":<the setting value>})
@socketio.on('save_settings')
def save_settings(data):
save_config(self.config, self.config_file_path)
# Tell that the setting was changed
self.socketio.emit('save_settings', {"status":True});
def list_backends(self):
@ -501,7 +577,7 @@ class Gpt4AllWebUI(GPT4AllAPI):
self.config['voice'] = str(data["voice"])
self.config['language'] = str(data["language"])
self.config['temp'] = float(data["temp"])
self.config['temperature'] = float(data["temperature"])
self.config['top_k'] = int(data["topK"])
self.config['top_p'] = float(data["topP"])
self.config['repeat_penalty'] = float(data["repeatPenalty"])
@ -518,7 +594,7 @@ class Gpt4AllWebUI(GPT4AllAPI):
print(f"\tPersonality:{self.config['personality']}")
print(f"\tLanguage:{self.config['language']}")
print(f"\tVoice:{self.config['voice']}")
print(f"\tTemperature:{self.config['temp']}")
print(f"\tTemperature:{self.config['temperature']}")
print(f"\tNPredict:{self.config['n_predict']}")
print(f"\tSeed:{self.config['seed']}")
print(f"\top_k:{self.config['top_k']}")
@ -621,14 +697,25 @@ if __name__ == "__main__":
# The default configuration must be kept unchanged as it is committed to the repository,
# so we have to make a copy that is not comitted
default_config = load_config(f"configs/default.yaml")
if args.config=="default":
args.config = "local_default"
if not Path(f"configs/local_default.yaml").exists():
print("No local configuration file found. Building from scratch")
shutil.copy(f"configs/default.yaml", f"configs/local_default.yaml")
config_file_path = f"configs/{args.config}.yaml"
config = load_config(config_file_path)
if "version" not in config or int(config["version"])<int(default_config["version"]):
#Upgrade old configuration files to new format
print("Configuration file is very old. Replacing with default configuration")
for key, value in default_config.items():
if key not in config:
config[key] = value
save_config(config, config_file_path)
# Override values in config with command-line arguments
for arg_name, arg_value in vars(args).items():
if arg_value is not None:

View File

@ -57,7 +57,7 @@ class LLAMACPP(GPTBackend):
self.model.reset()
for tok in self.model.generate(prompt,
n_predict=n_predict,
temp=self.config['temp'],
temp=self.config['temperature'],
top_k=self.config['top_k'],
top_p=self.config['top_p'],
repeat_penalty=self.config['repeat_penalty'],

View File

@ -1,3 +1,4 @@
version: 2
config: default
ctx_size: 512
db_path: databases/database.db
@ -17,7 +18,7 @@ port: 9600
repeat_last_n: 40
repeat_penalty: 1.2
seed: 0
temp: 0.9
temperature: 0.9
top_k: 50
top_p: 0.95
voice: ""

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -0,0 +1,76 @@
# Server endpoints documentation
## Introduction:
This Flask server provides various endpoints to manage and interact with the chatbot. Here's a brief explanation of the endpoints available:
## Endpoints:
"/list_backends": GET request endpoint to list all the available backends.
"/list_models": GET request endpoint to list all the available models.
"/list_personalities_languages": GET request endpoint to list all the available personality languages.
"/list_personalities_categories": GET request endpoint to list all the available personality categories.
"/list_personalities": GET request endpoint to list all the available personalities.
"/list_languages": GET request endpoint to list all the available languages.
"/list_discussions": GET request endpoint to list all the available discussions.
"/set_personality_language": GET request endpoint to set the personality language.
"/set_personality_category": GET request endpoint to set the personality category.
"/": GET request endpoint to display the index page.
"/path:filename": GET request endpoint to serve static files.
"/export_discussion": GET request endpoint to export the current discussion.
"/export": GET request endpoint to export the chatbot's data.
"/new_discussion": GET request endpoint to create a new discussion.
"/stop_gen": GET request endpoint to stop the chatbot from generating responses.
"/rename": POST request endpoint to rename a discussion.
"/edit_title": POST request endpoint to edit the title of a discussion.
"/load_discussion": POST request endpoint to load a discussion.
"/delete_discussion": POST request endpoint to delete a discussion.
"/update_message": GET request endpoint to update a message.
"/message_rank_up": GET request endpoint to rank up a message.
"/message_rank_down": GET request endpoint to rank down a message.
"/delete_message": GET request endpoint to delete a message.
"/set_backend": POST request endpoint to set the backend.
"/set_model": POST request endpoint to set the model.
"/update_model_params": POST request endpoint to update the model parameters.
"/get_config": GET request endpoint to get the chatbot's configuration.
"/extensions": GET request endpoint to list all the available extensions.
"/training": GET request endpoint to start the training process.
"/main": GET request endpoint to start the chatbot.
"/settings": GET request endpoint to display the settings page.
"/help": GET request endpoint to display the help page.
# Socketio endpoints
These are the WebSocket server endpoints that are used to handle real-time communication between the client and server using the SocketIO library.
The first decorator `@socketio.on('connect')` listens for a connection event and calls the `connect()` function when a client connects to the server. Similarly, the second decorator `@socketio.on('disconnect')` listens for a disconnection event and calls the `disconnect()` function when a client disconnects from the server.
The third decorator `@socketio.on('generate_msg')` is used to handle the event of generating a message. It takes the data sent by the client and adds a new message to the current discussion with the user as the sender and the message content as the prompt. It then starts a new thread to parse the prompt into a prompt stream.
The fourth decorator `@socketio.on('generate_msg_from')` is used to handle the event of generating a message from a specific message ID. It takes the data sent by the client which includes the message ID and message prompt and starts a new thread to parse the prompt into a prompt stream.
The fifth decorator `@socketio.on('update_setting')`, listens for updates to the chatbot's configuration settings. The listener takes in a JSON object that contains the name of the setting being updated (setting_name) and the new value for the setting (setting_value). The function then updates the corresponding value in the chatbot's configuration dictionary based on the setting_name. The updated setting is then sent to the client with a status flag indicating whether the update was successful.
The sixth decorator `@socketio.on('save_settings')`, listens for a request from the client to save the current chatbot settings to a file. When triggered, the save_settings function writes the current configuration dictionary to a file specified by self.config_file_path. Once the file has been written, the function sends a status flag indicating whether the save was successful to the client.
The available settings are:
- `temperature`: A floating-point value that determines the creativity of the chatbot's responses. Higher values will result in more diverse and unpredictable responses, while lower values will result in more conservative and predictable responses.
- `top_k`: An integer that determines the number of most likely tokens to consider at each step of generating a response. Smaller values will result in more conservative and predictable responses, while larger values will result in more diverse and unpredictable responses.
- `top_p`: A floating-point value between 0 and 1 that determines the probability mass threshold for including the next token in the generated response. Smaller values will result in more conservative and predictable responses, while larger values will result in more diverse and unpredictable responses.
- `n_predict`: An integer that determines the number of responses the chatbot generates for a given prompt.
- `n_threads`: An integer that determines the number of threads to use for generating responses.
- `ctx_size`: An integer that determines the maximum number of tokens to include in the context for generating responses.
- `repeat_penalty`: A floating-point value that determines the penalty for repeating the same token or sequence of tokens in a generated response. Higher values will result in the chatbot being less likely to repeat itself.
- `repeat_last_n`: An integer that determines the number of previous generated tokens to consider for the repeat_penalty calculation.
- `language`: A string representing the language for audio input.
- `personality_language`: A string representing the language to use for generating personality traits.
- `personality_category`: A string representing the category of personality traits to use for generating responses.
- `personality`: A string representing the name of a specific personality traits to use for generating responses.
- `model`: A string representing the model to use for generating responses.
- `backend`: A string representing the backend to use for generating responses.
The save_settings function is used to save the updated settings to a configuratio
## How to use:
Call from client side.

View File

@ -178,7 +178,7 @@ class GPT4AllAPI():
self.bot_says += text
if not self.personality.detect_antiprompt(self.bot_says):
self.socketio.emit('message', {'data': self.bot_says});
self.socketio.emit('message', {'data': self.bot_says})
if self.cancel_gen:
print("Generation canceled")
self.cancel_gen = False
@ -200,7 +200,7 @@ class GPT4AllAPI():
self.discussion_messages,
new_text_callback=self.new_text_callback,
n_predict=total_n_predict,
temp=self.config['temp'],
temp=self.config['temperature'],
top_k=self.config['top_k'],
top_p=self.config['top_p'],
repeat_penalty=self.config['repeat_penalty'],

View File

@ -19,6 +19,7 @@ __license__ = "Apache 2.0"
def load_config(file_path):
with open(file_path, 'r', encoding='utf-8') as stream:
config = yaml.safe_load(stream)
return config

View File

@ -21,7 +21,7 @@ fetch('/settings')
languageInput = document.getElementById('language');
voiceInput = document.getElementById('voice');
seedInput = document.getElementById('seed');
tempInput = document.getElementById('temp');
tempInput = document.getElementById('temperature');
nPredictInput = document.getElementById('n-predict');
topKInput = document.getElementById('top-k');
topPInput = document.getElementById('top-p');
@ -51,7 +51,7 @@ fetch('/settings')
languageInput.value = data["language"]
voiceInput.value = data["voice"]
seedInput.value = data["seed"]
tempInput.value = data["temp"]
tempInput.value = data["temperature"]
nPredictInput.value = data["n_predict"]
topKInput.value = data["top_k"]
topPInput.value = data["top_p"]
@ -59,7 +59,7 @@ fetch('/settings')
repeatPenaltyInput.textContent = data["repeat_penalty"]
repeatLastNInput.textContent = data["repeat_last_n"]
temperatureValue.textContent =`Temperature(${data["temp"]})`
temperatureValue.textContent =`Temperature(${data["temperature"]})`
n_predictValue.textContent =`N Predict(${data["n_predict"]})`
topkValue.textContent =`Top-K(${data["top_k"]})`

View File

@ -41,8 +41,8 @@
<input class="bg-gray-200 dark:bg-gray-700 shadow appearance-none border rounded py-2 px-3 leading-tight focus:outline-none focus:shadow-outline" id="seed" type="text" name="seed" value="0">
</div>
<div class="mb-4 flex-row">
<label class="font-bold mb-2" for="temp" id="temperature-value">Temperature (0.1)</label>
<input class="slider-value" id="temp" type="range" min="0" max="5" step="0.1" value="0.01" name="temp">
<label class="font-bold mb-2" for="temperature" id="temperature-value">Temperature (0.1)</label>
<input class="slider-value" id="temperature" type="range" min="0" max="5" step="0.1" value="0.01" name="temperature">
</div>
<div class="mb-4 flex-row">
<label class="font-bold mb-2" for="n-predict" id="n-predict-value">N Predict (256)</label>

File diff suppressed because one or more lines are too long

View File

@ -68,7 +68,7 @@
<div class="flex flex-col align-bottom ">
<div class="relative">
<p class="absolute left-0 mt-6">
<label for="temp" class=" text-sm font-medium">
<label for="temperature" class=" text-sm font-medium">
Temperature:
</label>
</p>
@ -80,7 +80,7 @@
</div>
<input id="temp" type="range" v-model="configFile.temp" min="0" max="5" step="0.1"
<input id="temperature" type="range" v-model="configFile.temp" min="0" max="5" step="0.1"
class="flex-none h-2 mt-14 mb-2 w-full bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 focus:ring-blue-500 focus:border-blue-500 dark:border-gray-600 dark:placeholder-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500">
</div>
</div>