upgraded code

This commit is contained in:
Saifeddine ALOUI 2023-05-29 20:24:25 +02:00
parent 9946ea028b
commit 6bee09a734
9 changed files with 642 additions and 53 deletions

View File

@ -274,6 +274,36 @@ class DiscussionsDB:
)
discussions.append(discussion)
return discussions
def import_from_json(self, json_data):
discussions = []
data = json_data
for discussion_data in data:
discussion_id = discussion_data.get("id")
discussion_title = discussion_data.get("title")
messages_data = discussion_data.get("messages", [])
discussion = {"id": discussion_id, "title": discussion_title, "messages": []}
# Insert discussion into the database
self.insert("INSERT INTO discussion (id, title) VALUES (?, ?)", (discussion_id, discussion_title))
for message_data in messages_data:
sender = message_data.get("sender")
content = message_data.get("content")
content_type = message_data.get("type")
rank = message_data.get("rank")
parent = message_data.get("parent")
discussion["messages"].append(
{"sender": sender, "content": content, "type": content_type, "rank": rank, "parent": parent}
)
# Insert message into the database
self.insert("INSERT INTO message (sender, content, type, rank, parent, discussion_id) VALUES (?, ?, ?, ?, ?, ?)",
(sender, content, content_type, rank, parent, discussion_id))
discussions.append(discussion)
return discussions
class Discussion:
def __init__(self, discussion_id, discussions_db:DiscussionsDB):

View File

@ -1 +1,84 @@
# TODO : implement
try:
from langchain.llms.base import LLM
except ImportError:
raise ImportError(
'To use the ctransformers.langchain module, please install the '
'`langchain` python package: `pip install langchain`')
from typing import Any, Dict, Optional, Sequence
from pydantic import root_validator
from langchain.callbacks.manager import CallbackManagerForLLMRun
from api.binding import LLMBinding
class GenericBinding(LLM):
"""Wrapper around All compatible LLM interfaces.
Thanks to Marella for providing the base for this work.
To follow him, here is his github profile:
To use, you should have the `langchain` python package installed.
"""
client: Any #: :meta private:
model: str
"""The path to a model file or directory or the name of a Hugging Face Hub
model repo."""
model_type: Optional[str] = None
"""The model type."""
model_file: Optional[str] = None
"""The name of the model file in repo or directory."""
config: Optional[Dict[str, Any]] = None
"""The config parameters."""
lib: Optional[Any] = None
"""The path to a shared library or one of `avx2`, `avx`, `basic`."""
@property
def _identifying_params(self) -> Dict[str, Any]:
"""Get the identifying parameters."""
return {
'model': self.model,
'model_type': self.model_type,
'model_file': self.model_file,
'config': self.config,
}
@property
def _llm_type(self) -> str:
"""Return type of llm."""
return 'generic_binding'
@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
"""Validate and load model from a local file or remote repo."""
config = values['config'] or {}
values['client'] = LLMBinding(config, True)
return values
def _call(
self,
prompt: str,
stop: Optional[Sequence[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
) -> str:
"""Generate text from a prompt.
Args:
prompt: The prompt to generate text from.
stop: A list of sequences to stop generation when encountered.
Returns:
The generated text.
"""
text = []
for chunk in self.client(prompt, stop=stop, stream=True):
text.append(chunk)
if run_manager:
run_manager.on_llm_new_token(chunk, verbose=self.verbose)
return ''.join(text)

9
app.py
View File

@ -232,6 +232,11 @@ class Gpt4AllWebUI(GPT4AllAPI):
self.add_endpoint(
"/export_multiple_discussions", "export_multiple_discussions", self.export_multiple_discussions, methods=["POST"]
)
self.add_endpoint(
"/import_multiple_discussions", "import_multiple_discussions", self.import_multiple_discussions, methods=["POST"]
)
def export_multiple_discussions(self):
data = request.get_json()
@ -239,6 +244,10 @@ class Gpt4AllWebUI(GPT4AllAPI):
discussions = self.db.export_discussions_to_json(discussion_ids)
return jsonify(discussions)
def import_multiple_discussions(self):
data = request.get_json()
discussions = data
return jsonify(discussions)
def reset(self):
os.kill(os.getpid(), signal.SIGINT) # Send the interrupt signal to the current process

View File

@ -0,0 +1,468 @@
# Flask Backend API Documentation
This documentation provides an overview of the endpoints available in the Flask backend API.
## Introduction
The Flask backend API exposes various endpoints to interact with the application. Each endpoint performs a specific function and supports different HTTP methods. The following sections describe each endpoint along with their parameters and expected outputs.
## Endpoints
### Endpoint: /disk_usage (GET)
**Description**: Retrieves the disk usage of the system.
**Parameters**: None
**Output**: Returns the disk usage information.
---
### Endpoint: /list_bindings (GET)
**Description**: Lists the available bindings.
**Parameters**: None
**Output**: Returns a list of available bindings.
---
### Endpoint: /list_models (GET)
**Description**: Lists the available models.
**Parameters**: None
**Output**: Returns a list of available models.
---
### Endpoint: /list_personalities_languages (GET)
**Description**: Lists the languages supported by personalities.
**Parameters**: None
**Output**: Returns a list of languages supported by personalities.
---
### Endpoint: /list_personalities_categories (GET)
**Description**: Lists the categories of personalities.
**Parameters**: None
**Output**: Returns a list of personality categories.
---
### Endpoint: /list_personalities (GET)
**Description**: Lists the available personalities.
**Parameters**: None
**Output**: Returns a list of available personalities.
---
### Endpoint: /list_languages (GET)
**Description**: Lists the available languages.
**Parameters**: None
**Output**: Returns a list of available languages.
---
### Endpoint: /list_discussions (GET)
**Description**: Lists the discussions.
**Parameters**: None
**Output**: Returns a list of discussions.
---
### Endpoint: /set_personality (GET)
**Description**: Sets the active personality.
**Parameters**: None
**Output**: Sets the active personality.
---
### Endpoint: /delete_personality (GET)
**Description**: Deletes a personality.
**Parameters**: None
**Output**: Deletes the specified personality.
---
### Endpoint: / (GET)
**Description**: Returns the index page.
**Parameters**: None
**Output**: Returns the index page.
---
### Endpoint: /<path:filename> (GET)
**Description**: Serves static files.
**Parameters**: `filename` - The path to the static file.
**Output**: Returns the requested static file.
---
### Endpoint: /personalities/<path:filename> (GET)
**Description**: Serves personality files.
**Parameters**: `filename` - The path to the personality file.
**Output**: Returns the requested personality file.
---
### Endpoint: /outputs/<path:filename> (GET)
**Description**: Serves output files.
**Parameters**: `filename` - The path to the output file.
**Output**: Returns the requested output file.
---
### Endpoint: /export_discussion (GET)
**Description**: Exports a discussion.
**Parameters**: None
**Output**: Exports the specified discussion.
---
### Endpoint: /export (GET)
**Description**: Exports data.
**Parameters**: None
**Output**: Exports the specified data.
---
### Endpoint: /new_discussion (GET)
**Description**: Creates a new discussion.
**Parameters**: None
**Output**: Creates a new discussion.
---
### Endpoint: /stop_gen (GET)
**Description**: Stops the generation process.
**Parameters**: None
**Output**: Stops the generation process.
---
### Endpoint: /rename (POST)
**Description**: Renames a resource.
**Parameters**: None
**Output**: Renames the specified resource.
---
### Endpoint: /edit_title (POST)
**Description**: Edits the title of a resource.
**Parameters**: None
**Output**: Edits the title of the specified resource.
---
### Endpoint: /load_discussion (POST)
**Description**: Loads a discussion.
**Parameters**: None
**Output**: Loads the specified discussion.
---
### Endpoint: /delete_discussion (POST)
**Description**: Deletes a discussion.
**Parameters**: None
**Output**: Deletes the specified discussion.
---
### Endpoint: /update_message (GET)
**Description**: Updates a message.
**Parameters**: None
**Output**: Updates the specified message.
---
### Endpoint: /message_rank_up (GET)
**Description**: Increases the rank of a message.
**Parameters**: None
**Output**: Increases the rank of the specified message.
---
### Endpoint: /message_rank_down (GET)
**Description**: Decreases the rank of a message.
**Parameters**: None
**Output**: Decreases the rank of the specified message.
---
### Endpoint: /delete_message (GET)
**Description**: Deletes a message.
**Parameters**: None
**Output**: Deletes the specified message.
---
### Endpoint: /set_binding (POST)
**Description**: Sets a binding.
**Parameters**: None
**Output**: Sets the specified binding.
---
### Endpoint: /set_model (POST)
**Description**: Sets a model.
**Parameters**: None
**Output**: Sets the specified model.
---
### Endpoint: /update_model_params (POST)
**Description**: Updates model parameters.
**Parameters**: None
**Output**: Updates the specified model parameters.
---
### Endpoint: /get_config (GET)
**Description**: Retrieves the configuration.
**Parameters**: None
**Output**: Returns the configuration.
---
### Endpoint: /get_available_models (GET)
**Description**: Retrieves the available models.
**Parameters**: None
**Output**: Returns a list of available models.
---
### Endpoint: /extensions (GET)
**Description**: Retrieves the extensions.
**Parameters**: None
**Output**: Returns the extensions.
---
### Endpoint: /training (GET)
**Description**: Performs training.
**Parameters**: None
**Output**: Performs the training process.
---
### Endpoint: /main (GET)
**Description**: Returns the main page.
**Parameters**: None
**Output**: Returns the main page.
---
### Endpoint: /settings (GET)
**Description**: Returns the settings page.
**Parameters**: None
**Output**: Returns the settings page.
---
### Endpoint: /help (GET)
**Description**: Returns the help page.
**Parameters**: None
**Output**: Returns the help page.
---
### Endpoint: /get_generation_status (GET)
**Description**: Retrieves the generation status.
**Parameters**: None
**Output**: Returns the generation status.
---
### Endpoint: /update_setting (POST)
**Description**: Updates a setting.
**Parameters**: None
**Output**: Updates the specified setting.
---
### Endpoint: /apply_settings (POST)
**Description**: Applies the settings.
**Parameters**: None
**Output**: Applies the specified settings.
---
### Endpoint: /save_settings (POST)
**Description**: Saves the settings.
**Parameters**: None
**Output**: Saves the specified settings.
---
### Endpoint: /get_current_personality (GET)
**Description**: Retrieves the current personality.
**Parameters**: None
**Output**: Returns the current personality.
---
### Endpoint: /get_all_personalities (GET)
**Description**: Retrieves all personalities.
**Parameters**: None
**Output**: Returns a list of all personalities.
---
### Endpoint: /get_personality (GET)
**Description**: Retrieves a specific personality.
**Parameters**: None
**Output**: Returns the specified personality.
---
### Endpoint: /reset (GET)
**Description**: Resets the system.
**Parameters**: None
**Output**: Resets the system.
---
### Endpoint: /export_multiple_discussions (POST)
**Description**: Exports multiple discussions.
**Parameters**: None
**Output**: Exports the specified discussions.
---
### Endpoint: /import_multiple_discussions (POST)
**Description**: Imports multiple discussions.
**Parameters**: None
**Output**: Imports the specified discussions.

File diff suppressed because one or more lines are too long

1
web/dist/assets/index-86ec2b95.css vendored Normal file

File diff suppressed because one or more lines are too long

48
web/dist/assets/index-9deab5e4.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPT4All - WEBUI</title>
<script type="module" crossorigin src="/assets/index-0e9c5983.js"></script>
<link rel="stylesheet" href="/assets/index-c9ce79a4.css">
<script type="module" crossorigin src="/assets/index-9deab5e4.js"></script>
<link rel="stylesheet" href="/assets/index-86ec2b95.css">
</head>
<body>
<div id="app"></div>