CoolFace
Apppublic

Intoval/privateChatGPT

sourceHugging Facegpl-3.0updated 3y agoView on Hugging Face
1likes
presets.py227 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("Intoval Private ChatGPT 🚀")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-7b-hf-int4",79    "llama-7b-hf-int8",80    "llama-13b-hf",81    "llama-13b-hf-int4",82    "llama-30b-hf",83    "llama-30b-hf-int4",84    "llama-65b-hf"85]86 87if os.environ.get('HIDE_LOCAL_MODELS', 'false') == 'true':88    MODELS = ONLINE_MODELS89else:90    MODELS = ONLINE_MODELS + LOCAL_MODELS91 92DEFAULT_MODEL = 193 94os.makedirs("models", exist_ok=True)95os.makedirs("lora", exist_ok=True)96os.makedirs("history", exist_ok=True)97for dir_name in os.listdir("models"):98    if os.path.isdir(os.path.join("models", dir_name)):99        if dir_name not in MODELS:100            MODELS.append(dir_name)101 102MODEL_TOKEN_LIMIT = {103    "gpt-3.5-turbo": 4096,104    "gpt-3.5-turbo-0301": 4096,105    "gpt-4": 8192,106    "gpt-4-0314": 8192,107    "gpt-4-32k": 32768,108    "gpt-4-32k-0314": 32768109}110 111TOKEN_OFFSET = 1000 # 模型的token上限减去这个值,得到软上限。到达软上限之后,自动尝试减少token占用。112DEFAULT_TOKEN_LIMIT = 3000 # 默认的token上限113REDUCE_TOKEN_FACTOR = 0.5 # 与模型token上限想乘,得到目标token数。减少token占用时,将token占用减少到目标token数以下。114 115REPLY_LANGUAGES = [116    "简体中文",117    "繁體中文",118    "English",119    "日本語",120    "Español",121    "Français",122    "Deutsch",123    "跟随问题语言(不稳定)"124]125 126 127WEBSEARCH_PTOMPT_TEMPLATE = """\128Web search results:129 130{web_results}131Current date: {current_date}132 133Instructions: 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.134Query: {query}135Reply in {reply_language}136"""137 138PROMPT_TEMPLATE = """\139Context information is below.140---------------------141{context_str}142---------------------143Current date: {current_date}.144Using the provided context information, write a comprehensive reply to the given query.145Make sure to cite results using [number] notation after the reference.146If the provided context information refer to multiple subjects with the same name, write separate answers for each subject.147Use prior knowledge only if the given context didn't provide enough information.148Answer the question: {query_str}149Reply in {reply_language}150"""151 152REFINE_TEMPLATE = """\153The original question is as follows: {query_str}154We have provided an existing answer: {existing_answer}155We have the opportunity to refine the existing answer156(only if needed) with some more context below.157------------158{context_msg}159------------160Given the new context, refine the original answer to better161Reply in {reply_language}162If the context isn't useful, return the original answer.163"""164 165ALREADY_CONVERTED_MARK = "<!-- ALREADY CONVERTED BY PARSER. -->"166 167small_and_beautiful_theme = gr.themes.Soft(168        primary_hue=gr.themes.Color(169            c50="#02C160",170            c100="rgba(2, 193, 96, 0.2)",171            c200="#02C160",172            c300="rgba(2, 193, 96, 0.32)",173            c400="rgba(2, 193, 96, 0.32)",174            c500="rgba(2, 193, 96, 1.0)",175            c600="rgba(2, 193, 96, 1.0)",176            c700="rgba(2, 193, 96, 0.32)",177            c800="rgba(2, 193, 96, 0.32)",178            c900="#02C160",179            c950="#02C160",180        ),181        secondary_hue=gr.themes.Color(182            c50="#576b95",183            c100="#576b95",184            c200="#576b95",185            c300="#576b95",186            c400="#576b95",187            c500="#576b95",188            c600="#576b95",189            c700="#576b95",190            c800="#576b95",191            c900="#576b95",192            c950="#576b95",193        ),194        neutral_hue=gr.themes.Color(195            name="gray",196            c50="#f9fafb",197            c100="#f3f4f6",198            c200="#e5e7eb",199            c300="#d1d5db",200            c400="#B2B2B2",201            c500="#808080",202            c600="#636363",203            c700="#515151",204            c800="#393939",205            c900="#272727",206            c950="#171717",207        ),208        radius_size=gr.themes.sizes.radius_sm,209    ).set(210        button_primary_background_fill="#06AE56",211        button_primary_background_fill_dark="#06AE56",212        button_primary_background_fill_hover="#07C863",213        button_primary_border_color="#06AE56",214        button_primary_border_color_dark="#06AE56",215        button_primary_text_color="#FFFFFF",216        button_primary_text_color_dark="#FFFFFF",217        button_secondary_background_fill="#F2F2F2",218        button_secondary_background_fill_dark="#2B2B2B",219        button_secondary_text_color="#393939",220        button_secondary_text_color_dark="#FFFFFF",221        # background_fill_primary="#F7F7F7",222        # background_fill_primary_dark="#1F1F1F",223        block_title_text_color="*primary_500",224        block_title_background_fill="*primary_100",225        input_background_fill="#F6F6F6",226    )227