Spaces:
No application file
No application file
""" | |
Global constants. | |
""" | |
from enum import IntEnum | |
import os | |
REPO_PATH = os.path.dirname(os.path.dirname(__file__)) | |
TASKS = ["summarization", "question-answering", "sentiment-analysis", "text-classification", "toxic-detection", "knowledge-opended", "knowledge-mtpchoice", "language-modelling", "information-retrieval", "reasoning", "math"] | |
# Survey Link URL (to be removed) | |
SURVEY_LINK = """<div style='text-align: center; margin: 20px 0;'> | |
<div style='display: inline-block; border: 2px solid #DE3163; padding: 10px; border-radius: 5px;'> | |
<span style='color: #DE3163; font-weight: bold;'>We would love your feedback! Fill out <a href='https://docs.google.com/forms/d/e/1FAIpQLSfKSxwFOW6qD05phh4fwYjk8q0YV1VQe_bmK0_qOVTbC66_MA/viewform?usp=sf_link' style='color: #DE3163; text-decoration: underline;'>this short survey</a> to tell us what you like about the arena, what you don't like, and what you want to see in the future.</span> | |
</div> | |
</div>""" | |
##### For the gradio web server | |
SERVER_ERROR_MSG = ( | |
"**NETWORK ERROR DUE TO HIGH TRAFFIC. PLEASE REGENERATE OR REFRESH THIS PAGE.**" | |
) | |
TEXT_MODERATION_MSG = ( | |
"$MODERATION$ YOUR TEXT VIOLATES OUR CONTENT MODERATION GUIDELINES." | |
) | |
IMAGE_MODERATION_MSG = ( | |
"$MODERATION$ YOUR IMAGE VIOLATES OUR CONTENT MODERATION GUIDELINES." | |
) | |
MODERATION_MSG = "$MODERATION$ YOUR INPUT VIOLATES OUR CONTENT MODERATION GUIDELINES." | |
CONVERSATION_LIMIT_MSG = "YOU HAVE REACHED THE CONVERSATION LENGTH LIMIT. PLEASE CLEAR HISTORY AND START A NEW CONVERSATION." | |
INACTIVE_MSG = "THIS SESSION HAS BEEN INACTIVE FOR TOO LONG. PLEASE REFRESH THIS PAGE." | |
SLOW_MODEL_MSG = "⚠️ Both models will show the responses all at once. Please stay patient as it may take over 30 seconds." | |
RATE_LIMIT_MSG = "**RATE LIMIT OF THIS MODEL IS REACHED. PLEASE COME BACK LATER OR USE <span style='color: red; font-weight: bold;'>[BATTLE MODE](https://chat.lmsys.org)</span> (the 1st tab).**" | |
# Maximum input length | |
INPUT_CHAR_LEN_LIMIT = int(os.getenv("FASTCHAT_INPUT_CHAR_LEN_LIMIT", 12000)) | |
BLIND_MODE_INPUT_CHAR_LEN_LIMIT = int( | |
os.getenv("FASTCHAT_BLIND_MODE_INPUT_CHAR_LEN_LIMIT", 30000) | |
) | |
# Maximum conversation turns | |
CONVERSATION_TURN_LIMIT = 50 | |
# Session expiration time | |
SESSION_EXPIRATION_TIME = 3600 | |
# The output dir of log files | |
LOGDIR = os.getenv("LOGDIR", ".") | |
# CPU Instruction Set Architecture | |
CPU_ISA = os.getenv("CPU_ISA") | |
##### For the controller and workers (could be overwritten through ENV variables.) | |
CONTROLLER_HEART_BEAT_EXPIRATION = int( | |
os.getenv("FASTCHAT_CONTROLLER_HEART_BEAT_EXPIRATION", 90) | |
) | |
WORKER_HEART_BEAT_INTERVAL = int(os.getenv("FASTCHAT_WORKER_HEART_BEAT_INTERVAL", 45)) | |
WORKER_API_TIMEOUT = int(os.getenv("FASTCHAT_WORKER_API_TIMEOUT", 100)) | |
WORKER_API_EMBEDDING_BATCH_SIZE = int( | |
os.getenv("FASTCHAT_WORKER_API_EMBEDDING_BATCH_SIZE", 4) | |
) | |
class ErrorCode(IntEnum): | |
""" | |
https://platform.openai.com/docs/guides/error-codes/api-errors | |
""" | |
VALIDATION_TYPE_ERROR = 40001 | |
INVALID_AUTH_KEY = 40101 | |
INCORRECT_AUTH_KEY = 40102 | |
NO_PERMISSION = 40103 | |
INVALID_MODEL = 40301 | |
PARAM_OUT_OF_RANGE = 40302 | |
CONTEXT_OVERFLOW = 40303 | |
RATE_LIMIT = 42901 | |
QUOTA_EXCEEDED = 42902 | |
ENGINE_OVERLOADED = 42903 | |
INTERNAL_ERROR = 50001 | |
CUDA_OUT_OF_MEMORY = 50002 | |
GRADIO_REQUEST_ERROR = 50003 | |
GRADIO_STREAM_UNKNOWN_ERROR = 50004 | |
CONTROLLER_NO_WORKER = 50005 | |
CONTROLLER_WORKER_TIMEOUT = 50006 | |
LANGUAGES = list(map(lambda x: (x[1], x[0]), [ | |
('aa', 'Afar'), | |
('ab', 'Abkhazian'), | |
('af', 'Afrikaans'), | |
('ak', 'Akan'), | |
('sq', 'Albanian'), | |
('am', 'Amharic'), | |
('ar', 'Arabic'), | |
('an', 'Aragonese'), | |
('hy', 'Armenian'), | |
('as', 'Assamese'), | |
('av', 'Avaric'), | |
('ae', 'Avestan'), | |
('ay', 'Aymara'), | |
('az', 'Azerbaijani'), | |
('ba', 'Bashkir'), | |
('bm', 'Bambara'), | |
('eu', 'Basque'), | |
('be', 'Belarusian'), | |
('bn', 'Bengali'), | |
('bh', 'Bihari languages'), | |
('bi', 'Bislama'), | |
('bo', 'Tibetan'), | |
('bs', 'Bosnian'), | |
('br', 'Breton'), | |
('bg', 'Bulgarian'), | |
('my', 'Burmese'), | |
('ca', 'Catalan; Valencian'), | |
('cs', 'Czech'), | |
('ch', 'Chamorro'), | |
('ce', 'Chechen'), | |
('zh', 'Chinese'), | |
('cu', 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic'), | |
('cv', 'Chuvash'), | |
('kw', 'Cornish'), | |
('co', 'Corsican'), | |
('cr', 'Cree'), | |
('cy', 'Welsh'), | |
('cs', 'Czech'), | |
('da', 'Danish'), | |
('de', 'German'), | |
('dv', 'Divehi; Dhivehi; Maldivian'), | |
('nl', 'Dutch; Flemish'), | |
('dz', 'Dzongkha'), | |
('el', 'Greek, Modern (1453-)'), | |
('en', 'English'), | |
('eo', 'Esperanto'), | |
('et', 'Estonian'), | |
('eu', 'Basque'), | |
('ee', 'Ewe'), | |
('fo', 'Faroese'), | |
('fa', 'Persian'), | |
('fj', 'Fijian'), | |
('fi', 'Finnish'), | |
('fr', 'French'), | |
('fr', 'French'), | |
('fy', 'Western Frisian'), | |
('ff', 'Fulah'), | |
('Ga', 'Georgian'), | |
('de', 'German'), | |
('gd', 'Gaelic; Scottish Gaelic'), | |
('ga', 'Irish'), | |
('gl', 'Galician'), | |
('gv', 'Manx'), | |
('el', 'Greek, Modern (1453-)'), | |
('gn', 'Guarani'), | |
('gu', 'Gujarati'), | |
('ht', 'Haitian; Haitian Creole'), | |
('ha', 'Hausa'), | |
('he', 'Hebrew'), | |
('hz', 'Herero'), | |
('hi', 'Hindi'), | |
('ho', 'Hiri Motu'), | |
('hr', 'Croatian'), | |
('hu', 'Hungarian'), | |
('hy', 'Armenian'), | |
('ig', 'Igbo'), | |
('is', 'Icelandic'), | |
('io', 'Ido'), | |
('ii', 'Sichuan Yi; Nuosu'), | |
('iu', 'Inuktitut'), | |
('ie', 'Interlingue; Occidental'), | |
('ia', 'Interlingua (International Auxiliary Language Association)'), | |
('id', 'Indonesian'), | |
('ik', 'Inupiaq'), | |
('is', 'Icelandic'), | |
('it', 'Italian'), | |
('jv', 'Javanese'), | |
('ja', 'Japanese'), | |
('kl', 'Kalaallisut; Greenlandic'), | |
('kn', 'Kannada'), | |
('ks', 'Kashmiri'), | |
('ka', 'Georgian'), | |
('kr', 'Kanuri'), | |
('kk', 'Kazakh'), | |
('km', 'Central Khmer'), | |
('ki', 'Kikuyu; Gikuyu'), | |
('rw', 'Kinyarwanda'), | |
('ky', 'Kirghiz; Kyrgyz'), | |
('kv', 'Komi'), | |
('kg', 'Kongo'), | |
('ko', 'Korean'), | |
('kj', 'Kuanyama; Kwanyama'), | |
('ku', 'Kurdish'), | |
('lo', 'Lao'), | |
('la', 'Latin'), | |
('lv', 'Latvian'), | |
('li', 'Limburgan; Limburger; Limburgish'), | |
('ln', 'Lingala'), | |
('lt', 'Lithuanian'), | |
('lb', 'Luxembourgish; Letzeburgesch'), | |
('lu', 'Luba-Katanga'), | |
('lg', 'Ganda'), | |
('mk', 'Macedonian'), | |
('mh', 'Marshallese'), | |
('ml', 'Malayalam'), | |
('mi', 'Maori'), | |
('mr', 'Marathi'), | |
('ms', 'Malay'), | |
('Mi', 'Micmac'), | |
('mk', 'Macedonian'), | |
('mg', 'Malagasy'), | |
('mt', 'Maltese'), | |
('mn', 'Mongolian'), | |
('mi', 'Maori'), | |
('ms', 'Malay'), | |
('my', 'Burmese'), | |
('na', 'Nauru'), | |
('nv', 'Navajo; Navaho'), | |
('nr', 'Ndebele, South; South Ndebele'), | |
('nd', 'Ndebele, North; North Ndebele'), | |
('ng', 'Ndonga'), | |
('ne', 'Nepali'), | |
('nl', 'Dutch; Flemish'), | |
('nn', 'Norwegian Nynorsk; Nynorsk, Norwegian'), | |
('nb', 'Bokmål, Norwegian; Norwegian Bokmål'), | |
('no', 'Norwegian'), | |
('oc', 'Occitan (post 1500)'), | |
('oj', 'Ojibwa'), | |
('or', 'Oriya'), | |
('om', 'Oromo'), | |
('os', 'Ossetian; Ossetic'), | |
('pa', 'Panjabi; Punjabi'), | |
('fa', 'Persian'), | |
('pi', 'Pali'), | |
('pl', 'Polish'), | |
('pt', 'Portuguese'), | |
('ps', 'Pushto; Pashto'), | |
('qu', 'Quechua'), | |
('rm', 'Romansh'), | |
('ro', 'Romanian; Moldavian; Moldovan'), | |
('ro', 'Romanian; Moldavian; Moldovan'), | |
('rn', 'Rundi'), | |
('ru', 'Russian'), | |
('sg', 'Sango'), | |
('sa', 'Sanskrit'), | |
('si', 'Sinhala; Sinhalese'), | |
('sk', 'Slovak'), | |
('sk', 'Slovak'), | |
('sl', 'Slovenian'), | |
('se', 'Northern Sami'), | |
('sm', 'Samoan'), | |
('sn', 'Shona'), | |
('sd', 'Sindhi'), | |
('so', 'Somali'), | |
('st', 'Sotho, Southern'), | |
('es', 'Spanish; Castilian'), | |
('sq', 'Albanian'), | |
('sc', 'Sardinian'), | |
('sr', 'Serbian'), | |
('ss', 'Swati'), | |
('su', 'Sundanese'), | |
('sw', 'Swahili'), | |
('sv', 'Swedish'), | |
('ty', 'Tahitian'), | |
('ta', 'Tamil'), | |
('tt', 'Tatar'), | |
('te', 'Telugu'), | |
('tg', 'Tajik'), | |
('tl', 'Tagalog'), | |
('th', 'Thai'), | |
('bo', 'Tibetan'), | |
('ti', 'Tigrinya'), | |
('to', 'Tonga (Tonga Islands)'), | |
('tn', 'Tswana'), | |
('ts', 'Tsonga'), | |
('tk', 'Turkmen'), | |
('tr', 'Turkish'), | |
('tw', 'Twi'), | |
('ug', 'Uighur; Uyghur'), | |
('uk', 'Ukrainian'), | |
('ur', 'Urdu'), | |
('uz', 'Uzbek'), | |
('ve', 'Venda'), | |
('vi', 'Vietnamese'), | |
('vo', 'Volapük'), | |
('cy', 'Welsh'), | |
('wa', 'Walloon'), | |
('wo', 'Wolof'), | |
('xh', 'Xhosa'), | |
('yi', 'Yiddish'), | |
('yo', 'Yoruba'), | |
('za', 'Zhuang; Chuang'), | |
('zh', 'Chinese'), | |
('zu', 'Zulu') | |
])) | |