CoolFace
Apppublic

MasterDee/chat-ui

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
README.md835 linesDownload Raw Back to root
1---2title: chat-ui3emoji: 🔥4colorFrom: purple5colorTo: purple6sdk: docker7pinned: false8license: apache-2.09base_path: /chat10app_port: 300011failure_strategy: rollback12load_balancing_strategy: random13---14 15# Chat UI16 17![Chat UI repository thumbnail](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/chatui-websearch.png)18 19A chat interface using open source models, eg OpenAssistant or Llama. It is a SvelteKit app and it powers the [HuggingChat app on hf.co/chat](https://huggingface.co/chat).20 210. [No Setup Deploy](#no-setup-deploy)221. [Setup](#setup)232. [Launch](#launch)243. [Web Search](#web-search)254. [Text Embedding Models](#text-embedding-models)265. [Extra parameters](#extra-parameters)276. [Common issues](#common-issues)287. [Deploying to a HF Space](#deploying-to-a-hf-space)298. [Building](#building)30 31## No Setup Deploy32 33If you don't want to configure, setup, and launch your own Chat UI yourself, you can use this option as a fast deploy alternative.34 35You can deploy your own customized Chat UI instance with any supported [LLM](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending) of your choice on [Hugging Face Spaces](https://huggingface.co/spaces). To do so, use the chat-ui template [available here](https://huggingface.co/new-space?template=huggingchat/chat-ui-template).36 37Set `HF_TOKEN` in [Space secrets](https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables) to deploy a model with gated access or a model in a private repository. It's also compatible with [Inference for PROs](https://huggingface.co/blog/inference-pro) curated list of powerful models with higher rate limits. Make sure to create your personal token first in your [User Access Tokens settings](https://huggingface.co/settings/tokens).38 39Read the full tutorial [here](https://huggingface.co/docs/hub/spaces-sdks-docker-chatui#chatui-on-spaces).40 41## Setup42 43The default config for Chat UI is stored in the `.env` file. You will need to override some values to get Chat UI to run locally. This is done in `.env.local`.44 45Start by creating a `.env.local` file in the root of the repository. The bare minimum config you need to get Chat UI to run locally is the following:46 47```env48MONGODB_URL=<the URL to your MongoDB instance>49HF_TOKEN=<your access token>50```51 52### Database53 54The chat history is stored in a MongoDB instance, and having a DB instance available is needed for Chat UI to work.55 56You can use a local MongoDB instance. The easiest way is to spin one up using docker:57 58```bash59docker run -d -p 27017:27017 --name mongo-chatui mongo:latest60```61 62In which case the url of your DB will be `MONGODB_URL=mongodb://localhost:27017`.63 64Alternatively, you can use a [free MongoDB Atlas](https://www.mongodb.com/pricing) instance for this, Chat UI should fit comfortably within their free tier. After which you can set the `MONGODB_URL` variable in `.env.local` to match your instance.65 66### Hugging Face Access Token67 68If you use a remote inference endpoint, you will need a Hugging Face access token to run Chat UI locally. You can get one from [your Hugging Face profile](https://huggingface.co/settings/tokens).69 70## Launch71 72After you're done with the `.env.local` file you can run Chat UI locally with:73 74```bash75npm install76npm run dev77```78 79## Web Search80 81Chat UI features a powerful Web Search feature. It works by:82 831. Generating an appropriate search query from the user prompt.842. Performing web search and extracting content from webpages.853. Creating embeddings from texts using a text embedding model.864. From these embeddings, find the ones that are closest to the user query using a vector similarity search. Specifically, we use `inner product` distance.875. Get the corresponding texts to those closest embeddings and perform [Retrieval-Augmented Generation](https://huggingface.co/papers/2005.11401) (i.e. expand user prompt by adding those texts so that an LLM can use this information).88 89## Text Embedding Models90 91By default (for backward compatibility), when `TEXT_EMBEDDING_MODELS` environment variable is not defined, [transformers.js](https://huggingface.co/docs/transformers.js) embedding models will be used for embedding tasks, specifically, [Xenova/gte-small](https://huggingface.co/Xenova/gte-small) model.92 93You can customize the embedding model by setting `TEXT_EMBEDDING_MODELS` in your `.env.local` file. For example:94 95```env96TEXT_EMBEDDING_MODELS = `[97  {98    "name": "Xenova/gte-small",99    "displayName": "Xenova/gte-small",100    "description": "locally running embedding",101    "chunkCharLength": 512,102    "endpoints": [103      {"type": "transformersjs"}104    ]105  },106  {107    "name": "intfloat/e5-base-v2",108    "displayName": "intfloat/e5-base-v2",109    "description": "hosted embedding model",110    "chunkCharLength": 768,111    "preQuery": "query: ", # See https://huggingface.co/intfloat/e5-base-v2#faq112    "prePassage": "passage: ", # See https://huggingface.co/intfloat/e5-base-v2#faq113    "endpoints": [114      {115        "type": "tei",116        "url": "http://127.0.0.1:8080/",117        "authorization": "TOKEN_TYPE TOKEN" // optional authorization field. Example: "Basic VVNFUjpQQVNT"118      }119    ]120  }121]`122```123 124The required fields are `name`, `chunkCharLength` and `endpoints`.125Supported text embedding backends are: [`transformers.js`](https://huggingface.co/docs/transformers.js), [`TEI`](https://github.com/huggingface/text-embeddings-inference) and [`OpenAI`](https://platform.openai.com/docs/guides/embeddings). `transformers.js` models run locally as part of `chat-ui`, whereas `TEI` models run in a different environment & accessed through an API endpoint. `openai` models are accessed through the [OpenAI API](https://platform.openai.com/docs/guides/embeddings).126 127When more than one embedding models are supplied in `.env.local` file, the first will be used by default, and the others will only be used on LLM's which configured `embeddingModel` to the name of the model.128 129## Extra parameters130 131### OpenID connect132 133The login feature is disabled by default and users are attributed a unique ID based on their browser. But if you want to use OpenID to authenticate your users, you can add the following to your `.env.local` file:134 135```env136OPENID_CONFIG=`{137  PROVIDER_URL: "<your OIDC issuer>",138  CLIENT_ID: "<your OIDC client ID>",139  CLIENT_SECRET: "<your OIDC client secret>",140  SCOPES: "openid profile",141  TOLERANCE: // optional142  RESOURCE: // optional143}`144```145 146These variables will enable the openID sign-in modal for users.147 148### Theming149 150You can use a few environment variables to customize the look and feel of chat-ui. These are by default:151 152```env153PUBLIC_APP_NAME=ChatUI154PUBLIC_APP_ASSETS=chatui155PUBLIC_APP_COLOR=blue156PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone."157PUBLIC_APP_DATA_SHARING=158PUBLIC_APP_DISCLAIMER=159```160 161- `PUBLIC_APP_NAME` The name used as a title throughout the app.162- `PUBLIC_APP_ASSETS` Is used to find logos & favicons in `static/$PUBLIC_APP_ASSETS`, current options are `chatui` and `huggingchat`.163- `PUBLIC_APP_COLOR` Can be any of the [tailwind colors](https://tailwindcss.com/docs/customizing-colors#default-color-palette).164- `PUBLIC_APP_DATA_SHARING` Can be set to 1 to add a toggle in the user settings that lets your users opt-in to data sharing with models creator.165- `PUBLIC_APP_DISCLAIMER` If set to 1, we show a disclaimer about generated outputs on login.166 167### Web Search config168 169You can enable the web search through an API by adding `YDC_API_KEY` ([docs.you.com](https://docs.you.com)) or `SERPER_API_KEY` ([serper.dev](https://serper.dev/)) or `SERPAPI_KEY` ([serpapi.com](https://serpapi.com/)) or `SERPSTACK_API_KEY` ([serpstack.com](https://serpstack.com/)) to your `.env.local`.170 171You can also simply enable the local google websearch by setting `USE_LOCAL_WEBSEARCH=true` in your `.env.local` or specify a SearXNG instance by adding the query URL to `SEARXNG_QUERY_URL`.172 173### Custom models174 175You can customize the parameters passed to the model or even use a new model by updating the `MODELS` variable in your `.env.local`. The default one can be found in `.env` and looks like this :176 177```env178MODELS=`[179  {180    "name": "mistralai/Mistral-7B-Instruct-v0.2",181    "displayName": "mistralai/Mistral-7B-Instruct-v0.2",182    "description": "Mistral 7B is a new Apache 2.0 model, released by Mistral AI that outperforms Llama2 13B in benchmarks.",183    "websiteUrl": "https://mistral.ai/news/announcing-mistral-7b/",184    "preprompt": "",185    "chatPromptTemplate" : "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}}{{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s>{{/ifAssistant}}{{/each}}",186    "parameters": {187      "temperature": 0.3,188      "top_p": 0.95,189      "repetition_penalty": 1.2,190      "top_k": 50,191      "truncate": 3072,192      "max_new_tokens": 1024,193      "stop": ["</s>"]194    },195    "promptExamples": [196      {197        "title": "Write an email from bullet list",198        "prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)"199      }, {200        "title": "Code a snake game",201        "prompt": "Code a basic snake game in python, give explanations for each step."202      }, {203        "title": "Assist in a task",204        "prompt": "How do I make a delicious lemon cheesecake?"205      }206    ]207  }208]`209 210```211 212You can change things like the parameters, or customize the preprompt to better suit your needs. You can also add more models by adding more objects to the array, with different preprompts for example.213 214#### chatPromptTemplate215 216When querying the model for a chat response, the `chatPromptTemplate` template is used. `messages` is an array of chat messages, it has the format `[{ content: string }, ...]`. To identify if a message is a user message or an assistant message the `ifUser` and `ifAssistant` block helpers can be used.217 218The following is the default `chatPromptTemplate`, although newlines and indentiation have been added for readability. You can find the prompts used in production for HuggingChat [here](https://github.com/huggingface/chat-ui/blob/main/PROMPTS.md).219 220```prompt221{{preprompt}}222{{#each messages}}223  {{#ifUser}}{{@root.userMessageToken}}{{content}}{{@root.userMessageEndToken}}{{/ifUser}}224  {{#ifAssistant}}{{@root.assistantMessageToken}}{{content}}{{@root.assistantMessageEndToken}}{{/ifAssistant}}225{{/each}}226{{assistantMessageToken}}227```228 229#### Multi modal model230 231We currently only support IDEFICS as a multimodal model, hosted on TGI. You can enable it by using the following config (if you have a PRO HF Api token):232 233```env234    {235      "name": "HuggingFaceM4/idefics-80b-instruct",236      "multimodal" : true,237      "description": "IDEFICS is the new multimodal model by Hugging Face.",238      "preprompt": "",239      "chatPromptTemplate" : "{{#each messages}}{{#ifUser}}User: {{content}}{{/ifUser}}<end_of_utterance>\nAssistant: {{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}",240      "parameters": {241        "temperature": 0.1,242        "top_p": 0.95,243        "repetition_penalty": 1.2,244        "top_k": 12,245        "truncate": 1000,246        "max_new_tokens": 1024,247        "stop": ["<end_of_utterance>", "User:", "\nUser:"]248      }249    }250```251 252#### Running your own models using a custom endpoint253 254If you want to, instead of hitting models on the Hugging Face Inference API, you can run your own models locally.255 256A good option is to hit a [text-generation-inference](https://github.com/huggingface/text-generation-inference) endpoint. This is what is done in the official [Chat UI Spaces Docker template](https://huggingface.co/new-space?template=huggingchat/chat-ui-template) for instance: both this app and a text-generation-inference server run inside the same container.257 258To do this, you can add your own endpoints to the `MODELS` variable in `.env.local`, by adding an `"endpoints"` key for each model in `MODELS`.259 260```env261{262// rest of the model config here263"endpoints": [{264  "type" : "tgi",265  "url": "https://HOST:PORT",266  }]267}268```269 270If `endpoints` are left unspecified, ChatUI will look for the model on the hosted Hugging Face inference API using the model name.271 272##### OpenAI API compatible models273 274Chat UI can be used with any API server that supports OpenAI API compatibility, for example [text-generation-webui](https://github.com/oobabooga/text-generation-webui/tree/main/extensions/openai), [LocalAI](https://github.com/go-skynet/LocalAI), [FastChat](https://github.com/lm-sys/FastChat/blob/main/docs/openai_api.md), [llama-cpp-python](https://github.com/abetlen/llama-cpp-python), and [ialacol](https://github.com/chenhunghan/ialacol).275 276The following example config makes Chat UI works with [text-generation-webui](https://github.com/oobabooga/text-generation-webui/tree/main/extensions/openai), the `endpoint.baseUrl` is the url of the OpenAI API compatible server, this overrides the baseUrl to be used by OpenAI instance. The `endpoint.completion` determine which endpoint to be used, default is `chat_completions` which uses `v1/chat/completions`, change to `endpoint.completion` to `completions` to use the `v1/completions` endpoint.277 278```279MODELS=`[280  {281    "name": "text-generation-webui",282    "id": "text-generation-webui",283    "parameters": {284      "temperature": 0.9,285      "top_p": 0.95,286      "repetition_penalty": 1.2,287      "top_k": 50,288      "truncate": 1000,289      "max_new_tokens": 1024,290      "stop": []291    },292    "endpoints": [{293      "type" : "openai",294      "baseURL": "http://localhost:8000/v1"295    }]296  }297]`298 299```300 301The `openai` type includes official OpenAI models. You can add, for example, GPT4/GPT3.5 as a "openai" model:302 303```304OPENAI_API_KEY=#your openai api key here305MODELS=`[{306      "name": "gpt-4",307      "displayName": "GPT 4",308      "endpoints" : [{309        "type": "openai"310      }]311},312      {313      "name": "gpt-3.5-turbo",314      "displayName": "GPT 3.5 Turbo",315      "endpoints" : [{316        "type": "openai"317      }]318}]`319```320 321You 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:322 323```324MODELS=`[{325  "name": "claude-2.1",326  "displayName": "Claude 2.1",327  "description": "Anthropic has been founded by former OpenAI researchers...",328  "parameters": {329      "temperature": 0.5,330      "max_new_tokens": 4096,331  },332  "endpoints": [333      {334          "type": "openai",335          "baseURL": "https://gateway.example.com/v1",336          "defaultHeaders": {337              "x-portkey-config": '{"provider":"anthropic","api_key":"sk-ant-abc...xyz"}'338          }339      }340  ]341}]`342```343 344Example for GPT 4 deployed on Azure OpenAI:345 346```347MODELS=`[{348  "id": "gpt-4-1106-preview",349  "name": "gpt-4-1106-preview",350  "displayName": "gpt-4-1106-preview",351  "parameters": {352      "temperature": 0.5,353      "max_new_tokens": 4096,354  },355  "endpoints": [356      {357          "type": "openai",358          "baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",359          "defaultHeaders": {360              "api-key": "{api-key}"361          },362          "defaultQuery": {363              "api-version": "2023-05-15"364          }365      }366  ]367}]`368```369 370Or try Mistral from [Deepinfra](https://deepinfra.com/mistralai/Mistral-7B-Instruct-v0.1/api?example=openai-http):371 372> Note, apiKey can either be set custom per endpoint, or globally using `OPENAI_API_KEY` variable.373 374```375MODELS=`[{376  "name": "mistral-7b",377  "displayName": "Mistral 7B",378  "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.",379  "parameters": {380      "temperature": 0.5,381      "max_new_tokens": 4096,382  },383  "endpoints": [384      {385          "type": "openai",386          "baseURL": "https://api.deepinfra.com/v1/openai",387          "apiKey": "abc...xyz"388      }389  ]390}]`391```392 393##### Llama.cpp API server394 395chat-ui also supports the llama.cpp API server directly without the need for an adapter. You can do this using the `llamacpp` endpoint type.396 397If you want to run chat-ui with llama.cpp, you can do the following, using Zephyr as an example model:398 3991. Get [the weights](https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/tree/main) from the hub4002. Run the server with the following command: `./server -m models/zephyr-7b-beta.Q4_K_M.gguf -c 2048 -np 3`4013. Add the following to your `.env.local`:402 403```env404MODELS=`[405  {406      "name": "Local Zephyr",407      "chatPromptTemplate": "<|system|>\n{{preprompt}}</s>\n{{#each messages}}{{#ifUser}}<|user|>\n{{content}}</s>\n<|assistant|>\n{{/ifUser}}{{#ifAssistant}}{{content}}</s>\n{{/ifAssistant}}{{/each}}",408      "parameters": {409        "temperature": 0.1,410        "top_p": 0.95,411        "repetition_penalty": 1.2,412        "top_k": 50,413        "truncate": 1000,414        "max_new_tokens": 2048,415        "stop": ["</s>"]416      },417      "endpoints": [418        {419         "url": "http://127.0.0.1:8080",420         "type": "llamacpp"421        }422      ]423  }424]`425```426 427Start chat-ui with `npm run dev` and you should be able to chat with Zephyr locally.428 429#### Ollama430 431We also support the Ollama inference server. Spin up a model with432 433```cli434ollama run mistral435```436 437Then specify the endpoints like so:438 439```env440MODELS=`[441  {442      "name": "Ollama Mistral",443      "chatPromptTemplate": "<s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}",444      "parameters": {445        "temperature": 0.1,446        "top_p": 0.95,447        "repetition_penalty": 1.2,448        "top_k": 50,449        "truncate": 3072,450        "max_new_tokens": 1024,451        "stop": ["</s>"]452      },453      "endpoints": [454        {455         "type": "ollama",456         "url" : "http://127.0.0.1:11434",457         "ollamaName" : "mistral"458        }459      ]460  }461]`462```463 464#### Anthropic465 466We also support Anthropic models through the official SDK. You may provide your API key via the `ANTHROPIC_API_KEY` env variable, or alternatively, through the `endpoints.apiKey` as per the following example.467 468```469MODELS=`[470  {471      "name": "claude-3-sonnet-20240229",472      "displayName": "Claude 3 Sonnet",473      "description": "Ideal balance of intelligence and speed",474      "parameters": {475        "max_new_tokens": 4096,476      },477      "endpoints": [478        {479          "type": "anthropic",480          // optionals481          "apiKey": "sk-ant-...",482          "baseURL": "https://api.anthropic.com",483          defaultHeaders: {},484          defaultQuery: {}485        }486      ]487  },488  {489      "name": "claude-3-opus-20240229",490      "displayName": "Claude 3 Opus",491      "description": "Most powerful model for highly complex tasks",492      "parameters": {493         "max_new_tokens": 4096494      },495      "endpoints": [496        {497          "type": "anthropic",498          // optionals499          "apiKey": "sk-ant-...",500          "baseURL": "https://api.anthropic.com",501          defaultHeaders: {},502          defaultQuery: {}503        }504      ]505  }506]`507```508 509#### Amazon510 511You can also specify your Amazon SageMaker instance as an endpoint for chat-ui. The config goes like this:512 513```env514"endpoints": [515    {516      "type" : "aws",517      "service" : "sagemaker"518      "url": "",519      "accessKey": "",520      "secretKey" : "",521      "sessionToken": "",522      "region": "",523 524      "weight": 1525    }526]527```528 529You can also set `"service" : "lambda"` to use a lambda instance.530 531You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.532 533#### Cloudflare Workers AI534 535You can also use Cloudflare Workers AI to run your own models with serverless inference.536 537You will need to have a Cloudflare account, then get your [account ID](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/) as well as your [API token](https://developers.cloudflare.com/workers-ai/get-started/rest-api/#1-get-an-api-token) for Workers AI.538 539You can either specify them directly in your `.env.local` using the `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` variables, or you can set them directly in the endpoint config.540 541You can find the list of models available on Cloudflare [here](https://developers.cloudflare.com/workers-ai/models/#text-generation).542 543```env544  {545  "name" : "nousresearch/hermes-2-pro-mistral-7b",546  "tokenizer": "nousresearch/hermes-2-pro-mistral-7b",547  "parameters": {548    "stop": ["<|im_end|>"]549  },550  "endpoints" : [551    {552      "type" : "cloudflare"553      <!-- optionally specify these554      "accountId": "your-account-id",555      "authToken": "your-api-token"556      -->557    }558  ]559}560```561 562> [!NOTE]  563> Cloudlare Workers AI currently do not support custom sampling parameters like temperature, top_p, etc.564 565#### Cohere566 567You can also use Cohere to run their models directly from chat-ui. You will need to have a Cohere account, then get your [API token](https://dashboard.cohere.com/api-keys). You can either specify it directly in your `.env.local` using the `COHERE_API_TOKEN` variable, or you can set it in the endpoint config.568 569Here is an example of a Cohere model config. You can set which model you want to use by setting the `id` field to the model name.570 571```env572  {573    "name" : "CohereForAI/c4ai-command-r-v01",574    "id": "command-r",575    "description": "C4AI Command-R is a research release of a 35 billion parameter highly performant generative model",576    "endpoints": [577      {578        "type": "cohere",579        <!-- optionally specify these, or use COHERE_API_TOKEN580        "apiKey": "your-api-token"581        -->582      }583    ]584  }585```586 587##### Google Vertex models588 589Chat UI can connect to the google Vertex API endpoints ([List of supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models)).590 591To enable:592 5931. [Select](https://console.cloud.google.com/project) or [create](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project) a Google Cloud project.5941. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).5951. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).5961. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started)597   so you can access the API from your local workstation.598 599The service account credentials file can be imported as an environmental variable:600 601```env602    GOOGLE_APPLICATION_CREDENTIALS = clientid.json603```604 605Make sure your docker container has access to the file and the variable is correctly set.606Afterwards Google Vertex endpoints can be configured as following:607 608```609MODELS=`[610//...611    {612       "name": "gemini-1.5-pro",613       "displayName": "Vertex Gemini Pro 1.5",614       "endpoints" : [{615          "type": "vertex",616          "project": "abc-xyz",617          "location": "europe-west3",618          "model": "gemini-1.5-pro-preview-0409", // model-name619 620          // Optional621          "safetyThreshold": "BLOCK_MEDIUM_AND_ABOVE",622          "apiEndpoint": "", // alternative api endpoint url623       }]624     },625]`626 627```628 629##### LangServe630 631LangChain applications that are deployed using LangServe can be called with the following config:632 633```634MODELS=`[635//...636    {637       "name": "summarization-chain", //model-name638       "endpoints" : [{639         "type": "langserve",640         "url" : "http://127.0.0.1:8100",641       }]642     },643]`644 645```646 647### Custom endpoint authorization648 649#### Basic and Bearer650 651Custom endpoints may require authorization, depending on how you configure them. Authentication will usually be set either with `Basic` or `Bearer`.652 653For `Basic` we will need to generate a base64 encoding of the username and password.654 655`echo -n "USER:PASS" | base64`656 657> VVNFUjpQQVNT658 659For `Bearer` you can use a token, which can be grabbed from [here](https://huggingface.co/settings/tokens).660 661You can then add the generated information and the `authorization` parameter to your `.env.local`.662 663```env664"endpoints": [665  {666    "url": "https://HOST:PORT",667    "authorization": "Basic VVNFUjpQQVNT",668  }669]670```671 672Please note that if `HF_TOKEN` is also set or not empty, it will take precedence.673 674#### Models hosted on multiple custom endpoints675 676If the model being hosted will be available on multiple servers/instances add the `weight` parameter to your `.env.local`. The `weight` will be used to determine the probability of requesting a particular endpoint.677 678```env679"endpoints": [680  {681    "url": "https://HOST:PORT",682    "weight": 1683  },684  {685    "url": "https://HOST:PORT",686    "weight": 2687  }688  ...689]690```691 692#### Client Certificate Authentication (mTLS)693 694Custom endpoints may require client certificate authentication, depending on how you configure them. To enable mTLS between Chat UI and your custom endpoint, you will need to set the `USE_CLIENT_CERTIFICATE` to `true`, and add the `CERT_PATH` and `KEY_PATH` parameters to your `.env.local`. These parameters should point to the location of the certificate and key files on your local machine. The certificate and key files should be in PEM format. The key file can be encrypted with a passphrase, in which case you will also need to add the `CLIENT_KEY_PASSWORD` parameter to your `.env.local`.695 696If you're using a certificate signed by a private CA, you will also need to add the `CA_PATH` parameter to your `.env.local`. This parameter should point to the location of the CA certificate file on your local machine.697 698If you're using a self-signed certificate, e.g. for testing or development purposes, you can set the `REJECT_UNAUTHORIZED` parameter to `false` in your `.env.local`. This will disable certificate validation, and allow Chat UI to connect to your custom endpoint.699 700#### Specific Embedding Model701 702A model can use any of the embedding models defined in `.env.local`, (currently used when web searching),703by default it will use the first embedding model, but it can be changed with the field `embeddingModel`:704 705```env706TEXT_EMBEDDING_MODELS = `[707  {708    "name": "Xenova/gte-small",709    "chunkCharLength": 512,710    "endpoints": [711      {"type": "transformersjs"}712    ]713  },714  {715    "name": "intfloat/e5-base-v2",716    "chunkCharLength": 768,717    "endpoints": [718      {"type": "tei", "url": "http://127.0.0.1:8080/", "authorization": "Basic VVNFUjpQQVNT"},719      {"type": "tei", "url": "http://127.0.0.1:8081/"}720    ]721  }722]`723 724MODELS=`[725  {726      "name": "Ollama Mistral",727      "chatPromptTemplate": "...",728      "embeddingModel": "intfloat/e5-base-v2"729      "parameters": {730        ...731      },732      "endpoints": [733        ...734      ]735  }736]`737```738 739## Common issues740 741### 403:You don't have access to this conversation742 743Most likely you are running chat-ui over HTTP. The recommended option is to setup something like NGINX to handle HTTPS and proxy the requests to chat-ui. If you really need to run over HTTP you can add `ALLOW_INSECURE_COOKIES=true` to your `.env.local`.744 745Make sure to set your `PUBLIC_ORIGIN` in your `.env.local` to the correct URL as well.746 747## Deploying to a HF Space748 749Create a `DOTENV_LOCAL` secret to your HF space with the content of your .env.local, and they will be picked up automatically when you run.750 751## Building752 753To create a production version of your app:754 755```bash756npm run build757```758 759You can preview the production build with `npm run preview`.760 761> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.762 763## Config changes for HuggingChat764 765The config file for HuggingChat is stored in the `.env.template` file at the root of the repository. It is the single source of truth that is used to generate the actual `.env.local` file using our CI/CD pipeline. See [updateProdEnv](https://github.com/huggingface/chat-ui/blob/cdb33a9583f5339ade724db615347393ef48f5cd/scripts/updateProdEnv.ts) for more details.766 767> [!TIP]768> If you want to make changes to the model config used in production for HuggingChat, you should do so against `.env.template`.769 770We currently use the following secrets for deploying HuggingChat in addition to the `.env.template` above:771 772- `MONGODB_URL`773- `HF_TOKEN`774- `OPENID_CONFIG`775- `SERPER_API_KEY`776 777### Running a copy of HuggingChat locally778 779If you want to run an exact copy of HuggingChat locally, you will need to do the following first:780 7811. Create an [OAuth App on the hub](https://huggingface.co/settings/applications/new) with `openid profile email` permissions. Make sure to set the callback URL to something like `http://localhost:5173/chat/login/callback` which matches the right path for your local instance.7822. Create a [HF Token](https://huggingface.co/settings/tokens) with your Hugging Face account. You will need a Pro account to be able to access some of the larger models available through HuggingChat.7833. Create a free account with [serper.dev](https://serper.dev/) (you will get 2500 free search queries)7844. Run an instance of mongoDB, however you want. (Local or remote)785 786You can then create a new `.env.SECRET_CONFIG` file with the following content787 788```env789MONGODB_URL=<link to your mongo DB from step 4>790HF_TOKEN=<your HF token from step 2>791OPENID_CONFIG=`{792  PROVIDER_URL: "https://huggingface.co",793  CLIENT_ID: "<your client ID from step 1>",794  CLIENT_SECRET: "<your client secret from step 1>",795}`796SERPER_API_KEY=<your serper API key from step 3>797MESSAGES_BEFORE_LOGIN=<can be any numerical value, or set to 0 to require login>798```799 800You can then run `npm run updateLocalEnv` in the root of chat-ui. This will create a `.env.local` file which combines the `.env.template` and the `.env.SECRET_CONFIG` file. You can then run `npm run dev` to start your local instance of HuggingChat.801 802### Populate database803 804> [!WARNING]805> The `MONGODB_URL` used for this script will be fetched from `.env.local`. Make sure it's correct! The command runs directly on the database.806 807You can populate the database using faker data using the `populate` script:808 809```bash810npm run populate <flags here>811```812 813At least one flag must be specified, the following flags are available:814 815- `reset` - resets the database816- `all` - populates all tables817- `users` - populates the users table818- `settings` - populates the settings table for existing users819- `assistants` - populates the assistants table for existing users820- `conversations` - populates the conversations table for existing users821 822For example, you could use it like so:823 824```bash825npm run populate reset826```827 828to clear out the database. Then login in the app to create your user and run the following command:829 830```bash831npm run populate users settings assistants conversations832```833 834to populate the database with fake data, including fake conversations and assistants for your user.835