cathub/LocalChatGPT
0
1# -*- coding:utf-8 -*-2import gradio as gr3 4# ChatGPT 设置5initial_prompt = "You are a helpful assistant."6API_URL = "https://api.openai.com/v1/chat/completions"7BALANCE_API_URL="https://api.openai.com/dashboard/billing/credit_grants"8USAGE_API_URL="https://api.openai.com/dashboard/billing/usage"9HISTORY_DIR = "history"10TEMPLATES_DIR = "templates"11 12# 错误信息13standard_error_msg = "☹️发生了错误:" # 错误信息的标准前缀14error_retrieve_prompt = "请检查网络连接,或者API-Key是否有效。" # 获取对话时发生错误15connection_timeout_prompt = "连接超时,无法获取对话。" # 连接超时16read_timeout_prompt = "读取超时,无法获取对话。" # 读取超时17proxy_error_prompt = "代理错误,无法获取对话。" # 代理错误18ssl_error_prompt = "SSL错误,无法获取对话。" # SSL 错误19no_apikey_msg = "API key长度不是51位,请检查是否输入正确。" # API key 长度不足 51 位20no_input_msg = "请输入对话内容。" # 未输入对话内容21 22timeout_streaming = 10 # 流式对话时的超时时间23timeout_all = 200 # 非流式对话时的超时时间24enable_streaming_option = True # 是否启用选择选择是否实时显示回答的勾选框25HIDE_MY_KEY = False # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True26CONCURRENT_COUNT = 100 # 允许同时使用的用户数量27 28SIM_K = 529INDEX_QUERY_TEMPRATURE = 1.030 31title = """<h1 align="left" style="min-width:200px; margin-top:0;">川虎ChatGPT 🚀</h1>"""32description = """\33<div align="center" style="margin:16px 0">34 35由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发36 37访问川虎ChatGPT的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本38 39此App使用 `gpt-3.5-turbo` 大语言模型40</div>41"""42 43footer = """\44<div class="versions">{versions}</div>45"""46 47summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt48 49MODELS = [50 "gpt-3.5-turbo",51 "gpt-3.5-turbo-0301",52 "gpt-4",53 "gpt-4-0314",54 "gpt-4-32k",55 "gpt-4-32k-0314",56] # 可选的模型57 58MODEL_SOFT_TOKEN_LIMIT = {59 "gpt-3.5-turbo": {60 "streaming": 3500,61 "all": 350062 },63 "gpt-3.5-turbo-0301": {64 "streaming": 3500,65 "all": 350066 },67 "gpt-4": {68 "streaming": 7500,69 "all": 750070 },71 "gpt-4-0314": {72 "streaming": 7500,73 "all": 750074 },75 "gpt-4-32k": {76 "streaming": 31000,77 "all": 3100078 },79 "gpt-4-32k-0314": {80 "streaming": 31000,81 "all": 3100082 }83}84 85REPLY_LANGUAGES = [86 "简体中文",87 "繁體中文",88 "English",89 "日本語",90 "Español",91 "Français",92 "Deutsch",93 "跟随问题语言(不稳定)"94]95 96 97WEBSEARCH_PTOMPT_TEMPLATE = """\98Web search results:99 100{web_results}101Current date: {current_date}102 103Instructions: 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.104Query: {query}105Reply in {reply_language}106"""107 108PROMPT_TEMPLATE = """\109Context information is below.110---------------------111{context_str}112---------------------113Current date: {current_date}.114Using the provided context information, write a comprehensive reply to the given query.115Make sure to cite results using [number] notation after the reference.116If the provided context information refer to multiple subjects with the same name, write separate answers for each subject.117Use prior knowledge only if the given context didn't provide enough information.118Answer the question: {query_str}119Reply in {reply_language}120"""121 122REFINE_TEMPLATE = """\123The original question is as follows: {query_str}124We have provided an existing answer: {existing_answer}125We have the opportunity to refine the existing answer126(only if needed) with some more context below.127------------128{context_msg}129------------130Given the new context, refine the original answer to better131Reply in {reply_language}132If the context isn't useful, return the original answer.133"""134 135ALREADY_CONVERTED_MARK = "<!-- ALREADY CONVERTED BY PARSER. -->"136 137small_and_beautiful_theme = gr.themes.Soft(138 primary_hue=gr.themes.Color(139 c50="#02C160",140 c100="rgba(2, 193, 96, 0.2)",141 c200="#02C160",142 c300="rgba(2, 193, 96, 0.32)",143 c400="rgba(2, 193, 96, 0.32)",144 c500="rgba(2, 193, 96, 1.0)",145 c600="rgba(2, 193, 96, 1.0)",146 c700="rgba(2, 193, 96, 0.32)",147 c800="rgba(2, 193, 96, 0.32)",148 c900="#02C160",149 c950="#02C160",150 ),151 secondary_hue=gr.themes.Color(152 c50="#576b95",153 c100="#576b95",154 c200="#576b95",155 c300="#576b95",156 c400="#576b95",157 c500="#576b95",158 c600="#576b95",159 c700="#576b95",160 c800="#576b95",161 c900="#576b95",162 c950="#576b95",163 ),164 neutral_hue=gr.themes.Color(165 name="gray",166 c50="#f9fafb",167 c100="#f3f4f6",168 c200="#e5e7eb",169 c300="#d1d5db",170 c400="#B2B2B2",171 c500="#808080",172 c600="#636363",173 c700="#515151",174 c800="#393939",175 c900="#272727",176 c950="#171717",177 ),178 radius_size=gr.themes.sizes.radius_sm,179 ).set(180 button_primary_background_fill="#06AE56",181 button_primary_background_fill_dark="#06AE56",182 button_primary_background_fill_hover="#07C863",183 button_primary_border_color="#06AE56",184 button_primary_border_color_dark="#06AE56",185 button_primary_text_color="#FFFFFF",186 button_primary_text_color_dark="#FFFFFF",187 button_secondary_background_fill="#F2F2F2",188 button_secondary_background_fill_dark="#2B2B2B",189 button_secondary_text_color="#393939",190 button_secondary_text_color_dark="#FFFFFF",191 # background_fill_primary="#F7F7F7",192 # background_fill_primary_dark="#1F1F1F",193 block_title_text_color="*primary_500",194 block_title_background_fill="*primary_100",195 input_background_fill="#F6F6F6",196 )197 