From 73a5c0d56a9be3babc6e428be8f57c5fa8722085 Mon Sep 17 00:00:00 2001 From: Luke <9198896+flexchar@users.noreply.github.com> Date: Tue, 6 Feb 2024 11:04:13 +0100 Subject: [PATCH] Several QoL contributions (#760) * allow customizing disclaimer as `PUBLIC_APP_DISCLAIMER_MESSAGE` * support passing `defaultHeaders` to `openai` endpoint * add azure openai, claude, mistral examples using `defaultHeaders` & `openai` endpoint * fix streaming being buffered behind cloudflare tunnel might help to relieve issue #598 * support new lines in model description * don't automatically generate modelUrl to huggingface fixes broken links for self-hosted or custom-named model * add `PUBLIC_APP_DISCLAIMER_MESSAGE` in `.env` * `npm run format` --------- Co-authored-by: Nathan Sarrazin --- .env | 1 + .env.template | 1 + README.md | 69 +++++++++++++++++++ src/lib/components/DisclaimerModal.svelte | 9 ++- .../server/endpoints/openai/endpointOai.ts | 5 +- src/routes/conversation/[id]/+server.ts | 6 +- src/routes/settings/[...model]/+page.svelte | 22 +++--- 7 files changed, 98 insertions(+), 15 deletions(-) diff --git a/.env b/.env index 90cb6169e05..a6761d7852e 100644 --- a/.env +++ b/.env @@ -120,6 +120,7 @@ PUBLIC_APP_COLOR=blue # can be any of tailwind colors: https://tailwindcss.com/d PUBLIC_APP_DESCRIPTION=# description used throughout the app (if not set, a default one will be used) PUBLIC_APP_DATA_SHARING=#set to 1 to enable options & text regarding data sharing PUBLIC_APP_DISCLAIMER=#set to 1 to show a disclaimer on login page +PUBLIC_APP_DISCLAIMER_MESSAGE="Disclaimer: AI is an area of active research with known problems such as biased generation and misinformation. Do not use this application for high-stakes decisions or advice." LLM_SUMMERIZATION=true EXPOSE_API=true diff --git a/.env.template b/.env.template index 7c5ce5b0c6d..deb22d5ba87 100644 --- a/.env.template +++ b/.env.template @@ -228,6 +228,7 @@ PUBLIC_APP_NAME=HuggingChat PUBLIC_APP_ASSETS=huggingchat PUBLIC_APP_COLOR=yellow PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone." +PUBLIC_APP_DISCLAIMER_MESSAGE="Disclaimer: AI is an area of active research with known problems such as biased generation and misinformation. Do not use this application for high-stakes decisions or advice." PUBLIC_APP_DATA_SHARING=1 PUBLIC_APP_DISCLAIMER=1 diff --git a/README.md b/README.md index 3695d9bfba8..64af99312ae 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,75 @@ MODELS=`[{ }]` ``` +You may also consume any model provider that provides compatible OpenAI API endpoint. For example, you may self-host [Portkey](https://github.com/Portkey-AI/gateway) gateway and experiment with Claude or GPTs offered by Azure OpenAI. Example for Claude from Anthropic: + +``` +MODELS=`[{ + "name": "claude-2.1", + "displayName": "Claude 2.1", + "description": "Anthropic has been founded by former OpenAI researchers...", + "parameters": { + "temperature": 0.5, + "max_new_tokens": 4096, + }, + "endpoints": [ + { + "type": "openai", + "baseURL": "https://gateway.example.com/v1", + "defaultHeaders": { + "x-portkey-config": '{"provider":"anthropic","api_key":"sk-ant-abc...xyz"}' + } + } + ] +}]` +``` + +Example for GPT 4 deployed on Azure OpenAI: + +``` +MODELS=`[{ + "id": "gpt-4-1106-preview", + "name": "gpt-4-1106-preview", + "displayName": "gpt-4-1106-preview", + "parameters": { + "temperature": 0.5, + "max_new_tokens": 4096, + }, + "endpoints": [ + { + "type": "openai", + "baseURL": "https://gateway.example.com/v1", + "defaultHeaders": { + "x-portkey-config": '{"provider":"azure-openai","resource_name":"abc-fr","deployment_id":"gpt-4-1106-preview","api_version":"2023-03-15-preview","api_key":"abc...xyz"}' + } + } + ] +}]` +``` + +Or try Mistral from [Deepinfra](https://deepinfra.com/mistralai/Mistral-7B-Instruct-v0.1/api?example=openai-http): + +> Note, apiKey can either be set custom per endpoint, or globally using `OPENAI_API_KEY` variable. + +``` +MODELS=`[{ + "name": "mistral-7b", + "displayName": "Mistral 7B", + "description": "A 7B dense Transformer, fast-deployed and easily customisable. Small, yet powerful for a variety of use cases. Supports English and code, and a 8k context window.", + "parameters": { + "temperature": 0.5, + "max_new_tokens": 4096, + }, + "endpoints": [ + { + "type": "openai", + "baseURL": "https://api.deepinfra.com/v1/openai", + "apiKey": "abc...xyz" + } + ] +}]` +``` + ##### Llama.cpp API server chat-ui also supports the llama.cpp API server directly without the need for an adapter. You can do this using the `llamacpp` endpoint type. diff --git a/src/lib/components/DisclaimerModal.svelte b/src/lib/components/DisclaimerModal.svelte index ecb5f22a895..590bb088b3c 100644 --- a/src/lib/components/DisclaimerModal.svelte +++ b/src/lib/components/DisclaimerModal.svelte @@ -1,7 +1,11 @@