dual_window / app_utils.py
HuanzhiMao's picture
Fixing Dual Window Bug and Adding Single Model Demo (#1)
0157229 verified
import gradio as gr
from backend import get_handler
import uuid
CUSTOM_CSS = """
/* Highlight the entire message box for the bot */
.bot-highlight {
background-color: yellow !important;
padding: 0px;
border-radius: 8px;
}
"""
MAPPINGS = {"GorillaFileSystem": "gorilla_file_system",
"MathAPI": "math_api",
"MessageAPI": "message_api",
"TwitterAPI": "posting_api",
"TicketAPI": "ticket_api",
"TradingBot": "trading_bot",
"TravelAPI": "travel_booking",
"VehicleControlAPI": "vehicle_control"}
MODELS = ["gpt-4o-mini-2024-07-18-FC", "gpt-4o-2024-08-06-FC", "gpt-4o-mini-2024-07-18-FC",
"gpt-4-turbo-2024-04-09-FC", "gpt-3.5-turbo-0125-FC"]
CATEGORIES = ["GorillaFileSystem", "MathAPI", "MessageAPI", "TwitterAPI",
"TicketAPI", "TradingBot", "TravelAPI", "VehicleControlAPI"]
DEFAULT_MODEL_1 = MODELS[0]
DEFAULT_MODEL_2 = MODELS[1]
DEFAULT_TEMPERATURE_1 = 0.7
DEFAULT_TEMPERATURE_2 = 0.4
INITIAL_CHAT_HISTORY = [
{"role": "user", "content": "Hi, can you help me with some tasks?"},
{"role": "assistant", "content": "Hello there! How can I assist you today?"},
]
SINGLE_MODEL_BOT_EXAMPLE_SETTING = {
"Example 1 - GFSFileSystem": (MODELS[0], 0.8, CATEGORIES[0], "Move final_report.pdf' within document directory to 'temp' directory in document. Make sure to create the directory"),
"Example 2 - TradingBot": (MODELS[1], 0.9, CATEGORIES[5], "I'm contemplating enhancing my investment portfolio with some tech industry assets, and I've got my eye on Nvidia Corp. I'm keen to know its current stock price, and would appreciate if you could source this information for me."),
"Example 3 - TravelAPI": (MODELS[2], 0.7, CATEGORIES[6], "As I plan a getaway, I'm curious about all the airports available for my travel. Would you share that information with me?"),
}
DUAL_MODEL_BOT_1_EXAMPLE_SETTING = {
"Example 1 - GFSFileSystem": (MODELS[0], 0.8, CATEGORIES[0], "Move final_report.pdf' within document directory to 'temp' directory in document. Make sure to create the directory"),
"Example 2 - TradingBot": (MODELS[1], 0.9, CATEGORIES[5], "I'm contemplating enhancing my investment portfolio with some tech industry assets, and I've got my eye on Nvidia Corp. I'm keen to know its current stock price, and would appreciate if you could source this information for me."),
"Example 3 - TravelAPI": (MODELS[2], 0.7, CATEGORIES[6], "As I plan a getaway, I'm curious about all the airports available for my travel. Would you share that information with me?"),
}
DUAL_MODEL_BOT_2_EXAMPLE_SETTING = {
"Example 1 - GFSFileSystem": (MODELS[3], 0.5, CATEGORIES[0], "Move final_report.pdf' within document directory to 'temp' directory in document. Make sure to create the directory"),
"Example 2 - TradingBot": (MODELS[4], 0.6, CATEGORIES[5], "I'm contemplating enhancing my investment portfolio with some tech industry assets, and I've got my eye on Nvidia Corp. I'm keen to know its current stock price, and would appreciate if you could source this information for me."),
"Example 3 - TravelAPI": (MODELS[0], 0.4, CATEGORIES[6], "As I plan a getaway, I'm curious about all the airports available for my travel. Would you share that information with me?"),
}
def get_initial_state():
return list(INITIAL_CHAT_HISTORY)
def print_like_dislike(x: gr.LikeData):
print(x.index, x.value, x.liked)
def equalize_and_zip(list1, list2):
if list1 == None:
list1 = []
if list2 == None:
list2 = []
if isinstance(list1, str):
list1 = [list1]
if isinstance(list2, str):
list2 = [list2]
max_len = max(len(list1), len(list2))
list1.extend([None] * (max_len - len(list1)))
list2.extend([None] * (max_len - len(list2)))
return list(zip(list1, list2))
def consume_data(shared_queue):
none_list = []
while True:
data = shared_queue.get()
if data is None:
if data in none_list:
print("[Consumer] No more data to consume. Exiting.")
break
else:
none_list.append(data)
yield data
def initialize_empty_test_entry():
return {
"initial_config": {},
"involved_classes": [],
"id": str(uuid.uuid4()),
"question": [],
"function": []
}