mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-18 20:17:50 +00:00
synced
This commit is contained in:
parent
046f3be530
commit
1d3a0ce7aa
@ -8,14 +8,17 @@ description:
|
||||
|
||||
"""
|
||||
from fastapi import APIRouter, Request
|
||||
from pydantic import BaseModel, Field
|
||||
from lollms_webui import LOLLMSWebUI
|
||||
from pydantic import BaseModel
|
||||
from starlette.responses import StreamingResponse
|
||||
from lollms.types import MSG_TYPE
|
||||
from lollms.main_config import BaseConfig
|
||||
from lollms.utilities import detect_antiprompt, remove_text_from_string, trace_exception
|
||||
from lollms.utilities import detect_antiprompt, remove_text_from_string, trace_exception, find_first_available_file_index
|
||||
from ascii_colors import ASCIIColors
|
||||
from lollms.databases.discussions_database import DiscussionsDB
|
||||
from lollms.types import SENDER_TYPES
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
from safe_store.text_vectorizer import TextVectorizer, VectorizationMethod, VisualizationMethod
|
||||
import tqdm
|
||||
@ -23,7 +26,8 @@ from fastapi import FastAPI, UploadFile, File
|
||||
import shutil
|
||||
import os
|
||||
import platform
|
||||
|
||||
from functools import partial
|
||||
from datetime import datetime
|
||||
from utilities.execution_engines.python_execution_engine import execute_python
|
||||
from utilities.execution_engines.latex_execution_engine import execute_latex
|
||||
from utilities.execution_engines.shell_execution_engine import execute_bash
|
||||
@ -32,3 +36,90 @@ from utilities.execution_engines.shell_execution_engine import execute_bash
|
||||
|
||||
router = APIRouter()
|
||||
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
||||
|
||||
class AddWebPageRequest(BaseModel):
|
||||
client_id: str = Field(...)
|
||||
url: str = Field(..., description="Url to be used")
|
||||
|
||||
class CmdExecutionRequest(BaseModel):
|
||||
client_id: str = Field(...)
|
||||
command: str = Field(..., description="Url to be used")
|
||||
parameters: List
|
||||
|
||||
@router.post("/execute_personality_command")
|
||||
async def execute_personality_command(request: CmdExecutionRequest):
|
||||
client_id = request.client_id
|
||||
client = lollmsElfServer.session.get_client(client_id)
|
||||
|
||||
lollmsElfServer.cancel_gen = False
|
||||
client.generated_text=""
|
||||
client.cancel_generation=False
|
||||
client.continuing=False
|
||||
client.first_chunk=True
|
||||
|
||||
if not lollmsElfServer.model:
|
||||
ASCIIColors.error("Model not selected. Please select a model")
|
||||
lollmsElfServer.error("Model not selected. Please select a model", client_id=client_id)
|
||||
return {'status':False,"error":"Model not selected. Please select a model"}
|
||||
|
||||
if not lollmsElfServer.busy:
|
||||
if lollmsElfServer.session.get_client(client_id).discussion is None:
|
||||
if lollmsElfServer.db.does_last_discussion_have_messages():
|
||||
lollmsElfServer.session.get_client(client_id).discussion = lollmsElfServer.db.create_discussion()
|
||||
else:
|
||||
lollmsElfServer.session.get_client(client_id).discussion = lollmsElfServer.db.load_last_discussion()
|
||||
|
||||
ump = lollmsElfServer.config.discussion_prompt_separator +lollmsElfServer.config.user_name.strip() if lollmsElfServer.config.use_user_name_in_discussions else lollmsElfServer.personality.user_message_prefix
|
||||
message = lollmsElfServer.session.get_client(client_id).discussion.add_message(
|
||||
message_type = MSG_TYPE.MSG_TYPE_FULL.value,
|
||||
sender_type = SENDER_TYPES.SENDER_TYPES_USER.value,
|
||||
sender = ump.replace(lollmsElfServer.config.discussion_prompt_separator,"").replace(":",""),
|
||||
content="",
|
||||
metadata=None,
|
||||
parent_message_id=lollmsElfServer.message_id
|
||||
)
|
||||
lollmsElfServer.busy=True
|
||||
|
||||
command = request.command
|
||||
parameters = request.parameters
|
||||
lollmsElfServer.prepare_reception(client_id)
|
||||
if lollmsElfServer.personality.processor is not None:
|
||||
lollmsElfServer.start_time = datetime.now()
|
||||
lollmsElfServer.personality.processor.callback = partial(lollmsElfServer.process_chunk, client_id=client_id)
|
||||
lollmsElfServer.personality.processor.execute_command(command, parameters)
|
||||
else:
|
||||
lollmsElfServer.warning("Non scripted personalities do not support commands",client_id=client_id)
|
||||
lollmsElfServer.close_message(client_id)
|
||||
lollmsElfServer.busy=False
|
||||
|
||||
#tpe = threading.Thread(target=lollmsElfServer.start_message_generation, args=(message, message_id, client_id))
|
||||
#tpe.start()
|
||||
else:
|
||||
lollmsElfServer.error("I am busy. Come back later.", client_id=client_id)
|
||||
return {'status':False,"error":"I am busy. Come back later."}
|
||||
|
||||
lollmsElfServer.busy=False
|
||||
return {'status':True,}
|
||||
|
||||
@router.post("/add_webpage")
|
||||
async def add_webpage(request: AddWebPageRequest):
|
||||
lollmsElfServer.ShowBlockingMessage("Scraping web page\nPlease wait...")
|
||||
ASCIIColors.yellow("Scaping web page")
|
||||
client = lollmsElfServer.session.get_client(request.client_id)
|
||||
url = request.url
|
||||
index = find_first_available_file_index(lollmsElfServer.lollms_paths.personal_uploads_path,"web_",".txt")
|
||||
file_path=lollmsElfServer.lollms_paths.personal_uploads_path/f"web_{index}.txt"
|
||||
lollmsElfServer.scrape_and_save(url=url, file_path=file_path)
|
||||
try:
|
||||
if not lollmsElfServer.personality.processor is None:
|
||||
lollmsElfServer.personality.processor.add_file(file_path, client, partial(lollmsElfServer.process_chunk, client_id = request.client_id))
|
||||
# File saved successfully
|
||||
else:
|
||||
lollmsElfServer.personality.add_file(file_path, client, partial(lollmsElfServer.process_chunk, client_id = request.client_id))
|
||||
# File saved successfully
|
||||
lollmsElfServer.HideBlockingMessage()
|
||||
return {'status':True,}
|
||||
except Exception as e:
|
||||
# Error occurred while saving the file
|
||||
lollmsElfServer.HideBlockingMessage()
|
||||
return {'status':False,"error":str(e)}
|
||||
|
@ -67,6 +67,7 @@ def add_events(sio:socketio):
|
||||
|
||||
@sio.on('add_webpage')
|
||||
def add_webpage(sid, data):
|
||||
lollmsElfServer.ShowBlockingMessage("Scraping web page\nPlease wait...")
|
||||
ASCIIColors.yellow("Scaping web page")
|
||||
client = lollmsElfServer.session.get_client(sid)
|
||||
url = data['url']
|
||||
@ -82,9 +83,11 @@ def add_events(sio:socketio):
|
||||
lollmsElfServer.personality.add_file(file_path, client, partial(lollmsElfServer.process_chunk, client_id = sid))
|
||||
# File saved successfully
|
||||
run_async(partial(sio.emit,'web_page_added', {'status':True}))
|
||||
lollmsElfServer.HideBlockingMessage()
|
||||
except Exception as e:
|
||||
# Error occurred while saving the file
|
||||
run_async(partial(sio.emit,'web_page_added', {'status':False}))
|
||||
lollmsElfServer.HideBlockingMessage()
|
||||
|
||||
@sio.on('take_picture')
|
||||
def take_picture(sid):
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 5d4b5faa0f50aa2649d64fd7bfb2a5ab46f95fdc
|
||||
Subproject commit ddba6ed36413048fed0c5363926aa1520987c064
|
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
4
web/dist/index.html
vendored
@ -6,8 +6,8 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>LoLLMS WebUI - Welcome</title>
|
||||
<script type="module" crossorigin src="/assets/index-9c94bfac.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index-b3fd63c8.css">
|
||||
<script type="module" crossorigin src="/assets/index-f3eff979.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index-2184e400.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
@ -296,7 +296,7 @@
|
||||
<ProgressBar ref="progress" :progress="progress_value" class="w-full h-4"></ProgressBar>
|
||||
<p class="text-2xl animate-pulse mt-2 text-white">{{ loading_infos }} ...</p>
|
||||
</div>
|
||||
<InputBox prompt-text="Enter the url to the page to use as discussion support" @ok="handleOk" ref="web_url_input_box"></InputBox>
|
||||
<InputBox prompt-text="Enter the url to the page to use as discussion support" @ok="addWebpage" ref="web_url_input_box"></InputBox>
|
||||
<SkillsLibraryViewer ref="skills_lib"></SkillsLibraryViewer>
|
||||
</template>
|
||||
|
||||
@ -465,7 +465,15 @@ export default {
|
||||
console.log("addWebLink received")
|
||||
this.$refs.web_url_input_box.showPanel();
|
||||
},
|
||||
handleOk(){
|
||||
addWebpage(){
|
||||
|
||||
axios.post('/add_webpage', {"client_id":this.client_id, "url": this.$refs.web_url_input_box.inputText}, {headers: this.posts_headers}).then(response => {
|
||||
if (response && response.status){
|
||||
console.log("Done")
|
||||
this.recoverFiles()
|
||||
}
|
||||
});
|
||||
/*
|
||||
console.log("OK")
|
||||
socket.on('web_page_added',()=>{
|
||||
axios.get('/get_current_personality_files_list').then(res=>{
|
||||
@ -478,6 +486,7 @@ export default {
|
||||
})
|
||||
});
|
||||
socket.emit('add_webpage',{'url':this.$refs.web_url_input_box.inputText})
|
||||
*/
|
||||
},
|
||||
show_progress(data){
|
||||
this.progress_visibility_val = true;
|
||||
@ -1271,6 +1280,23 @@ export default {
|
||||
},
|
||||
sendCmd(cmd){
|
||||
this.isGenerating = true;
|
||||
// axios.post('/execute_personality_command', {command: cmd, parameters:[]})
|
||||
// .then((res) => {
|
||||
// if (res) {
|
||||
// if (res.status) {
|
||||
// this.$store.state.toast.showToast("Command executed",4,true)
|
||||
// }
|
||||
// else
|
||||
// this.$store.state.messageBox.showMessage("Error: Couldn't execute command!")
|
||||
// return res.data;
|
||||
// }
|
||||
// })
|
||||
// .catch(error => {
|
||||
// console.log(error.message, 'save_configuration')
|
||||
// this.$store.state.messageBox.showMessage("Couldn't save settings!")
|
||||
|
||||
// });
|
||||
|
||||
socket.emit('execute_command', { command: cmd, parameters: [] });
|
||||
},
|
||||
notify(notif){
|
||||
|
Loading…
Reference in New Issue
Block a user