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