|
|
@ -8,26 +8,20 @@ import warnings
|
|
|
|
from swarms.modelui.modules.block_requests import OpenMonkeyPatch, RequestBlocker
|
|
|
|
from swarms.modelui.modules.block_requests import OpenMonkeyPatch, RequestBlocker
|
|
|
|
from swarms.modelui.modules.logging_colors import logger
|
|
|
|
from swarms.modelui.modules.logging_colors import logger
|
|
|
|
|
|
|
|
|
|
|
|
from vllm import LLM
|
|
|
|
from vllm import LLM
|
|
|
|
|
|
|
|
|
|
|
|
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
|
|
|
os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
|
|
|
|
os.environ["BITSANDBYTES_NOWELCOME"] = "1"
|
|
|
|
os.environ['BITSANDBYTES_NOWELCOME'] = '1'
|
|
|
|
warnings.filterwarnings(
|
|
|
|
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
|
|
|
|
"ignore", category=UserWarning, message="TypedStorage is deprecated"
|
|
|
|
warnings.filterwarnings('ignore', category=UserWarning, message='Using the update method is deprecated')
|
|
|
|
)
|
|
|
|
warnings.filterwarnings('ignore', category=UserWarning, message='Field "model_name" has conflict')
|
|
|
|
warnings.filterwarnings(
|
|
|
|
|
|
|
|
"ignore", category=UserWarning, message="Using the update method is deprecated"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
warnings.filterwarnings(
|
|
|
|
|
|
|
|
"ignore", category=UserWarning, message='Field "model_name" has conflict'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with RequestBlocker():
|
|
|
|
with RequestBlocker():
|
|
|
|
import gradio as gr
|
|
|
|
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
import matplotlib
|
|
|
|
import matplotlib
|
|
|
|
|
|
|
|
|
|
|
|
matplotlib.use("Agg") # This fixes LaTeX rendering on some systems
|
|
|
|
matplotlib.use('Agg') # This fixes LaTeX rendering on some systems
|
|
|
|
|
|
|
|
|
|
|
|
import swarms.modelui.modules.extensions as extensions_module
|
|
|
|
import swarms.modelui.modules.extensions as extensions_module
|
|
|
|
from swarms.modelui.modules import (
|
|
|
|
from swarms.modelui.modules import (
|
|
|
@ -42,7 +36,7 @@ from swarms.modelui.modules import (
|
|
|
|
ui_notebook,
|
|
|
|
ui_notebook,
|
|
|
|
ui_parameters,
|
|
|
|
ui_parameters,
|
|
|
|
ui_session,
|
|
|
|
ui_session,
|
|
|
|
utils,
|
|
|
|
utils
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from swarms.modelui.modules.extensions import apply_extensions
|
|
|
|
from swarms.modelui.modules.extensions import apply_extensions
|
|
|
|
from swarms.modelui.modules.LoRA import add_lora_to_model
|
|
|
|
from swarms.modelui.modules.LoRA import add_lora_to_model
|
|
|
@ -50,7 +44,7 @@ from swarms.modelui.modules.models import load_model
|
|
|
|
from swarms.modelui.modules.models_settings import (
|
|
|
|
from swarms.modelui.modules.models_settings import (
|
|
|
|
get_fallback_settings,
|
|
|
|
get_fallback_settings,
|
|
|
|
get_model_metadata,
|
|
|
|
get_model_metadata,
|
|
|
|
update_model_parameters,
|
|
|
|
update_model_parameters
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from swarms.modelui.modules.utils import gradio
|
|
|
|
from swarms.modelui.modules.utils import gradio
|
|
|
|
|
|
|
|
|
|
|
@ -68,8 +62,6 @@ import time
|
|
|
|
from langchain.llms import VLLM
|
|
|
|
from langchain.llms import VLLM
|
|
|
|
|
|
|
|
|
|
|
|
tool_server_flag = False
|
|
|
|
tool_server_flag = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_tool_server():
|
|
|
|
def start_tool_server():
|
|
|
|
# server = Thread(target=run_tool_server)
|
|
|
|
# server = Thread(target=run_tool_server)
|
|
|
|
server = Process(target=run_tool_server)
|
|
|
|
server = Process(target=run_tool_server)
|
|
|
@ -78,9 +70,12 @@ def start_tool_server():
|
|
|
|
tool_server_flag = True
|
|
|
|
tool_server_flag = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
available_models = ["ChatGPT", "GPT-3.5"]
|
|
|
|
|
|
|
|
DEFAULTMODEL = "ChatGPT" # "GPT-3.5"
|
|
|
|
DEFAULTMODEL = "ChatGPT" # "GPT-3.5"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Read the model/ directory and get the list of models
|
|
|
|
|
|
|
|
model_dir = Path("./models/")
|
|
|
|
|
|
|
|
available_models = ["ChatGPT", "GPT-3.5"] + [f.name for f in model_dir.iterdir() if f.is_dir()]
|
|
|
|
|
|
|
|
|
|
|
|
tools_mappings = {
|
|
|
|
tools_mappings = {
|
|
|
|
"klarna": "https://www.klarna.com/",
|
|
|
|
"klarna": "https://www.klarna.com/",
|
|
|
|
"weather": "http://127.0.0.1:8079/tools/weather/",
|
|
|
|
"weather": "http://127.0.0.1:8079/tools/weather/",
|
|
|
@ -132,23 +127,21 @@ chat_history = ""
|
|
|
|
|
|
|
|
|
|
|
|
MAX_SLEEP_TIME = 40
|
|
|
|
MAX_SLEEP_TIME = 40
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def download_model(model_url: str, memory_utilization: int):
|
|
|
|
def download_model(model_url: str, memory_utilization: int):
|
|
|
|
# Extract model name from the URL
|
|
|
|
# Extract model name from the URL
|
|
|
|
model_name = model_url.split("/")[-1]
|
|
|
|
model_name = model_url.split('/')[-1]
|
|
|
|
# Download the model using VLLM
|
|
|
|
# Download the model using VLLM
|
|
|
|
vllm_model = VLLM(
|
|
|
|
vllm_model = VLLM(
|
|
|
|
model=model_url,
|
|
|
|
model=model_url,
|
|
|
|
trust_remote_code=True,
|
|
|
|
trust_remote_code=True,
|
|
|
|
gpu_memory_utilization=memory_utilization,
|
|
|
|
gpu_memory_utilization=memory_utilization,
|
|
|
|
download_dir="models/",
|
|
|
|
download_dir=model_dir
|
|
|
|
)
|
|
|
|
)
|
|
|
|
# Add the downloaded model to the available_models list
|
|
|
|
# Add the downloaded model to the available_models list
|
|
|
|
available_models.append((model_name, vllm_model))
|
|
|
|
available_models.append((model_name, vllm_model))
|
|
|
|
# Update the dropdown choices with the new available_models list
|
|
|
|
# Update the dropdown choices with the new available_models list
|
|
|
|
model_chosen.update(choices=available_models)
|
|
|
|
model_chosen.update(choices=available_models)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_tools():
|
|
|
|
def load_tools():
|
|
|
|
global valid_tools_info
|
|
|
|
global valid_tools_info
|
|
|
|
global all_tools_list
|
|
|
|
global all_tools_list
|
|
|
@ -159,24 +152,23 @@ def load_tools():
|
|
|
|
all_tools_list = sorted(list(valid_tools_info.keys()))
|
|
|
|
all_tools_list = sorted(list(valid_tools_info.keys()))
|
|
|
|
return gr.update(choices=all_tools_list)
|
|
|
|
return gr.update(choices=all_tools_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_environ(OPENAI_API_KEY: str = "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",
|
|
|
|
|
|
|
|
WOLFRAMALPH_APP_ID: str = "",
|
|
|
|
|
|
|
|
WEATHER_API_KEYS: str = "",
|
|
|
|
|
|
|
|
BING_SUBSCRIPT_KEY: str = "",
|
|
|
|
|
|
|
|
ALPHA_VANTAGE_KEY: str = "",
|
|
|
|
|
|
|
|
BING_MAP_KEY: str = "",
|
|
|
|
|
|
|
|
BAIDU_TRANSLATE_KEY: str = "",
|
|
|
|
|
|
|
|
RAPIDAPI_KEY: str = "",
|
|
|
|
|
|
|
|
SERPER_API_KEY: str = "",
|
|
|
|
|
|
|
|
GPLACES_API_KEY: str = "",
|
|
|
|
|
|
|
|
SCENEX_API_KEY: str = "",
|
|
|
|
|
|
|
|
STEAMSHIP_API_KEY: str = "",
|
|
|
|
|
|
|
|
HUGGINGFACE_API_KEY: str = "",
|
|
|
|
|
|
|
|
AMADEUS_ID: str = "",
|
|
|
|
|
|
|
|
AMADEUS_KEY: str = "",
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
def set_environ(
|
|
|
|
|
|
|
|
OPENAI_API_KEY: str = "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",
|
|
|
|
|
|
|
|
WOLFRAMALPH_APP_ID: str = "",
|
|
|
|
|
|
|
|
WEATHER_API_KEYS: str = "",
|
|
|
|
|
|
|
|
BING_SUBSCRIPT_KEY: str = "",
|
|
|
|
|
|
|
|
ALPHA_VANTAGE_KEY: str = "",
|
|
|
|
|
|
|
|
BING_MAP_KEY: str = "",
|
|
|
|
|
|
|
|
BAIDU_TRANSLATE_KEY: str = "",
|
|
|
|
|
|
|
|
RAPIDAPI_KEY: str = "",
|
|
|
|
|
|
|
|
SERPER_API_KEY: str = "",
|
|
|
|
|
|
|
|
GPLACES_API_KEY: str = "",
|
|
|
|
|
|
|
|
SCENEX_API_KEY: str = "",
|
|
|
|
|
|
|
|
STEAMSHIP_API_KEY: str = "",
|
|
|
|
|
|
|
|
HUGGINGFACE_API_KEY: str = "",
|
|
|
|
|
|
|
|
AMADEUS_ID: str = "",
|
|
|
|
|
|
|
|
AMADEUS_KEY: str = "",
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
|
|
|
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
|
|
|
os.environ["WOLFRAMALPH_APP_ID"] = WOLFRAMALPH_APP_ID
|
|
|
|
os.environ["WOLFRAMALPH_APP_ID"] = WOLFRAMALPH_APP_ID
|
|
|
|
os.environ["WEATHER_API_KEYS"] = WEATHER_API_KEYS
|
|
|
|
os.environ["WEATHER_API_KEYS"] = WEATHER_API_KEYS
|
|
|
@ -197,53 +189,31 @@ def set_environ(
|
|
|
|
time.sleep(MAX_SLEEP_TIME)
|
|
|
|
time.sleep(MAX_SLEEP_TIME)
|
|
|
|
return gr.update(value="OK!")
|
|
|
|
return gr.update(value="OK!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_avatar_imgs(tools_chosen):
|
|
|
|
def show_avatar_imgs(tools_chosen):
|
|
|
|
if len(tools_chosen) == 0:
|
|
|
|
if len(tools_chosen) == 0:
|
|
|
|
tools_chosen = list(valid_tools_info.keys())
|
|
|
|
tools_chosen = list(valid_tools_info.keys())
|
|
|
|
img_template = '<a href="{}" style="float: left"> <img style="margin:5px" src="{}.png" width="24" height="24" alt="avatar" /> {} </a>'
|
|
|
|
img_template = '<a href="{}" style="float: left"> <img style="margin:5px" src="{}.png" width="24" height="24" alt="avatar" /> {} </a>'
|
|
|
|
imgs = [
|
|
|
|
imgs = [valid_tools_info[tool]['avatar'] for tool in tools_chosen if valid_tools_info[tool]['avatar'] != None]
|
|
|
|
valid_tools_info[tool]["avatar"]
|
|
|
|
imgs = ' '.join([img_template.format(img, img, tool) for img, tool in zip(imgs, tools_chosen)])
|
|
|
|
for tool in tools_chosen
|
|
|
|
return [gr.update(value='<span class="">' + imgs + '</span>', visible=True), gr.update(visible=True)]
|
|
|
|
if valid_tools_info[tool]["avatar"] != None
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
imgs = " ".join(
|
|
|
|
|
|
|
|
[img_template.format(img, img, tool) for img, tool in zip(imgs, tools_chosen)]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
gr.update(value='<span class="">' + imgs + "</span>", visible=True),
|
|
|
|
|
|
|
|
gr.update(visible=True),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def answer_by_tools(question, tools_chosen, model_chosen):
|
|
|
|
def answer_by_tools(question, tools_chosen, model_chosen):
|
|
|
|
global return_msg
|
|
|
|
global return_msg
|
|
|
|
return_msg += [(question, None), (None, "...")]
|
|
|
|
return_msg += [(question, None), (None, '...')]
|
|
|
|
yield [gr.update(visible=True, value=return_msg), gr.update(), gr.update()]
|
|
|
|
yield [gr.update(visible=True, value=return_msg), gr.update(), gr.update()]
|
|
|
|
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "")
|
|
|
|
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY', '')
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if len(tools_chosen) == 0: # if there is no tools chosen, we use all todo (TODO: What if the pool is too large.)
|
|
|
|
len(tools_chosen) == 0
|
|
|
|
|
|
|
|
): # if there is no tools chosen, we use all todo (TODO: What if the pool is too large.)
|
|
|
|
|
|
|
|
tools_chosen = list(valid_tools_info.keys())
|
|
|
|
tools_chosen = list(valid_tools_info.keys())
|
|
|
|
|
|
|
|
|
|
|
|
if len(tools_chosen) == 1:
|
|
|
|
if len(tools_chosen) == 1:
|
|
|
|
answerer = STQuestionAnswerer(
|
|
|
|
answerer = STQuestionAnswerer(OPENAI_API_KEY.strip(), stream_output=True, llm=model_chosen)
|
|
|
|
OPENAI_API_KEY.strip(), stream_output=True, llm=model_chosen
|
|
|
|
agent_executor = answerer.load_tools(tools_chosen[0], valid_tools_info[tools_chosen[0]],
|
|
|
|
)
|
|
|
|
prompt_type="react-with-tool-description", return_intermediate_steps=True)
|
|
|
|
agent_executor = answerer.load_tools(
|
|
|
|
|
|
|
|
tools_chosen[0],
|
|
|
|
|
|
|
|
valid_tools_info[tools_chosen[0]],
|
|
|
|
|
|
|
|
prompt_type="react-with-tool-description",
|
|
|
|
|
|
|
|
return_intermediate_steps=True,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
answerer = MTQuestionAnswerer(
|
|
|
|
answerer = MTQuestionAnswerer(OPENAI_API_KEY.strip(),
|
|
|
|
OPENAI_API_KEY.strip(),
|
|
|
|
load_valid_tools({k: tools_mappings[k] for k in tools_chosen}),
|
|
|
|
load_valid_tools({k: tools_mappings[k] for k in tools_chosen}),
|
|
|
|
stream_output=True, llm=model_chosen)
|
|
|
|
stream_output=True,
|
|
|
|
|
|
|
|
llm=model_chosen,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
agent_executor = answerer.build_runner()
|
|
|
|
agent_executor = answerer.build_runner()
|
|
|
|
|
|
|
|
|
|
|
@ -251,15 +221,12 @@ def answer_by_tools(question, tools_chosen, model_chosen):
|
|
|
|
chat_history += "Question: " + question + "\n"
|
|
|
|
chat_history += "Question: " + question + "\n"
|
|
|
|
question = chat_history
|
|
|
|
question = chat_history
|
|
|
|
for inter in agent_executor(question):
|
|
|
|
for inter in agent_executor(question):
|
|
|
|
if isinstance(inter, AgentFinish):
|
|
|
|
if isinstance(inter, AgentFinish): continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
result_str = []
|
|
|
|
result_str = []
|
|
|
|
return_msg.pop()
|
|
|
|
return_msg.pop()
|
|
|
|
if isinstance(inter, dict):
|
|
|
|
if isinstance(inter, dict):
|
|
|
|
result_str.append(
|
|
|
|
result_str.append("<font color=red>Answer:</font> {}".format(inter['output']))
|
|
|
|
"<font color=red>Answer:</font> {}".format(inter["output"])
|
|
|
|
chat_history += "Answer:" + inter['output'] + "\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
chat_history += "Answer:" + inter["output"] + "\n"
|
|
|
|
|
|
|
|
result_str.append("...")
|
|
|
|
result_str.append("...")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -267,40 +234,23 @@ def answer_by_tools(question, tools_chosen, model_chosen):
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
print(inter[0])
|
|
|
|
print(inter[0])
|
|
|
|
not_observation = inter[0]
|
|
|
|
not_observation = inter[0]
|
|
|
|
if not not_observation.startswith("Thought:"):
|
|
|
|
if not not_observation.startswith('Thought:'):
|
|
|
|
not_observation = "Thought: " + not_observation
|
|
|
|
not_observation = "Thought: " + not_observation
|
|
|
|
chat_history += not_observation
|
|
|
|
chat_history += not_observation
|
|
|
|
not_observation = not_observation.replace(
|
|
|
|
not_observation = not_observation.replace('Thought:', '<font color=green>Thought: </font>')
|
|
|
|
"Thought:", "<font color=green>Thought: </font>"
|
|
|
|
not_observation = not_observation.replace('Action:', '<font color=purple>Action: </font>')
|
|
|
|
)
|
|
|
|
not_observation = not_observation.replace('Action Input:', '<font color=purple>Action Input: </font>')
|
|
|
|
not_observation = not_observation.replace(
|
|
|
|
|
|
|
|
"Action:", "<font color=purple>Action: </font>"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
not_observation = not_observation.replace(
|
|
|
|
|
|
|
|
"Action Input:", "<font color=purple>Action Input: </font>"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
result_str.append("{}".format(not_observation))
|
|
|
|
result_str.append("{}".format(not_observation))
|
|
|
|
result_str.append(
|
|
|
|
result_str.append("<font color=blue>Action output:</font>\n{}".format(inter[1]))
|
|
|
|
"<font color=blue>Action output:</font>\n{}".format(inter[1])
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
chat_history += "\nAction output:" + inter[1] + "\n"
|
|
|
|
chat_history += "\nAction output:" + inter[1] + "\n"
|
|
|
|
result_str.append("...")
|
|
|
|
result_str.append("...")
|
|
|
|
return_msg += [(None, result) for result in result_str]
|
|
|
|
return_msg += [(None, result) for result in result_str]
|
|
|
|
yield [gr.update(visible=True, value=return_msg), gr.update(), gr.update()]
|
|
|
|
yield [gr.update(visible=True, value=return_msg), gr.update(), gr.update()]
|
|
|
|
return_msg.pop()
|
|
|
|
return_msg.pop()
|
|
|
|
if return_msg[-1][1].startswith("<font color=red>Answer:</font> "):
|
|
|
|
if return_msg[-1][1].startswith("<font color=red>Answer:</font> "):
|
|
|
|
return_msg[-1] = (
|
|
|
|
return_msg[-1] = (return_msg[-1][0], return_msg[-1][1].replace("<font color=red>Answer:</font> ",
|
|
|
|
return_msg[-1][0],
|
|
|
|
"<font color=green>Final Answer:</font> "))
|
|
|
|
return_msg[-1][1].replace(
|
|
|
|
yield [gr.update(visible=True, value=return_msg), gr.update(visible=True), gr.update(visible=False)]
|
|
|
|
"<font color=red>Answer:</font> ",
|
|
|
|
|
|
|
|
"<font color=green>Final Answer:</font> ",
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
yield [
|
|
|
|
|
|
|
|
gr.update(visible=True, value=return_msg),
|
|
|
|
|
|
|
|
gr.update(visible=True),
|
|
|
|
|
|
|
|
gr.update(visible=False),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def retrieve(tools_search):
|
|
|
|
def retrieve(tools_search):
|
|
|
@ -308,13 +258,14 @@ def retrieve(tools_search):
|
|
|
|
return gr.update(choices=all_tools_list)
|
|
|
|
return gr.update(choices=all_tools_list)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
url = "http://127.0.0.1:8079/retrieve"
|
|
|
|
url = "http://127.0.0.1:8079/retrieve"
|
|
|
|
param = {"query": tools_search}
|
|
|
|
param = {
|
|
|
|
|
|
|
|
"query": tools_search
|
|
|
|
|
|
|
|
}
|
|
|
|
response = requests.post(url, json=param)
|
|
|
|
response = requests.post(url, json=param)
|
|
|
|
result = response.json()
|
|
|
|
result = response.json()
|
|
|
|
retrieved_tools = result["tools"]
|
|
|
|
retrieved_tools = result["tools"]
|
|
|
|
return gr.update(choices=retrieved_tools)
|
|
|
|
return gr.update(choices=retrieved_tools)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clear_retrieve():
|
|
|
|
def clear_retrieve():
|
|
|
|
return [gr.update(value=""), gr.update(choices=all_tools_list)]
|
|
|
|
return [gr.update(value=""), gr.update(choices=all_tools_list)]
|
|
|
|
|
|
|
|
|
|
|
@ -326,14 +277,13 @@ def clear_history():
|
|
|
|
chat_history = ""
|
|
|
|
chat_history = ""
|
|
|
|
yield gr.update(visible=True, value=return_msg)
|
|
|
|
yield gr.update(visible=True, value=return_msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
title = 'Swarm Models'
|
|
|
|
title = "Swarm Models"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# css/js strings
|
|
|
|
# css/js strings
|
|
|
|
css = ui.css
|
|
|
|
css = ui.css
|
|
|
|
js = ui.js
|
|
|
|
js = ui.js
|
|
|
|
css += apply_extensions("css")
|
|
|
|
css += apply_extensions('css')
|
|
|
|
js += apply_extensions("js")
|
|
|
|
js += apply_extensions('js')
|
|
|
|
|
|
|
|
|
|
|
|
# with gr.Blocks(css=css, analytics_enabled=False, title=title, theme=ui.theme) as demo:
|
|
|
|
# with gr.Blocks(css=css, analytics_enabled=False, title=title, theme=ui.theme) as demo:
|
|
|
|
with gr.Blocks() as demo:
|
|
|
|
with gr.Blocks() as demo:
|
|
|
@ -341,93 +291,39 @@ with gr.Blocks() as demo:
|
|
|
|
with gr.Column(scale=14):
|
|
|
|
with gr.Column(scale=14):
|
|
|
|
gr.Markdown("")
|
|
|
|
gr.Markdown("")
|
|
|
|
with gr.Column(scale=1):
|
|
|
|
with gr.Column(scale=1):
|
|
|
|
gr.Image(
|
|
|
|
gr.Image(show_label=False, show_download_button=False, value="images/swarmslogobanner.png")
|
|
|
|
show_label=False,
|
|
|
|
|
|
|
|
show_download_button=False,
|
|
|
|
|
|
|
|
value="images/swarmslogobanner.png",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with gr.Tab("Key setting"):
|
|
|
|
with gr.Tab("Key setting"):
|
|
|
|
OPENAI_API_KEY = gr.Textbox(
|
|
|
|
OPENAI_API_KEY = gr.Textbox(label="OpenAI API KEY:", placeholder="sk-...", type="text")
|
|
|
|
label="OpenAI API KEY:", placeholder="sk-...", type="text"
|
|
|
|
WOLFRAMALPH_APP_ID = gr.Textbox(label="Wolframalpha app id:", placeholder="Key to use wlframalpha", type="text")
|
|
|
|
)
|
|
|
|
WEATHER_API_KEYS = gr.Textbox(label="Weather api key:", placeholder="Key to use weather api", type="text")
|
|
|
|
WOLFRAMALPH_APP_ID = gr.Textbox(
|
|
|
|
BING_SUBSCRIPT_KEY = gr.Textbox(label="Bing subscript key:", placeholder="Key to use bing search", type="text")
|
|
|
|
label="Wolframalpha app id:",
|
|
|
|
ALPHA_VANTAGE_KEY = gr.Textbox(label="Stock api key:", placeholder="Key to use stock api", type="text")
|
|
|
|
placeholder="Key to use wlframalpha",
|
|
|
|
BING_MAP_KEY = gr.Textbox(label="Bing map key:", placeholder="Key to use bing map", type="text")
|
|
|
|
type="text",
|
|
|
|
BAIDU_TRANSLATE_KEY = gr.Textbox(label="Baidu translation key:", placeholder="Key to use baidu translation", type="text")
|
|
|
|
)
|
|
|
|
RAPIDAPI_KEY = gr.Textbox(label="Rapidapi key:", placeholder="Key to use zillow, airbnb and job search", type="text")
|
|
|
|
WEATHER_API_KEYS = gr.Textbox(
|
|
|
|
SERPER_API_KEY = gr.Textbox(label="Serper key:", placeholder="Key to use google serper and google scholar", type="text")
|
|
|
|
label="Weather api key:", placeholder="Key to use weather api", type="text"
|
|
|
|
GPLACES_API_KEY = gr.Textbox(label="Google places key:", placeholder="Key to use google places", type="text")
|
|
|
|
)
|
|
|
|
SCENEX_API_KEY = gr.Textbox(label="Scenex api key:", placeholder="Key to use sceneXplain", type="text")
|
|
|
|
BING_SUBSCRIPT_KEY = gr.Textbox(
|
|
|
|
STEAMSHIP_API_KEY = gr.Textbox(label="Steamship api key:", placeholder="Key to use image generation", type="text")
|
|
|
|
label="Bing subscript key:",
|
|
|
|
HUGGINGFACE_API_KEY = gr.Textbox(label="Huggingface api key:", placeholder="Key to use models in huggingface hub", type="text")
|
|
|
|
placeholder="Key to use bing search",
|
|
|
|
AMADEUS_ID = gr.Textbox(label="Amadeus id:", placeholder="Id to use Amadeus", type="text")
|
|
|
|
type="text",
|
|
|
|
AMADEUS_KEY = gr.Textbox(label="Amadeus key:", placeholder="Key to use Amadeus", type="text")
|
|
|
|
)
|
|
|
|
|
|
|
|
ALPHA_VANTAGE_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Stock api key:", placeholder="Key to use stock api", type="text"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
BING_MAP_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Bing map key:", placeholder="Key to use bing map", type="text"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
BAIDU_TRANSLATE_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Baidu translation key:",
|
|
|
|
|
|
|
|
placeholder="Key to use baidu translation",
|
|
|
|
|
|
|
|
type="text",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
RAPIDAPI_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Rapidapi key:",
|
|
|
|
|
|
|
|
placeholder="Key to use zillow, airbnb and job search",
|
|
|
|
|
|
|
|
type="text",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
SERPER_API_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Serper key:",
|
|
|
|
|
|
|
|
placeholder="Key to use google serper and google scholar",
|
|
|
|
|
|
|
|
type="text",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
GPLACES_API_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Google places key:",
|
|
|
|
|
|
|
|
placeholder="Key to use google places",
|
|
|
|
|
|
|
|
type="text",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
SCENEX_API_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Scenex api key:", placeholder="Key to use sceneXplain", type="text"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
STEAMSHIP_API_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Steamship api key:",
|
|
|
|
|
|
|
|
placeholder="Key to use image generation",
|
|
|
|
|
|
|
|
type="text",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
HUGGINGFACE_API_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Huggingface api key:",
|
|
|
|
|
|
|
|
placeholder="Key to use models in huggingface hub",
|
|
|
|
|
|
|
|
type="text",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
AMADEUS_ID = gr.Textbox(
|
|
|
|
|
|
|
|
label="Amadeus id:", placeholder="Id to use Amadeus", type="text"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
AMADEUS_KEY = gr.Textbox(
|
|
|
|
|
|
|
|
label="Amadeus key:", placeholder="Key to use Amadeus", type="text"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
key_set_btn = gr.Button(value="Set keys!")
|
|
|
|
key_set_btn = gr.Button(value="Set keys!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with gr.Tab("Chat with Tool"):
|
|
|
|
with gr.Tab("Chat with Tool"):
|
|
|
|
with gr.Row():
|
|
|
|
with gr.Row():
|
|
|
|
with gr.Column(scale=4):
|
|
|
|
with gr.Column(scale=4):
|
|
|
|
with gr.Row():
|
|
|
|
with gr.Row():
|
|
|
|
with gr.Column(scale=0.85):
|
|
|
|
with gr.Column(scale=0.85):
|
|
|
|
txt = gr.Textbox(
|
|
|
|
txt = gr.Textbox(show_label=False, placeholder="Question here. Use Shift+Enter to add new line.",
|
|
|
|
show_label=False,
|
|
|
|
lines=1).style(container=False)
|
|
|
|
placeholder="Question here. Use Shift+Enter to add new line.",
|
|
|
|
|
|
|
|
lines=1,
|
|
|
|
|
|
|
|
).style(container=False)
|
|
|
|
|
|
|
|
with gr.Column(scale=0.15, min_width=0):
|
|
|
|
with gr.Column(scale=0.15, min_width=0):
|
|
|
|
buttonChat = gr.Button("Chat")
|
|
|
|
buttonChat = gr.Button("Chat")
|
|
|
|
|
|
|
|
|
|
|
|
memory_utilization = gr.Slider(
|
|
|
|
memory_utilization = gr.Slider(label="Memory Utilization:", min=0, max=1, step=0.1, default=0.5)
|
|
|
|
label="Memory Utilization:", min=0, max=1, step=0.1, default=0.5
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chatbot = gr.Chatbot(show_label=False, visible=True).style(height=600)
|
|
|
|
chatbot = gr.Chatbot(show_label=False, visible=True).style(height=600)
|
|
|
|
buttonClear = gr.Button("Clear History")
|
|
|
|
buttonClear = gr.Button("Clear History")
|
|
|
|
buttonStop = gr.Button("Stop", visible=False)
|
|
|
|
buttonStop = gr.Button("Stop", visible=False)
|
|
|
@ -435,22 +331,13 @@ with gr.Blocks() as demo:
|
|
|
|
with gr.Column(scale=4):
|
|
|
|
with gr.Column(scale=4):
|
|
|
|
with gr.Row():
|
|
|
|
with gr.Row():
|
|
|
|
with gr.Column(scale=1):
|
|
|
|
with gr.Column(scale=1):
|
|
|
|
model_url = gr.Textbox(
|
|
|
|
model_url = gr.Textbox(label="VLLM Model URL:", placeholder="URL to download VLLM model from Hugging Face", type="text");
|
|
|
|
label="VLLM Model URL:",
|
|
|
|
buttonDownload = gr.Button("Download Model");
|
|
|
|
placeholder="URL to download VLLM model from Hugging Face",
|
|
|
|
buttonDownload.click(fn=download_model, inputs=[model_url, memory_utilization]);
|
|
|
|
type="text",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
buttonDownload = gr.Button("Download Model")
|
|
|
|
|
|
|
|
buttonDownload.click(
|
|
|
|
|
|
|
|
fn=download_model, inputs=[model_url, memory_utilization]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
model_chosen = gr.Dropdown(
|
|
|
|
model_chosen = gr.Dropdown(
|
|
|
|
list(available_models),
|
|
|
|
list(available_models), value=DEFAULTMODEL, multiselect=False, label="Model provided",
|
|
|
|
value=DEFAULTMODEL,
|
|
|
|
info="Choose the model to solve your question, Default means ChatGPT."
|
|
|
|
multiselect=False,
|
|
|
|
)
|
|
|
|
label="Model provided",
|
|
|
|
|
|
|
|
info="Choose the model to solve your question, Default means ChatGPT.",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
with gr.Row():
|
|
|
|
with gr.Row():
|
|
|
|
tools_search = gr.Textbox(
|
|
|
|
tools_search = gr.Textbox(
|
|
|
|
lines=1,
|
|
|
|
lines=1,
|
|
|
@ -465,58 +352,38 @@ with gr.Blocks() as demo:
|
|
|
|
info="Choose the tools to solve your question.",
|
|
|
|
info="Choose the tools to solve your question.",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
key_set_btn.click(
|
|
|
|
key_set_btn.click(fn=set_environ, inputs=[
|
|
|
|
fn=set_environ,
|
|
|
|
OPENAI_API_KEY,
|
|
|
|
inputs=[
|
|
|
|
WOLFRAMALPH_APP_ID,
|
|
|
|
OPENAI_API_KEY,
|
|
|
|
WEATHER_API_KEYS,
|
|
|
|
WOLFRAMALPH_APP_ID,
|
|
|
|
BING_SUBSCRIPT_KEY,
|
|
|
|
WEATHER_API_KEYS,
|
|
|
|
ALPHA_VANTAGE_KEY,
|
|
|
|
BING_SUBSCRIPT_KEY,
|
|
|
|
BING_MAP_KEY,
|
|
|
|
ALPHA_VANTAGE_KEY,
|
|
|
|
BAIDU_TRANSLATE_KEY,
|
|
|
|
BING_MAP_KEY,
|
|
|
|
RAPIDAPI_KEY,
|
|
|
|
BAIDU_TRANSLATE_KEY,
|
|
|
|
SERPER_API_KEY,
|
|
|
|
RAPIDAPI_KEY,
|
|
|
|
GPLACES_API_KEY,
|
|
|
|
SERPER_API_KEY,
|
|
|
|
SCENEX_API_KEY,
|
|
|
|
GPLACES_API_KEY,
|
|
|
|
STEAMSHIP_API_KEY,
|
|
|
|
SCENEX_API_KEY,
|
|
|
|
HUGGINGFACE_API_KEY,
|
|
|
|
STEAMSHIP_API_KEY,
|
|
|
|
AMADEUS_ID,
|
|
|
|
HUGGINGFACE_API_KEY,
|
|
|
|
AMADEUS_KEY,
|
|
|
|
AMADEUS_ID,
|
|
|
|
], outputs=key_set_btn)
|
|
|
|
AMADEUS_KEY,
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
outputs=key_set_btn,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
key_set_btn.click(fn=load_tools, outputs=tools_chosen)
|
|
|
|
key_set_btn.click(fn=load_tools, outputs=tools_chosen)
|
|
|
|
|
|
|
|
|
|
|
|
tools_search.change(retrieve, tools_search, tools_chosen)
|
|
|
|
tools_search.change(retrieve, tools_search, tools_chosen)
|
|
|
|
buttonSearch.click(clear_retrieve, [], [tools_search, tools_chosen])
|
|
|
|
buttonSearch.click(clear_retrieve, [], [tools_search, tools_chosen])
|
|
|
|
|
|
|
|
|
|
|
|
txt.submit(
|
|
|
|
txt.submit(lambda: [gr.update(value=''), gr.update(visible=False), gr.update(visible=True)], [],
|
|
|
|
lambda: [
|
|
|
|
[txt, buttonClear, buttonStop])
|
|
|
|
gr.update(value=""),
|
|
|
|
inference_event = txt.submit(answer_by_tools, [txt, tools_chosen, model_chosen], [chatbot, buttonClear, buttonStop])
|
|
|
|
gr.update(visible=False),
|
|
|
|
buttonChat.click(answer_by_tools, [txt, tools_chosen, model_chosen], [chatbot, buttonClear, buttonStop])
|
|
|
|
gr.update(visible=True),
|
|
|
|
buttonStop.click(lambda: [gr.update(visible=True), gr.update(visible=False)], [], [buttonClear, buttonStop],
|
|
|
|
],
|
|
|
|
cancels=[inference_event])
|
|
|
|
[],
|
|
|
|
|
|
|
|
[txt, buttonClear, buttonStop],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
inference_event = txt.submit(
|
|
|
|
|
|
|
|
answer_by_tools,
|
|
|
|
|
|
|
|
[txt, tools_chosen, model_chosen],
|
|
|
|
|
|
|
|
[chatbot, buttonClear, buttonStop],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
buttonChat.click(
|
|
|
|
|
|
|
|
answer_by_tools,
|
|
|
|
|
|
|
|
[txt, tools_chosen, model_chosen],
|
|
|
|
|
|
|
|
[chatbot, buttonClear, buttonStop],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
buttonStop.click(
|
|
|
|
|
|
|
|
lambda: [gr.update(visible=True), gr.update(visible=False)],
|
|
|
|
|
|
|
|
[],
|
|
|
|
|
|
|
|
[buttonClear, buttonStop],
|
|
|
|
|
|
|
|
cancels=[inference_event],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
buttonClear.click(clear_history, [], chatbot)
|
|
|
|
buttonClear.click(clear_history, [], chatbot)
|
|
|
|
|
|
|
|
|
|
|
|
# demo.queue().launch(share=False, inbrowser=True, server_name="127.0.0.1", server_port=7001)
|
|
|
|
# demo.queue().launch(share=False, inbrowser=True, server_name="127.0.0.1", server_port=7001)
|
|
|
|
demo.queue().launch()
|
|
|
|
demo.queue().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|