CoolFace
Apppublic

Danielzero/GPT3.5

sourceHugging Facegpl-3.0updated 3y agoView on Hugging Face
1likes
presets.py223 linesDownload Raw Back to modules
1# -*- coding:utf-8 -*-2import os3from pathlib import Path4import gradio as gr5from .webui_locale import I18nAuto6 7i18n = I18nAuto()  # internationalization8 9CHATGLM_MODEL = None10CHATGLM_TOKENIZER = None11LLAMA_MODEL = None12LLAMA_INFERENCER = None13 14# ChatGPT 设置15INITIAL_SYSTEM_PROMPT = "You are a helpful assistant."16API_HOST = "api.openai.com"17COMPLETION_URL = "https://api.openai.com/v1/chat/completions"18BALANCE_API_URL="https://api.openai.com/dashboard/billing/credit_grants"19USAGE_API_URL="https://api.openai.com/dashboard/billing/usage"20HISTORY_DIR = Path("history")21HISTORY_DIR = "history"22TEMPLATES_DIR = "templates"23 24# 错误信息25STANDARD_ERROR_MSG = i18n("☹️发生了错误:")  # 错误信息的标准前缀26GENERAL_ERROR_MSG = i18n("获取对话时发生错误,请查看后台日志")27ERROR_RETRIEVE_MSG = i18n("请检查网络连接,或者API-Key是否有效。")28CONNECTION_TIMEOUT_MSG = i18n("连接超时,无法获取对话。")  # 连接超时29READ_TIMEOUT_MSG = i18n("读取超时,无法获取对话。")  # 读取超时30PROXY_ERROR_MSG = i18n("代理错误,无法获取对话。")  # 代理错误31SSL_ERROR_PROMPT = i18n("SSL错误,无法获取对话。")  # SSL 错误32NO_APIKEY_MSG = i18n("API key为空,请检查是否输入正确。")  # API key 长度不足 51 位33NO_INPUT_MSG = i18n("请输入对话内容。")  # 未输入对话内容34BILLING_NOT_APPLICABLE_MSG = i18n("账单信息不适用") # 本地运行的模型返回的账单信息35 36TIMEOUT_STREAMING = 60  # 流式对话时的超时时间37TIMEOUT_ALL = 200  # 非流式对话时的超时时间38ENABLE_STREAMING_OPTION = True  # 是否启用选择选择是否实时显示回答的勾选框39HIDE_MY_KEY = False  # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True40CONCURRENT_COUNT = 100 # 允许同时使用的用户数量41 42SIM_K = 543INDEX_QUERY_TEMPRATURE = 1.044 45CHUANHU_TITLE = i18n("川虎Chat 🚀")46 47CHUANHU_DESCRIPTION = i18n("由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发<br />访问川虎Chat的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本")48 49FOOTER = """<div class="versions">{versions}</div>"""50 51APPEARANCE_SWITCHER = """52<div style="display: flex; justify-content: space-between;">53<span style="margin-top: 4px !important;">"""+ i18n("切换亮暗色主题")  + """</span>54<span><label class="apSwitch" for="checkbox">55    <input type="checkbox" id="checkbox">56    <div class="apSlider"></div>57</label></span>58</div>59"""60 61SUMMARIZE_PROMPT = "你是谁?我们刚才聊了什么?"  # 总结对话时的 prompt62 63ONLINE_MODELS = [64    "gpt-3.5-turbo",65    "gpt-3.5-turbo-0301",66    "gpt-4",67    "gpt-4-0314",68    "gpt-4-32k",69    "gpt-4-32k-0314",70    "xmchat",71]72 73LOCAL_MODELS = [74    "chatglm-6b",75    "chatglm-6b-int4",76    "chatglm-6b-int4-qe",77    "llama-7b-hf",78    "llama-13b-hf",79    "llama-30b-hf",80    "llama-65b-hf"81]82 83if os.environ.get('HIDE_LOCAL_MODELS', 'false') == 'true':84    MODELS = ONLINE_MODELS85else:86    MODELS = ONLINE_MODELS + LOCAL_MODELS87 88DEFAULT_MODEL = 089 90os.makedirs("models", exist_ok=True)91os.makedirs("lora", exist_ok=True)92os.makedirs("history", exist_ok=True)93for dir_name in os.listdir("models"):94    if os.path.isdir(os.path.join("models", dir_name)):95        if dir_name not in MODELS:96            MODELS.append(dir_name)97 98MODEL_TOKEN_LIMIT = {99    "gpt-3.5-turbo": 4096,100    "gpt-3.5-turbo-0301": 4096,101    "gpt-4": 8192,102    "gpt-4-0314": 8192,103    "gpt-4-32k": 32768,104    "gpt-4-32k-0314": 32768105}106 107TOKEN_OFFSET = 1000 # 模型的token上限减去这个值,得到软上限。到达软上限之后,自动尝试减少token占用。108DEFAULT_TOKEN_LIMIT = 3000 # 默认的token上限109REDUCE_TOKEN_FACTOR = 0.5 # 与模型token上限想乘,得到目标token数。减少token占用时,将token占用减少到目标token数以下。110 111REPLY_LANGUAGES = [112    "简体中文",113    "繁體中文",114    "English",115    "日本語",116    "Español",117    "Français",118    "Deutsch",119    "跟随问题语言(不稳定)"120]121 122 123WEBSEARCH_PTOMPT_TEMPLATE = """\124Web search results:125 126{web_results}127Current date: {current_date}128 129Instructions: Using the provided web search results, write a comprehensive reply to the given query. Make sure to cite results using [[number](URL)] notation after the reference. If the provided search results refer to multiple subjects with the same name, write separate answers for each subject.130Query: {query}131Reply in {reply_language}132"""133 134PROMPT_TEMPLATE = """\135Context information is below.136---------------------137{context_str}138---------------------139Current date: {current_date}.140Using the provided context information, write a comprehensive reply to the given query.141Make sure to cite results using [number] notation after the reference.142If the provided context information refer to multiple subjects with the same name, write separate answers for each subject.143Use prior knowledge only if the given context didn't provide enough information.144Answer the question: {query_str}145Reply in {reply_language}146"""147 148REFINE_TEMPLATE = """\149The original question is as follows: {query_str}150We have provided an existing answer: {existing_answer}151We have the opportunity to refine the existing answer152(only if needed) with some more context below.153------------154{context_msg}155------------156Given the new context, refine the original answer to better157Reply in {reply_language}158If the context isn't useful, return the original answer.159"""160 161ALREADY_CONVERTED_MARK = "<!-- ALREADY CONVERTED BY PARSER. -->"162 163small_and_beautiful_theme = gr.themes.Soft(164        primary_hue=gr.themes.Color(165            c50="#02C160",166            c100="rgba(2, 193, 96, 0.2)",167            c200="#02C160",168            c300="rgba(2, 193, 96, 0.32)",169            c400="rgba(2, 193, 96, 0.32)",170            c500="rgba(2, 193, 96, 1.0)",171            c600="rgba(2, 193, 96, 1.0)",172            c700="rgba(2, 193, 96, 0.32)",173            c800="rgba(2, 193, 96, 0.32)",174            c900="#02C160",175            c950="#02C160",176        ),177        secondary_hue=gr.themes.Color(178            c50="#576b95",179            c100="#576b95",180            c200="#576b95",181            c300="#576b95",182            c400="#576b95",183            c500="#576b95",184            c600="#576b95",185            c700="#576b95",186            c800="#576b95",187            c900="#576b95",188            c950="#576b95",189        ),190        neutral_hue=gr.themes.Color(191            name="gray",192            c50="#f9fafb",193            c100="#f3f4f6",194            c200="#e5e7eb",195            c300="#d1d5db",196            c400="#B2B2B2",197            c500="#808080",198            c600="#636363",199            c700="#515151",200            c800="#393939",201            c900="#272727",202            c950="#171717",203        ),204        radius_size=gr.themes.sizes.radius_sm,205    ).set(206        button_primary_background_fill="#06AE56",207        button_primary_background_fill_dark="#06AE56",208        button_primary_background_fill_hover="#07C863",209        button_primary_border_color="#06AE56",210        button_primary_border_color_dark="#06AE56",211        button_primary_text_color="#FFFFFF",212        button_primary_text_color_dark="#FFFFFF",213        button_secondary_background_fill="#F2F2F2",214        button_secondary_background_fill_dark="#2B2B2B",215        button_secondary_text_color="#393939",216        button_secondary_text_color_dark="#FFFFFF",217        # background_fill_primary="#F7F7F7",218        # background_fill_primary_dark="#1F1F1F",219        block_title_text_color="*primary_500",220        block_title_background_fill="*primary_100",221        input_background_fill="#F6F6F6",222    )223