Spaces:
Runtime error
Runtime error
dst1213 commited on
Commit ·
b2ed5dc
1
Parent(s): 5c666cb
pipeline v2,找医生模型,修改template,temperature,chunk_size等参数
Browse filesFiles changed (7)
41 unmodified lines42434445464748120 unmodified lines169170171172173174175291 unmodified lines46746846947047147247347447547647747847948048148248348441 unmodified lineswith gr.Row().style(equal_height=True):with gr.Column(scale=5):with gr.Row():chatbot = gr.Chatbot(label="Chuanhu Chat", elem_id="chuanhu_chatbot").style(height="100%")with gr.Row():with gr.Column(min_width=225, scale=12):user_input = gr.Textbox(120 unmodified linestemperature_slider = gr.Slider(minimum=-0,maximum=2.0,value=1.0,step=0.1,interactive=True,label="temperature",291 unmodified linesif __name__ == "__main__":reload_javascript()# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(# server_name=server_name,# server_port=server_port,# share=share,# auth=auth_list if authflag else None,# favicon_path="./assets/favicon.ico",# inbrowser=not dockerflag, # 禁止在docker下开启inbrowser# )reload_javascript()demo.queue(concurrency_count=CONCURRENT_COUNT).launch(favicon_path="./assets/favicon.ico",)# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860,auth=("在这里填写用户名", "在这里填写密码")) # 可设置用户名与密码# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(auth=("在这里填写用户名", "在这里填写密码")) # 适合Nginx反向代理41 unmodified lines42434445464748120 unmodified lines169170171172173174175291 unmodified lines46746846947047147247347447547647747847948048148248341 unmodified lineswith gr.Row().style(equal_height=True):with gr.Column(scale=5):with gr.Row():chatbot = gr.Chatbot(label="CooGen", elem_id="chuanhu_chatbot").style(height="100%") # TODO dst1213,Chuanhu Chat改CooGenwith gr.Row():with gr.Column(min_width=225, scale=12):user_input = gr.Textbox(120 unmodified linestemperature_slider = gr.Slider(minimum=-0,maximum=2.0,value=0.5, # TODO dst1213 1.0改0.5step=0.1,interactive=True,label="temperature",291 unmodified linesif __name__ == "__main__":reload_javascript()# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(# server_name=server_name, # TODO dst1213改成'0.0.0.0'可以局域网用# server_port=server_port,# share=share,# auth=auth_list if authflag else None,# favicon_path="./assets/favicon.ico",# inbrowser=not dockerflag, # 禁止在docker下开启inbrowser# )reload_javascript()demo.queue(concurrency_count=CONCURRENT_COUNT).launch(favicon_path="./assets/favicon.ico",)# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860,auth=("在这里填写用户名", "在这里填写密码")) # 可设置用户名与密码# demo.queue(concurrency_count=CONCURRENT_COUNT).launch(auth=("在这里填写用户名", "在这里填写密码")) # 适合Nginx反向代理
7 unmodified lines8910117 unmodified lines- README.md要按照huggingface的要求写- template要从gitignore去掉- share=False,huggingface spaces不支持- 参考这个https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT/blob/main/ChuanhuChatbot.py7 unmodified lines891011121314151617187 unmodified lines- README.md要按照huggingface的要求写- template要从gitignore去掉- share=False,huggingface spaces不支持- 参考这个https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT/blob/main/ChuanhuChatbot.py- 改成这样:```pythonreload_javascript()demo.queue(concurrency_count=CONCURRENT_COUNT).launch(favicon_path="./assets/favicon.ico",)```
12345678910111213---title: CooGen Chatemoji: 🐯colorFrom: greencolorTo: redsdk: gradiosdk_version: 3.28.0app_file: ChuanhuChatbot.pypinned: falselicense: gpl-3.0---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130<div align="right"><!-- 语言: -->简体中文 | <a title="English" href="./readme/README_en.md">English</a> | <a title="Japanese" href="./readme/README_ja.md">日本語</a></div><h1 align="center">川虎 Chat 🐯 Chuanhu Chat</h1><div align="center"><a href="https://github.com/GaiZhenBiao/ChuanhuChatGPT"><img src="https://user-images.githubusercontent.com/70903329/227087087-93b37d64-7dc3-4738-a518-c1cf05591c8a.png" alt="Logo" height="156"></a><p align="center"><h3>为ChatGPT/ChatGLM/LLaMA/StableLM/MOSS等多种LLM提供了一个轻快好用的Web图形界面</h3><p align="center"><a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/blob/main/LICENSE"><img alt="Tests Passing" src="https://img.shields.io/github/license/GaiZhenbiao/ChuanhuChatGPT" /></a><a href="https://gradio.app/"><img alt="GitHub Contributors" src="https://img.shields.io/badge/Base-Gradio-fb7d1a?style=flat" /></a><a href="https://t.me/tkdifferent"><img alt="GitHub pull requests" src="https://img.shields.io/badge/Telegram-Group-blue.svg?logo=telegram" /></a><p>流式传输 / 无限对话 / 保存对话 / 预设Prompt集 / 联网搜索 / 根据文件回答 <br />渲染LaTeX / 渲染表格 / 代码高亮 / 自动亮暗色切换 / 自适应界面 / “小而美”的体验 <br />自定义api-Host / 多参数可调 / 多API Key均衡负载 / 多用户显示 / 适配GPT-4 / 支持本地部署LLM</p><a href="https://www.bilibili.com/video/BV1mo4y1r7eE"><strong>视频教程</strong></a>·<a href="https://www.bilibili.com/video/BV1184y1w7aP"><strong>2.0介绍视频</strong></a>||<a href="https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT"><strong>在线体验</strong></a>·<a href="https://huggingface.co/login?next=%2Fspaces%2FJohnSmith9982%2FChuanhuChatGPT%3Fduplicate%3Dtrue"><strong>一键部署</strong></a></p><p align="center"><img alt="Animation Demo" src="https://user-images.githubusercontent.com/51039745/226255695-6b17ff1f-ea8d-464f-b69b-a7b6b68fffe8.gif" /></p></p></div>## 目录| [使用技巧](#使用技巧) | [安装方式](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程) | [常见问题](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/常见问题) | [给作者买可乐🥤](#捐款) || ------------------ | -------------------------------------------------------------------- | -------------------------------------------------------------------- | -------------------- |## 使用技巧- 使用System Prompt可以很有效地设定前提条件。- 使用Prompt模板功能时,选择Prompt模板集合文件,然后从下拉菜单中选择想要的prompt。- 如果回答不满意,可以使用 `重新生成`按钮再试一次- 输入框支持换行,按 `shift enter`即可。- 可以在输入框按上下箭头在输入历史之间切换- 部署到服务器:在 `config.json` 中设置 `"server_name": "0.0.0.0", "server_port": <你的端口号>,`。- 获取公共链接:在 `config.json` 中设置 `"share": true,`。注意程序必须在运行,才能通过公共链接访问。- 在Hugging Face上使用:建议在右上角 **复制Space** 再使用,这样App反应可能会快一点。## 快速上手```shellgit clone https://github.com/GaiZhenbiao/ChuanhuChatGPT.gitcd ChuanhuChatGPTpip install -r requirements.txt```在项目文件夹中复制一份 `config_example.json`,并将其重命名为 `config.json`,在其中填入 `API-Key` 等设置。```shellpython ChuanhuChatbot.py```一个浏览器窗口将会自动打开,此时您将可以使用 **川虎Chat** 与ChatGPT或其他模型进行对话。> **Note**>> 具体详尽的安装教程和使用教程请查看[本项目的wiki页面](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程)。## 疑难杂症解决在遇到各种问题查阅相关信息前,您可以先尝试手动拉取本项目的最新更改并更新 gradio,然后重试。步骤为:1. 点击网页上的 `Download ZIP` 下载最新代码,或```shellgit pull https://github.com/GaiZhenbiao/ChuanhuChatGPT.git main -f```2. 尝试再次安装依赖(可能本项目引入了新的依赖)```pip install -r requirements.txt```3. 更新gradio```pip install gradio --upgrade --force-reinstall```很多时候,这样就可以解决问题。如果问题仍然存在,请查阅该页面:[常见问题](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/常见问题)该页面列出了**几乎所有**您可能遇到的各种问题,包括如何配置代理,以及遇到问题后您该采取的措施,**请务必认真阅读**。## 了解更多若需了解更多信息,请查看我们的 [wiki](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki):- [想要做出贡献?](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/贡献指南)- [项目更新情况?](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/更新日志)- [二次开发许可?](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用许可)- [如何引用项目?](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用许可#如何引用该项目)## Starchart[](https://star-history.com/#GaiZhenbiao/ChuanhuChatGPT&Date)## Contributors<a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/graphs/contributors"><img src="https://contrib.rocks/image?repo=GaiZhenbiao/ChuanhuChatGPT" /></a>## 捐款🐯如果觉得这个软件对你有所帮助,欢迎请作者喝可乐、喝咖啡~联系作者:请去[我的bilibili账号](https://space.bilibili.com/29125536)私信我。<a href="https://www.buymeacoffee.com/ChuanhuChat" ><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=ChuanhuChat&button_colour=219d53&font_colour=ffffff&font_family=Poppins&outline_colour=ffffff&coffee_colour=FFDD00" alt="Buy Me A Coffee" width="250"></a><img width="250" alt="image" src="https://user-images.githubusercontent.com/51039745/226920291-e8ec0b0a-400f-4c20-ac13-dafac0c3aeeb.JPG">
69 unmodified lines70717273747576106 unmodified lines18318418518669 unmodified linesdockerflag = True## 处理 api-key 以及 允许的用户列表 TODO dst1213 keymy_api_key = config.get("openai_api_key", "")my_api_key = os.environ.get("OPENAI_API_KEY", my_api_key)xmchat_api_key = config.get("xmchat_api_key", "")106 unmodified linesexcept ValueError:passshare = config.get("share", False) # TODO dst1213 False 公网72H,spaces等环境必须关掉!!!69 unmodified lines70717273747576106 unmodified lines18318418518669 unmodified linesdockerflag = True## 处理 api-key 以及 允许的用户列表 TODO dst1213 keymy_api_key = config.get("openai_api_key","")#, "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")my_api_key = os.environ.get("OPENAI_API_KEY", my_api_key)xmchat_api_key = config.get("xmchat_api_key", "")106 unmodified linesexcept ValueError:passshare = config.get("share", True) # TODO dst1213 False 公网72H
219 unmodified lines22022122222322422522614 unmodified lines241242243244245246247248249250251252219 unmodified linesmax_input_size=4096,num_output=5,max_chunk_overlap=20,chunk_size_limit=600,)from llama_index import ServiceContext14 unmodified linesreference_results = add_source_numbers(reference_results, use_source=False)display_append = add_details(reference_results)display_append = "\n\n" + "".join(display_append)real_inputs = (replace_today(PROMPT_TEMPLATE).replace("{query_str}", real_inputs).replace("{context_str}", "\n\n".join(reference_results)).replace("{reply_language}", reply_language))elif use_websearch:limited_context = Truesearch_results = ddg(real_inputs, max_results=5)#, region="cn-zh") # 修改了地区从wt-wt改成了中国 TODO219 unmodified lines22022122222322422522614 unmodified lines241242243244245246247248249250251252253254255256219 unmodified linesmax_input_size=4096,num_output=5,max_chunk_overlap=20,chunk_size_limit=1000,# TODO dst1213,原来600,改1000)from llama_index import ServiceContext14 unmodified linesreference_results = add_source_numbers(reference_results, use_source=False)display_append = add_details(reference_results)display_append = "\n\n" + "".join(display_append)from .models import preprocess# output = preprocess()# logging.info(f"=======output:{output}")real_inputs = (replace_today(PROMPT_TEMPLATE).replace("{query_str}", real_inputs).replace("{context_str}", "\n\n".join(reference_results)).replace("{reply_language}", reply_language))logging.info(f"=======real_inputs:{real_inputs}")elif use_websearch:limited_context = Truesearch_results = ddg(real_inputs, max_results=5)#, region="cn-zh") # 修改了地区从wt-wt改成了中国 TODO
29 unmodified lines303132333435578 unmodified lines61461561661761861929 unmodified linesfrom .base_model import BaseLLMModel, ModelTypeclass OpenAIClient(BaseLLMModel):def __init__(self,578 unmodified lineselse:return model, msg, chatbot, gr.Dropdown.update(choices=lora_choices, visible=lora_selector_visibility)if __name__ == "__main__":with open("config.json", "r") as f:29 unmodified lines30313233343536578 unmodified lines61561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573629 unmodified linesfrom .base_model import BaseLLMModel, ModelTypeclass OpenAIClient(BaseLLMModel):def __init__(self,578 unmodified lineselse:return model, msg, chatbot, gr.Dropdown.update(choices=lora_choices, visible=lora_selector_visibility)def get_pre_question():prompt ="""context ------------{"openapi": "3.1.0","info": {"title": "clinical trials information searcher","description": "Searches for clinical trials based on various filter parameters such as trial status, lead organization, phase, eligibility criteria, and more","version": "v1"},"servers": [{"url": "https://clinicaltrials.gov"}],"paths": {"/api/query/full_studies": {"get": {"summary": "Enable users to query clinical trials information by title, doctor, hospital, facility, organization, location, phase, eligibility criteria, sponsor, investigator, and more","description": "Retrieves all content from the first study record returned for a submitted query by default. Returns up to 100 study records per query when the minimum rank and maximum rank parameters are set in a query URL and up to 10,000 records using the Full Studies interactive demonstration.","operationId": "full_studies","parameters": [{"in": "query","name": "expr","schema": {"type": "string","keyword_logic_relation": "+"},"description": "Determine the parameter based on the user's input keywords. Must translate non-English query to English,and then each keyword concatenated by `+`","required": true}, {"in": "query","name": "min_rnk","schema": {"type": "string"},"description": "Minimum Rank,determine the result list range lower boundary,default value is 1","required": true}, {"in": "query","name": "max_rnk","schema": {"type": "string"]},"description": "Maximum Rank,determine the result list range lower boundary,default value is 3","required": true}, {"in": "query","name": "fmt","schema": {"type": "string","enum": ["json","xml","tree"]]},"description": "Determine the result data format, like `json`,`xml`,`tree`, default value is `json`","required": true}],"responses": {{"brief_summary": "","brief_title": "","current_trial_status": "","lead_org": "","nct_id": "","number_of_arms": 2,"phase": "","primary_purpose": "","principal_investigator": "","study_protocol_type": ""}}}}}}——————————————————————分析以上context提到的接口和参数,帮我构造接口参数,,格式:“Request URL:xxx”,根据以下问题回答我。问题:心脏病的临床试验有哪些"""return promptdef preprocess():question = get_pre_question()# with open("config.json", "r") as f:# openai_api_key = cjson.load(f)["openai_api_key"]openai_api_key = "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"# set logging level to debuglogging.basicConfig(level=logging.DEBUG)# client = ModelManager(model_name="gpt-3.5-turbo", access_key=openai_api_key)# client = get_model(model_name="chatglm-6b-int4")client = OpenAIClient(model_name="gpt-3.5-turbo", api_key=openai_api_key)chatbot = []stream = False# 测试账单功能logging.info(colorama.Back.GREEN + "测试账单功能" + colorama.Back.RESET)# 测试问答logging.info(colorama.Back.GREEN + "测试问答" + colorama.Back.RESET)# question = "巴黎是中国的首都吗?"output = Nonefor i in client.predict(inputs=question, chatbot=chatbot, stream=stream):logging.info(i)logging.info(f"测试问答后history : {client.history}")answer = client.history[-1]ans = answer['content'].split("\n")for a in ans:if 'Request URL' in a:output = a[12:].strip()return outputif __name__ == "__main__":with open("config.json", "r") as f:
146 unmodified lines147148149150151152146 unmodified linesMake sure to cite results using [number] notation after the reference.If the provided context information refer to multiple subjects with the same name, write separate answers for each subject.Use prior knowledge only if the given context didn't provide enough information.Answer the question: {query_str}Reply in {reply_language}"""146 unmodified lines147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194146 unmodified linesMake sure to cite results using [number] notation after the reference.If the provided context information refer to multiple subjects with the same name, write separate answers for each subject.Use prior knowledge only if the given context didn't provide enough information.注意:1、Use prior knowledge re-answer me only if the given context didn't provide enough information.2、Don't give me information like “很抱歉,根据提供的context信息,并没有针对头疼的药物信息。”, if you don't know, answer like this “很抱歉,CooGen还在学习这些知识”。Answer the question: {query_str}Notice: If doctor or hospital not in the context, skip this oneReply in {reply_language}"""PROMPT_TEMPLATE_1 = """\Context information is below.---------------------{context_str}---------------------Current date: {current_date}.Using the provided context information, write a comprehensive reply to the given query.Make sure to cite results using [number] notation after the reference.If the provided context information refer to multiple subjects with the same name, write separate answers for each subject.Use prior knowledge only if the given context didn't provide enough information.注意:1、如果context里边没有相关信息,就丢弃context上下文,直接用你自己的知识重新回答我2、Use prior knowledge re-answer me only if the given context didn't provide enough information.3、Don't give me information like “很抱歉,根据提供的context信息,并没有针对头疼的药物信息。”, if you don't know, answer like this “很抱歉,CooGen还在学习这些知识”。4、如果用户找医生时我们找到的词条没有医生姓名或者姓名未知,就去掉这个词条,不要生成上下文里边没有的医生名字5、列出医生/专家清单时,要按姓名、医院、专长等顺序写6、列出医院/机构清单时,要按医院、地点、简介等顺序写Answer the question: {query_str}Reply in {reply_language}"""PROMPT_TEMPLATE_RAW = """\Context information is below.---------------------{context_str}---------------------Current date: {current_date}.Using the provided context information, write a comprehensive reply to the given query.Make sure to cite results using [number] notation after the reference.If the provided context information refer to multiple subjects with the same name, write separate answers for each subject.Use prior knowledge only if the given context didn't provide enough information.Answer the question: {query_str}Reply in {reply_language}"""
ChuanhuChatbot.py+8-9
CooGen_Readme.md+8-1
README.md+130-13
modules/config.py+2-2
modules/models/base_model.py+5-1
modules/models/models.py+117
modules/presets.py+42