Spaces:
Build error
Build error
github-actions[bot] commited on
Commit ·
42c7b73
0
Parent(s):
GitHub deploy: fe653a133672834321f02d8f21070debccbfb140
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .dockerignoreAdded+20
- .env.exampleAdded+22
- .eslintignoreAdded+13
- .eslintrc.cjsAdded+31
- .gitattributesAdded+42
- .github/FUNDING.ymlAdded+1
- .github/ISSUE_TEMPLATE/bug_report.yamlAdded+176
- .github/ISSUE_TEMPLATE/config.ymlAdded+1
- .github/ISSUE_TEMPLATE/feature_request.yamlAdded+82
- .github/dependabot.ymlAdded+20
- .github/pull_request_template.mdAdded+82
- .github/workflows/build-release.ymlAdded+72
- .github/workflows/codespell.disabledAdded+25
- .github/workflows/deploy-to-hf-spaces.ymlAdded+63
- .github/workflows/docker-build.yamlAdded+806
- .github/workflows/format-backend.yamlAdded+49
- .github/workflows/format-build-frontend.yamlAdded+65
- .github/workflows/integration-test.disabledAdded+255
- .github/workflows/lint-backend.disabledAdded+27
- .github/workflows/lint-frontend.disabledAdded+21
- .github/workflows/release-pypi.ymlAdded+36
- .gitignoreAdded+312
- .npmrcAdded+1
- .prettierignoreAdded+314
- .prettierrcAdded+10
- CHANGELOG.mdAdded
- CODE_OF_CONDUCT.mdAdded+99
- CONTRIBUTOR_LICENSE_AGREEMENTAdded+7
- DockerfileAdded+194
- LICENSEAdded+33
- LICENSE_HISTORYAdded+53
- LICENSE_NOTICEAdded+11
- MakefileAdded+33
- README.mdAdded+245
- TROUBLESHOOTING.mdAdded+36
- backend/.dockerignoreAdded+14
- backend/.gitignoreAdded+12
- backend/dev.shAdded+3
- backend/open_webui/__init__.pyAdded+103
- backend/open_webui/alembic.iniAdded+114
- backend/open_webui/config.pyAdded
- backend/open_webui/constants.pyAdded+126
- backend/open_webui/env.pyAdded+877
- backend/open_webui/functions.pyAdded+352
- backend/open_webui/internal/db.pyAdded+162
- backend/open_webui/internal/migrations/001_initial_schema.pyAdded+254
- backend/open_webui/internal/migrations/002_add_local_sharing.pyAdded+48
- backend/open_webui/internal/migrations/003_add_auth_api_key.pyAdded+48
- backend/open_webui/internal/migrations/004_add_archived.pyAdded+46
- backend/open_webui/internal/migrations/005_add_updated_at.pyAdded+130
1234567891011121314151617181920.github.DS_Storedocskubernetesnode_modules/.svelte-kit/package.env.env.*vite.config.js.timestamp-*vite.config.ts.timestamp-*__pycache__.ideavenv_olduploads.ipynb_checkpoints**/*.db_testbackend/data/*12345678910111213141516171819202122# Ollama URL for the backend to connect# The path '/ollama' will be redirected to the specified backend URLOLLAMA_BASE_URL='http://localhost:11434'
OPENAI_API_BASE_URL=''OPENAI_API_KEY=''
# AUTOMATIC1111_BASE_URL="http://localhost:7860"
# For production, you should only need one host as# fastapi serves the svelte-kit built frontend and backend from the same host and port.# To test with CORS locally, you can set something like# CORS_ALLOW_ORIGIN='http://localhost:5173;http://localhost:8080'CORS_ALLOW_ORIGIN='*'
# For production you should set this to match the proxy configuration (127.0.0.1)FORWARDED_ALLOW_IPS='*'
# DO NOT TRACKSCARF_NO_ANALYTICS=trueDO_NOT_TRACK=trueANONYMIZED_TELEMETRY=false12345678910111213.DS_Storenode_modules/build/.svelte-kit/package.env.env.*!.env.example
# Ignore files for PNPM, NPM and YARNpnpm-lock.yamlpackage-lock.jsonyarn.lock12345678910111213141516171819202122232425262728293031module.exports = { root: true, extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:svelte/recommended', 'plugin:cypress/recommended', 'prettier' ], parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint'], parserOptions: { sourceType: 'module', ecmaVersion: 2020, extraFileExtensions: ['.svelte'] }, env: { browser: true, es2017: true, node: true }, overrides: [ { files: ['*.svelte'], parser: 'svelte-eslint-parser', parserOptions: { parser: '@typescript-eslint/parser' } } ]};123456789101112131415161718192021222324252627282930313233343536373839404142# TypeScript*.ts text eol=lf*.tsx text eol=lf# JavaScript*.js text eol=lf*.jsx text eol=lf*.mjs text eol=lf*.cjs text eol=lf# Svelte*.svelte text eol=lf# HTML/CSS*.html text eol=lf*.css text eol=lf*.scss text eol=lf*.less text eol=lf# Config files and JSON*.json text eol=lf*.jsonc text eol=lf*.yml text eol=lf*.yaml text eol=lf*.toml text eol=lf# Shell scripts*.sh text eol=lf# Markdown & docs*.md text eol=lf*.mdx text eol=lf*.txt text eol=lf# Git-related.gitattributes text eol=lf.gitignore text eol=lf# Prettier and other dotfiles.prettierrc text eol=lf.prettierignore text eol=lf.eslintrc text eol=lf.eslintignore text eol=lf.stylelintrc text eol=lf.editorconfig text eol=lf# Misc*.env text eol=lf*.lock text eol=lf*.ttf filter=lfs diff=lfs merge=lfs -text*.jpg filter=lfs diff=lfs merge=lfs -text1github: tjbck123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176name: Bug Reportdescription: Create a detailed bug report to help us improve Open WebUI.title: 'issue: 'labels: ['bug', 'triage']assignees: []body: - type: markdown attributes: value: | # Bug Report
## Important Notes
- **Before submitting a bug report**: Please check the [Issues](https://github.com/open-webui/open-webui/issues) and [Discussions](https://github.com/open-webui/open-webui/discussions) sections to see if a similar issue has already been reported. If unsure, start a discussion first, as this helps us efficiently focus on improving the project. Duplicates may be closed without notice. **Please search for existing issues AND discussions. No matter open or closed.**
- Check for opened, **but also for (recently) CLOSED issues** as the issue you are trying to report **might already have been fixed on the dev branch!**
- **Respectful collaboration**: Open WebUI is a volunteer-driven project with a single maintainer and contributors who also have full-time jobs. Please be constructive and respectful in your communication.
- **Contributing**: If you encounter an issue, consider submitting a pull request or forking the project. We prioritize preventing contributor burnout to maintain Open WebUI's quality.
- **Bug Reproducibility**: If a bug cannot be reproduced using a `:main` or `:dev` Docker setup or with `pip install` on Python 3.11, community assistance may be required. In such cases, we will move it to the "[Issues](https://github.com/open-webui/open-webui/discussions/categories/issues)" Discussions section. Your help is appreciated!
- **Scope**: If you want to report a SECURITY VULNERABILITY, then do so through our [GitHub security page](https://github.com/open-webui/open-webui/security).
- type: checkboxes id: issue-check attributes: label: Check Existing Issues description: Confirm that you’ve checked for existing reports before submitting a new one. options: - label: I have searched for any existing and/or related issues. required: true - label: I have searched for any existing and/or related discussions. required: true - label: I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). required: true - label: I am using the latest version of Open WebUI. required: true
- type: dropdown id: installation-method attributes: label: Installation Method description: How did you install Open WebUI? options: - Git Clone - Pip Install - Docker - Other validations: required: true
- type: input id: open-webui-version attributes: label: Open WebUI Version description: Specify the version (e.g., v0.6.26) validations: required: true
- type: input id: ollama-version attributes: label: Ollama Version (if applicable) description: Specify the version (e.g., v0.2.0, or v0.1.32-rc1) validations: required: false
- type: input id: operating-system attributes: label: Operating System description: Specify the OS (e.g., Windows 10, macOS Sonoma, Ubuntu 22.04, Debian 12) validations: required: true
- type: input id: browser attributes: label: Browser (if applicable) description: Specify the browser/version (e.g., Chrome 100.0, Firefox 98.0) validations: required: false
- type: checkboxes id: confirmation attributes: label: Confirmation description: Ensure the following prerequisites have been met. options: - label: I have read and followed all instructions in `README.md`. required: true - label: I am using the latest version of **both** Open WebUI and Ollama. required: true - label: I have included the browser console logs. required: true - label: I have included the Docker container logs. required: true - label: I have **provided every relevant configuration, setting, and environment variable used in my setup.** required: true - label: I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). required: true - label: | I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. required: true - type: textarea id: expected-behavior attributes: label: Expected Behavior description: Describe what should have happened. validations: required: true
- type: textarea id: actual-behavior attributes: label: Actual Behavior description: Describe what actually happened. validations: required: true
- type: textarea id: reproduction-steps attributes: label: Steps to Reproduce description: | Please provide a **very detailed, step-by-step guide** to reproduce the issue. Your instructions should be so clear and precise that anyone can follow them without guesswork. Include every relevant detail—settings, configuration options, exact commands used, values entered, and any prerequisites or environment variables. **If full reproduction steps and all relevant settings are not provided, your issue may not be addressed.** **If your steps to reproduction are incomplete, lacking detail or not reproducible, your issue can not be addressed.**
placeholder: | Example (include every detail): 1. Start with a clean Ubuntu 22.04 install. 2. Install Docker v24.0.5 and start the service. 3. Clone the Open WebUI repo (git clone ...). 4. Use the Docker Compose file without modifications. 5. Open browser Chrome 115.0 in incognito mode. 6. Go to http://localhost:8080 and log in with user "test@example.com". 7. Set the language to "English" and theme to "Dark". 8. Attempt to connect to Ollama at "http://localhost:11434". 9. Observe that the error message "Connection refused" appears at the top right.
Please list each step carefully and include all relevant configuration, settings, and options. validations: required: true - type: textarea id: logs-screenshots attributes: label: Logs & Screenshots description: Include relevant logs, errors, or screenshots to help diagnose the issue. placeholder: 'Attach logs from the browser console, Docker logs, or error messages.' validations: required: true
- type: textarea id: additional-info attributes: label: Additional Information description: Provide any extra details that may assist in understanding the issue. validations: required: false
- type: markdown attributes: value: | ## Note **If the bug report is incomplete, does not follow instructions or is lacking details it may not be addressed.** Ensure that you've followed all the **README.md** and **troubleshooting.md** guidelines, and provide all necessary information for us to reproduce the issue. Thank you for contributing to Open WebUI!1blank_issues_enabled: false12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182name: Feature Requestdescription: Suggest an idea for this projecttitle: 'feat: 'labels: ['triage']body: - type: markdown attributes: value: | ## Important Notes ### Before submitting Please check the **open AND closed** [Issues](https://github.com/open-webui/open-webui/issues) AND [Discussions](https://github.com/open-webui/open-webui/discussions) to see if a similar request has been posted. It's likely we're already tracking it! If you’re unsure, start a discussion post first.
#### Scope
If your feature request is likely to take more than a quick coding session to implement, test and verify, then open it in the **Ideas** section of the [Discussions](https://github.com/open-webui/open-webui/discussions) instead. **We will close and force move your feature request to the Ideas section, if we believe your feature request is not trivial/quick to implement.** This is to ensure the issues tab is used only for issues, quickly addressable feature requests and tracking tickets by the maintainers. Other feature requests belong in the **Ideas** section of the [Discussions](https://github.com/open-webui/open-webui/discussions). If your feature request might impact others in the community, definitely open a discussion instead and evaluate whether and how to implement it. This will help us efficiently focus on improving the project. ### Collaborate respectfully We value a **constructive attitude**, so please be mindful of your communication. If negativity is part of your approach, our capacity to engage may be limited. We're here to help if you're **open to learning** and **communicating positively**.
Remember: - Open WebUI is a **volunteer-driven project** - It's managed by a **single maintainer** - It's supported by contributors who also have **full-time jobs**
We appreciate your time and ask that you **respect ours**.
### Contributing If you encounter an issue, we highly encourage you to submit a pull request or fork the project. We actively work to prevent contributor burnout to maintain the quality and continuity of Open WebUI.
### Bug reproducibility If a bug cannot be reproduced with a `:main` or `:dev` Docker setup, or a `pip install` with Python 3.11, it may require additional help from the community. In such cases, we will move it to the "[issues](https://github.com/open-webui/open-webui/discussions/categories/issues)" Discussions section due to our limited resources. We encourage the community to assist with these issues. Remember, it’s not that the issue doesn’t exist; we need your help!
- type: checkboxes id: existing-issue attributes: label: Check Existing Issues description: Please confirm that you've checked for existing similar requests options: - label: I have searched for all existing **open AND closed** issues and discussions for similar requests. I have found none that is comparable to my request. required: true - type: checkboxes id: feature-scope attributes: label: Verify Feature Scope description: Please confirm the feature's scope is within the described scope options: - label: I have read through and understood the scope definition for feature requests in the Issues section. I believe my feature request meets the definition and belongs in the Issues section instead of the Discussions. required: true - type: textarea id: problem-description attributes: label: Problem Description description: Is your feature request related to a problem? Please provide a clear and concise description of what the problem is. placeholder: "Ex. I'm always frustrated when... / Not related to a problem" validations: required: true - type: textarea id: solution-description attributes: label: Desired Solution you'd like description: Clearly describe what you want to happen. validations: required: true - type: textarea id: alternatives-considered attributes: label: Alternatives Considered description: A clear and concise description of any alternative solutions or features you've considered. - type: textarea id: additional-context attributes: label: Additional Context description: Add any other context or screenshots about the feature request here.1234567891011121314151617181920version: 2updates: - package-ecosystem: uv directory: '/' schedule: interval: monthly target-branch: 'dev'
- package-ecosystem: pip directory: '/backend' schedule: interval: monthly target-branch: 'dev'
- package-ecosystem: 'github-actions' directory: '/' schedule: # Check for updates to GitHub Actions every week interval: monthly target-branch: 'dev'12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182# Pull Request Checklist
### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
**Before submitting, make sure you've checked the following:**
- [ ] **Target branch:** Verify that the pull request targets the `dev` branch. **Not targeting the `dev` branch will lead to immediate closure of the PR.**- [ ] **Description:** Provide a concise description of the changes made in this pull request down below.- [ ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.- [ ] **Documentation:** If necessary, update relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs) like environment variables, the tutorials, or other documentation sources.- [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?- [ ] **Testing:** Perform manual tests to **verify the implemented fix/feature works as intended AND does not break any other functionality**. Take this as an opportunity to **make screenshots of the feature/fix and include it in the PR description**.- [ ] **Agentic AI Code:** Confirm this Pull Request is **not written by any AI Agent** or has at least **gone through additional human review AND manual testing**. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR.- [ ] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?- [ ] **Title Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
- [Concisely describe the changes made in this pull request, including any relevant motivation and impact (e.g., fixing a bug, adding a feature, or improving performance)]
### Added
- [List any new features, functionalities, or additions]
### Changed
- [List any changes, updates, refactorings, or optimizations]
### Deprecated
- [List any deprecated functionality or features that have been removed]
### Removed
- [List any removed features, files, or functionalities]
### Fixed
- [List any fixes, corrections, or bug fixes]
### Security
- [List any new or updated security-related changes, including vulnerability fixes]
### Breaking Changes
- **BREAKING CHANGE**: [List any breaking changes affecting compatibility or functionality]
---
### Additional Information
- [Insert any additional context, notes, or explanations for the changes] - [Reference any related issues, commits, or other relevant information]
### Screenshots or Videos
- [Attach any relevant screenshots or videos demonstrating the changes]
### Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
> [!NOTE]> Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172name: Release
on: push: branches: - main # or whatever branch you want to use
jobs: release: runs-on: ubuntu-latest
steps: - name: Checkout repository uses: actions/checkout@v5
- name: Check for changes in package.json run: | git diff --cached --diff-filter=d package.json || { echo "No changes to package.json" exit 1 }
- name: Get version number from package.json id: get_version run: | VERSION=$(jq -r '.version' package.json) echo "::set-output name=version::$VERSION"
- name: Extract latest CHANGELOG entry id: changelog run: | CHANGELOG_CONTENT=$(awk 'BEGIN {print_section=0;} /^## \[/ {if (print_section == 0) {print_section=1;} else {exit;}} print_section {print;}' CHANGELOG.md) CHANGELOG_ESCAPED=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\n/%0A/g') echo "Extracted latest release notes from CHANGELOG.md:" echo -e "$CHANGELOG_CONTENT" echo "::set-output name=content::$CHANGELOG_ESCAPED"
- name: Create GitHub release uses: actions/github-script@v8 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const changelog = `${{ steps.changelog.outputs.content }}`; const release = await github.rest.repos.createRelease({ owner: context.repo.owner, repo: context.repo.repo, tag_name: `v${{ steps.get_version.outputs.version }}`, name: `v${{ steps.get_version.outputs.version }}`, body: changelog, }) console.log(`Created release ${release.data.html_url}`)
- name: Upload package to GitHub release uses: actions/upload-artifact@v4 with: name: package path: | . !.git env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger Docker build workflow uses: actions/github-script@v8 with: script: | github.rest.actions.createWorkflowDispatch({ owner: context.repo.owner, repo: context.repo.repo, workflow_id: 'docker-build.yaml', ref: 'v${{ steps.get_version.outputs.version }}', })12345678910111213141516171819202122232425# Codespell configuration is within pyproject.toml---name: Codespell
on: push: branches: [main] pull_request: branches: [main]
permissions: contents: read
jobs: codespell: name: Check for spelling errors runs-on: ubuntu-latest
steps: - name: Checkout uses: actions/checkout@v4 - name: Annotate locations with typos uses: codespell-project/codespell-problem-matcher@v1 - name: Codespell uses: codespell-project/actions-codespell@v2123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263name: Deploy to HuggingFace Spaces
on: push: branches: - dev - main workflow_dispatch:
jobs: check-secret: runs-on: ubuntu-latest outputs: token-set: ${{ steps.check-key.outputs.defined }} steps: - id: check-key env: HF_TOKEN: ${{ secrets.HF_TOKEN }} if: "${{ env.HF_TOKEN != '' }}" run: echo "defined=true" >> $GITHUB_OUTPUT
deploy: runs-on: ubuntu-latest needs: [check-secret] if: needs.check-secret.outputs.token-set == 'true' env: HF_TOKEN: ${{ secrets.HF_TOKEN }} steps: - name: Checkout repository uses: actions/checkout@v5 with: lfs: true
- name: Remove git history run: rm -rf .git
- name: Prepend YAML front matter to README.md run: | echo "---" > temp_readme.md echo "title: Open WebUI" >> temp_readme.md echo "emoji: 🐳" >> temp_readme.md echo "colorFrom: purple" >> temp_readme.md echo "colorTo: gray" >> temp_readme.md echo "sdk: docker" >> temp_readme.md echo "app_port: 8080" >> temp_readme.md echo "---" >> temp_readme.md cat README.md >> temp_readme.md mv temp_readme.md README.md
- name: Configure git run: | git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" - name: Set up Git and push to Space run: | git init --initial-branch=main git lfs install git lfs track "*.ttf" git lfs track "*.jpg" rm demo.gif git add . git commit -m "GitHub deploy: ${{ github.sha }}" git push --force https://open-webui:${HF_TOKEN}@huggingface.co/spaces/open-webui/open-webui main123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806name: Create and publish Docker images with specific build args
on: workflow_dispatch: push: branches: - main - dev tags: - v*
env: REGISTRY: ghcr.io
jobs: build-main-image: runs-on: ${{ matrix.runner }} permissions: contents: read packages: write strategy: fail-fast: false matrix: include: - platform: linux/amd64 runner: ubuntu-latest - platform: linux/arm64 runner: ubuntu-24.04-arm
steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout repository uses: actions/checkout@v5
- name: Set up QEMU uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (default latest tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} flavor: | latest=${{ github.ref == 'refs/heads/main' }}
- name: Extract metadata for Docker cache id: cache-meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }} flavor: | prefix=cache-${{ matrix.platform }}- latest=false
- name: Build Docker image (latest) uses: docker/build-push-action@v5 id: build with: context: . push: true platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }} cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max build-args: | BUILD_HASH=${{ github.sha }}
- name: Export digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-main-${{ env.PLATFORM_PAIR }} path: /tmp/digests/* if-no-files-found: error retention-days: 1
build-cuda-image: runs-on: ${{ matrix.runner }} permissions: contents: read packages: write strategy: fail-fast: false matrix: include: - platform: linux/amd64 runner: ubuntu-latest - platform: linux/arm64 runner: ubuntu-24.04-arm
steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Delete huge unnecessary tools folder run: rm -rf /opt/hostedtoolcache
- name: Checkout repository uses: actions/checkout@v5
- name: Set up QEMU uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (cuda tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-cuda,onlatest=true
- name: Extract metadata for Docker cache id: cache-meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }} flavor: | prefix=cache-cuda-${{ matrix.platform }}- latest=false
- name: Build Docker image (cuda) uses: docker/build-push-action@v5 id: build with: context: . push: true platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }} cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max build-args: | BUILD_HASH=${{ github.sha }} USE_CUDA=true
- name: Export digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-cuda-${{ env.PLATFORM_PAIR }} path: /tmp/digests/* if-no-files-found: error retention-days: 1
build-cuda126-image: runs-on: ${{ matrix.runner }} permissions: contents: read packages: write strategy: fail-fast: false matrix: include: - platform: linux/amd64 runner: ubuntu-latest - platform: linux/arm64 runner: ubuntu-24.04-arm
steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Delete huge unnecessary tools folder run: rm -rf /opt/hostedtoolcache
- name: Checkout repository uses: actions/checkout@v5
- name: Set up QEMU uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (cuda126 tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda126 flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-cuda126,onlatest=true
- name: Extract metadata for Docker cache id: cache-meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }} flavor: | prefix=cache-cuda126-${{ matrix.platform }}- latest=false
- name: Build Docker image (cuda126) uses: docker/build-push-action@v5 id: build with: context: . push: true platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }} cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max build-args: | BUILD_HASH=${{ github.sha }} USE_CUDA=true USE_CUDA_VER=cu126
- name: Export digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-cuda126-${{ env.PLATFORM_PAIR }} path: /tmp/digests/* if-no-files-found: error retention-days: 1
build-ollama-image: runs-on: ${{ matrix.runner }} permissions: contents: read packages: write strategy: fail-fast: false matrix: include: - platform: linux/amd64 runner: ubuntu-latest - platform: linux/arm64 runner: ubuntu-24.04-arm
steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout repository uses: actions/checkout@v5
- name: Set up QEMU uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (ollama tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-ollama,onlatest=true
- name: Extract metadata for Docker cache id: cache-meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }} flavor: | prefix=cache-ollama-${{ matrix.platform }}- latest=false
- name: Build Docker image (ollama) uses: docker/build-push-action@v5 id: build with: context: . push: true platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }} cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max build-args: | BUILD_HASH=${{ github.sha }} USE_OLLAMA=true
- name: Export digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-ollama-${{ env.PLATFORM_PAIR }} path: /tmp/digests/* if-no-files-found: error retention-days: 1
build-slim-image: runs-on: ${{ matrix.runner }} permissions: contents: read packages: write strategy: fail-fast: false matrix: include: - platform: linux/amd64 runner: ubuntu-latest - platform: linux/arm64 runner: ubuntu-24.04-arm
steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout repository uses: actions/checkout@v5
- name: Set up QEMU uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (slim tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=slim flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-slim,onlatest=true
- name: Extract metadata for Docker cache id: cache-meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }} flavor: | prefix=cache-slim-${{ matrix.platform }}- latest=false
- name: Build Docker image (slim) uses: docker/build-push-action@v5 id: build with: context: . push: true platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }} cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max build-args: | BUILD_HASH=${{ github.sha }} USE_SLIM=true
- name: Export digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-slim-${{ env.PLATFORM_PAIR }} path: /tmp/digests/* if-no-files-found: error retention-days: 1
merge-main-images: runs-on: ubuntu-latest needs: [build-main-image] steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Download digests uses: actions/download-artifact@v5 with: pattern: digests-main-* path: /tmp/digests merge-multiple: true
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (default latest tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} flavor: | latest=${{ github.ref == 'refs/heads/main' }}
- name: Create manifest list and push working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image run: | docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
merge-cuda-images: runs-on: ubuntu-latest needs: [build-cuda-image] steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Download digests uses: actions/download-artifact@v5 with: pattern: digests-cuda-* path: /tmp/digests merge-multiple: true
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (default latest tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-cuda,onlatest=true
- name: Create manifest list and push working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image run: | docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
merge-cuda126-images: runs-on: ubuntu-latest needs: [build-cuda126-image] steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Download digests uses: actions/download-artifact@v5 with: pattern: digests-cuda126-* path: /tmp/digests merge-multiple: true
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (default latest tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda126 flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-cuda126,onlatest=true
- name: Create manifest list and push working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image run: | docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
merge-ollama-images: runs-on: ubuntu-latest needs: [build-ollama-image] steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Download digests uses: actions/download-artifact@v5 with: pattern: digests-ollama-* path: /tmp/digests merge-multiple: true
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (default ollama tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-ollama,onlatest=true
- name: Create manifest list and push working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image run: | docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
merge-slim-images: runs-on: ubuntu-latest needs: [build-slim-image] steps: # GitHub Packages requires the entire repository name to be in lowercase # although the repository owner has a lowercase username, this prevents some people from running actions after forking - name: Set repository and image name to lowercase run: | echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV} env: IMAGE_NAME: '${{ github.repository }}'
- name: Download digests uses: actions/download-artifact@v5 with: pattern: digests-slim-* path: /tmp/digests merge-multiple: true
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images (default slim tag) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.FULL_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=tag type=sha,prefix=git- type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=slim flavor: | latest=${{ github.ref == 'refs/heads/main' }} suffix=-slim,onlatest=true
- name: Create manifest list and push working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image run: | docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849name: Python CI
on: push: branches: - main - dev paths: - 'backend/**' - 'pyproject.toml' - 'uv.lock' pull_request: branches: - main - dev paths: - 'backend/**' - 'pyproject.toml' - 'uv.lock'
jobs: build: name: 'Format Backend' runs-on: ubuntu-latest
strategy: matrix: python-version: - 3.11.x - 3.12.x
steps: - uses: actions/checkout@v5
- name: Set up Python uses: actions/setup-python@v6 with: python-version: '${{ matrix.python-version }}'
- name: Install dependencies run: | python -m pip install --upgrade pip pip install black
- name: Format backend run: npm run format:backend
- name: Check for changes after format run: git diff --exit-code1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465name: Frontend Build
on: push: branches: - main - dev paths-ignore: - 'backend/**' - 'pyproject.toml' - 'uv.lock' pull_request: branches: - main - dev paths-ignore: - 'backend/**' - 'pyproject.toml' - 'uv.lock'
jobs: build: name: 'Format & Build Frontend' runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v5
- name: Setup Node.js uses: actions/setup-node@v5 with: node-version: '22'
- name: Install Dependencies run: npm install --force
- name: Format Frontend run: npm run format
- name: Run i18next run: npm run i18n:parse
- name: Check for Changes After Format run: git diff --exit-code
- name: Build Frontend run: npm run build
test-frontend: name: 'Frontend Unit Tests' runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v5
- name: Setup Node.js uses: actions/setup-node@v5 with: node-version: '22'
- name: Install Dependencies run: npm ci --force
- name: Run vitest run: npm run test:frontend123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255name: Integration Test
on: push: branches: - main - dev pull_request: branches: - main - dev
jobs: cypress-run: name: Run Cypress Integration Tests runs-on: ubuntu-latest steps: - name: Maximize build space uses: AdityaGarg8/remove-unwanted-software@v4.1 with: remove-android: 'true' remove-haskell: 'true' remove-codeql: 'true'
- name: Checkout Repository uses: actions/checkout@v4
- name: Build and run Compose Stack run: | docker compose \ --file docker-compose.yaml \ --file docker-compose.api.yaml \ --file docker-compose.a1111-test.yaml \ up --detach --build
- name: Delete Docker build cache run: | docker builder prune --all --force
- name: Wait for Ollama to be up timeout-minutes: 5 run: | until curl --output /dev/null --silent --fail http://localhost:11434; do printf '.' sleep 1 done echo "Service is up!"
- name: Preload Ollama model run: | docker exec ollama ollama pull qwen:0.5b-chat-v1.5-q2_K
- name: Cypress run uses: cypress-io/github-action@v6 env: LIBGL_ALWAYS_SOFTWARE: 1 with: browser: chrome wait-on: 'http://localhost:3000' config: baseUrl=http://localhost:3000
- uses: actions/upload-artifact@v4 if: always() name: Upload Cypress videos with: name: cypress-videos path: cypress/videos if-no-files-found: ignore
- name: Extract Compose logs if: always() run: | docker compose logs > compose-logs.txt
- uses: actions/upload-artifact@v4 if: always() name: Upload Compose logs with: name: compose-logs path: compose-logs.txt if-no-files-found: ignore
# pytest: # name: Run Backend Tests # runs-on: ubuntu-latest # steps: # - uses: actions/checkout@v4
# - name: Set up Python # uses: actions/setup-python@v5 # with: # python-version: ${{ matrix.python-version }}
# - name: Install dependencies # run: | # python -m pip install --upgrade pip # pip install -r backend/requirements.txt
# - name: pytest run # run: | # ls -al # cd backend # PYTHONPATH=. pytest . -o log_cli=true -o log_cli_level=INFO
migration_test: name: Run Migration Tests runs-on: ubuntu-latest services: postgres: image: postgres env: POSTGRES_PASSWORD: postgres options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 # mysql: # image: mysql # env: # MYSQL_ROOT_PASSWORD: mysql # MYSQL_DATABASE: mysql # options: >- # --health-cmd "mysqladmin ping -h localhost" # --health-interval 10s # --health-timeout 5s # --health-retries 5 # ports: # - 3306:3306 steps: - name: Checkout Repository uses: actions/checkout@v4
- name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }}
- name: Set up uv uses: yezz123/setup-uv@v4 with: uv-venv: venv
- name: Activate virtualenv run: | . venv/bin/activate echo PATH=$PATH >> $GITHUB_ENV
- name: Install dependencies run: | uv pip install -r backend/requirements.txt
- name: Test backend with SQLite id: sqlite env: WEBUI_SECRET_KEY: secret-key GLOBAL_LOG_LEVEL: debug run: | cd backend uvicorn open_webui.main:app --port "8080" --forwarded-allow-ips '*' & UVICORN_PID=$! # Wait up to 40 seconds for the server to start for i in {1..40}; do curl -s http://localhost:8080/api/config > /dev/null && break sleep 1 if [ $i -eq 40 ]; then echo "Server failed to start" kill -9 $UVICORN_PID exit 1 fi done # Check that the server is still running after 5 seconds sleep 5 if ! kill -0 $UVICORN_PID; then echo "Server has stopped" exit 1 fi
- name: Test backend with Postgres if: success() || steps.sqlite.conclusion == 'failure' env: WEBUI_SECRET_KEY: secret-key GLOBAL_LOG_LEVEL: debug DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres DATABASE_POOL_SIZE: 10 DATABASE_POOL_MAX_OVERFLOW: 10 DATABASE_POOL_TIMEOUT: 30 run: | cd backend uvicorn open_webui.main:app --port "8081" --forwarded-allow-ips '*' & UVICORN_PID=$! # Wait up to 20 seconds for the server to start for i in {1..20}; do curl -s http://localhost:8081/api/config > /dev/null && break sleep 1 if [ $i -eq 20 ]; then echo "Server failed to start" kill -9 $UVICORN_PID exit 1 fi done # Check that the server is still running after 5 seconds sleep 5 if ! kill -0 $UVICORN_PID; then echo "Server has stopped" exit 1 fi
# Check that service will reconnect to postgres when connection will be closed status_code=$(curl --write-out %{http_code} -s --output /dev/null http://localhost:8081/health/db) if [[ "$status_code" -ne 200 ]] ; then echo "Server has failed before postgres reconnect check" exit 1 fi
echo "Terminating all connections to postgres..." python -c "import os, psycopg2 as pg2; \ conn = pg2.connect(dsn=os.environ['DATABASE_URL'].replace('+pool', '')); \ cur = conn.cursor(); \ cur.execute('SELECT pg_terminate_backend(psa.pid) FROM pg_stat_activity psa WHERE datname = current_database() AND pid <> pg_backend_pid();')"
status_code=$(curl --write-out %{http_code} -s --output /dev/null http://localhost:8081/health/db) if [[ "$status_code" -ne 200 ]] ; then echo "Server has not reconnected to postgres after connection was closed: returned status $status_code" exit 1 fi
# - name: Test backend with MySQL# if: success() || steps.sqlite.conclusion == 'failure' || steps.postgres.conclusion == 'failure'# env:# WEBUI_SECRET_KEY: secret-key# GLOBAL_LOG_LEVEL: debug# DATABASE_URL: mysql://root:mysql@localhost:3306/mysql# run: |# cd backend# uvicorn open_webui.main:app --port "8083" --forwarded-allow-ips '*' &# UVICORN_PID=$!# # Wait up to 20 seconds for the server to start# for i in {1..20}; do# curl -s http://localhost:8083/api/config > /dev/null && break# sleep 1# if [ $i -eq 20 ]; then# echo "Server failed to start"# kill -9 $UVICORN_PID# exit 1# fi# done# # Check that the server is still running after 5 seconds# sleep 5# if ! kill -0 $UVICORN_PID; then# echo "Server has stopped"# exit 1# fi123456789101112131415161718192021222324252627name: Python CIon: push: branches: ['main'] pull_request:jobs: build: name: 'Lint Backend' env: PUBLIC_API_BASE_URL: '' runs-on: ubuntu-latest strategy: matrix: node-version: - latest steps: - uses: actions/checkout@v4 - name: Use Python uses: actions/setup-python@v5 - name: Use Bun uses: oven-sh/setup-bun@v1 - name: Install dependencies run: | python -m pip install --upgrade pip pip install pylint - name: Lint backend run: bun run lint:backend123456789101112131415161718192021name: Bun CIon: push: branches: ['main'] pull_request:jobs: build: name: 'Lint Frontend' env: PUBLIC_API_BASE_URL: '' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Use Bun uses: oven-sh/setup-bun@v1 - run: bun --version - name: Install frontend dependencies run: bun install --frozen-lockfile - run: bun run lint:frontend - run: bun run lint:types if: success() || failure()123456789101112131415161718192021222324252627282930313233343536name: Release to PyPI
on: push: branches: - main # or whatever branch you want to use - pypi-release
jobs: release: runs-on: ubuntu-latest environment: name: pypi url: https://pypi.org/p/open-webui permissions: id-token: write steps: - name: Checkout repository uses: actions/checkout@v5 with: fetch-depth: 0 - name: Install Git run: sudo apt-get update && sudo apt-get install -y git - uses: actions/setup-node@v5 with: node-version: 22 - uses: actions/setup-python@v6 with: python-version: 3.11 - name: Build run: | python -m pip install --upgrade pip pip install build python -m build . - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312x.pyyarn.lock.DS_Storenode_modules/build/.svelte-kit/package.env.env.*!.env.examplevite.config.js.timestamp-*vite.config.ts.timestamp-*# Byte-compiled / optimized / DLL files__pycache__/*.py[cod]*$py.class.nvmrcCLAUDE.md# C extensions*.so
# Pyodide distributionstatic/pyodide/*!static/pyodide/pyodide-lock.json
# Distribution / packaging.Pythonbuild/develop-eggs/dist/downloads/eggs/.eggs/lib64/parts/sdist/var/wheels/share/python-wheels/*.egg-info/.installed.cfg*.eggMANIFEST
# PyInstaller# Usually these files are written by a python script from a template# before PyInstaller builds the exe, so as to inject date/other infos into it.*.manifest*.spec
# Installer logspip-log.txtpip-delete-this-directory.txt
# Unit test / coverage reportshtmlcov/.tox/.nox/.coverage.coverage.*.cachenosetests.xmlcoverage.xml*.cover*.py,cover.hypothesis/.pytest_cache/cover/
# Translations*.mo*.pot
# Django stuff:*.loglocal_settings.pydb.sqlite3db.sqlite3-journal
# Flask stuff:instance/.webassets-cache
# Scrapy stuff:.scrapy
# Sphinx documentationdocs/_build/
# PyBuilder.pybuilder/target/
# Jupyter Notebook.ipynb_checkpoints
# IPythonprofile_default/ipython_config.py
# pyenv# For a library or package, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# .python-version
# pipenv# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.# However, in case of collaboration, if having platform-specific dependencies or dependencies# having no cross-platform support, pipenv may install dependencies that don't work, or not# install all needed dependencies.#Pipfile.lock
# poetry# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.# This is especially recommended for binary packages to ensure reproducibility, and is more# commonly ignored for libraries.# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control#poetry.lock
# pdm# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.#pdm.lock# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it# in version control.# https://pdm.fming.dev/#use-with-ide.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm__pypackages__/
# Celery stuffcelerybeat-schedulecelerybeat.pid
# SageMath parsed files*.sage.py
# Environments.env.venvenv/venv/ENV/env.bak/venv.bak/
# Spyder project settings.spyderproject.spyproject
# Rope project settings.ropeproject
# mkdocs documentation/site
# mypy.mypy_cache/.dmypy.jsondmypy.json
# Pyre type checker.pyre/
# pytype static type analyzer.pytype/
# Cython debug symbolscython_debug/
# PyCharm# JetBrains specific template is maintained in a separate JetBrains.gitignore that can# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore# and can be added to the global gitignore or merged into this file. For a more nuclear# option (not recommended) you can uncomment the following to ignore the entire idea folder..idea/
# Logslogs*.lognpm-debug.log*yarn-debug.log*yarn-error.log*lerna-debug.log*.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime datapids*.pid*.seed*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCoverlib-cov
# Coverage directory used by tools like istanbulcoverage*.lcov
# nyc test coverage.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files).grunt
# Bower dependency directory (https://bower.io/)bower_components
# node-waf configuration.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)build/Release
# Dependency directoriesnode_modules/jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)web_modules/
# TypeScript cache*.tsbuildinfo
# Optional npm cache directory.npm
# Optional eslint cache.eslintcache
# Optional stylelint cache.stylelintcache
# Microbundle cache.rpt2_cache/.rts2_cache_cjs/.rts2_cache_es/.rts2_cache_umd/
# Optional REPL history.node_repl_history
# Output of 'npm pack'*.tgz
# Yarn Integrity file.yarn-integrity
# dotenv environment variable files.env.env.development.local.env.test.local.env.production.local.env.local
# parcel-bundler cache (https://parceljs.org/).cache.parcel-cache
# Next.js build output.nextout
# Nuxt.js build / generate output.nuxtdist
# Gatsby files.cache/# Comment in the public line in if your project uses Gatsby and not Next.js# https://nextjs.org/blog/next-9-1#public-directory-support# public
# vuepress build output.vuepress/dist
# vuepress v2.x temp and cache directory.temp.cache
# Docusaurus cache and generated files.docusaurus
# Serverless directories.serverless/
# FuseBox cache.fusebox/
# DynamoDB Local files.dynamodb/
# TernJS port file.tern-port
# Stores VSCode versions used for testing VSCode extensions.vscode-test
# yarn v2.yarn/cache.yarn/unplugged.yarn/build-state.yml.yarn/install-state.gz.pnp.*
# cypress artifactscypress/videoscypress/screenshots.vscode/settings.json1engine-strict=true123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314# Ignore files for PNPM, NPM and YARNpnpm-lock.yamlpackage-lock.jsonyarn.lock
# Copy of .gitignore.DS_Storenode_modules/build/.svelte-kit/package.env.env.*!.env.examplevite.config.js.timestamp-*vite.config.ts.timestamp-*# Byte-compiled / optimized / DLL files__pycache__/*.py[cod]*$py.class
# C extensions*.so
# Distribution / packaging.Pythonbuild/develop-eggs/dist/downloads/eggs/.eggs/lib64/parts/sdist/var/wheels/share/python-wheels/*.egg-info/.installed.cfg*.eggMANIFEST
# PyInstaller# Usually these files are written by a python script from a template# before PyInstaller builds the exe, so as to inject date/other infos into it.*.manifest*.spec
# Installer logspip-log.txtpip-delete-this-directory.txt
# Unit test / coverage reportshtmlcov/.tox/.nox/.coverage.coverage.*.cachenosetests.xmlcoverage.xml*.cover*.py,cover.hypothesis/.pytest_cache/cover/
# Translations*.mo*.pot
# Django stuff:*.loglocal_settings.pydb.sqlite3db.sqlite3-journal
# Flask stuff:instance/.webassets-cache
# Scrapy stuff:.scrapy
# Sphinx documentationdocs/_build/
# PyBuilder.pybuilder/target/
# Jupyter Notebook.ipynb_checkpoints
# IPythonprofile_default/ipython_config.py
# pyenv# For a library or package, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# .python-version
# pipenv# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.# However, in case of collaboration, if having platform-specific dependencies or dependencies# having no cross-platform support, pipenv may install dependencies that don't work, or not# install all needed dependencies.#Pipfile.lock
# poetry# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.# This is especially recommended for binary packages to ensure reproducibility, and is more# commonly ignored for libraries.# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control#poetry.lock
# pdm# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.#pdm.lock# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it# in version control.# https://pdm.fming.dev/#use-with-ide.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm__pypackages__/
# Celery stuffcelerybeat-schedulecelerybeat.pid
# SageMath parsed files*.sage.py
# Environments.env.venvenv/venv/ENV/env.bak/venv.bak/
# Spyder project settings.spyderproject.spyproject
# Rope project settings.ropeproject
# mkdocs documentation/site
# mypy.mypy_cache/.dmypy.jsondmypy.json
# Pyre type checker.pyre/
# pytype static type analyzer.pytype/
# Cython debug symbolscython_debug/
# PyCharm# JetBrains specific template is maintained in a separate JetBrains.gitignore that can# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore# and can be added to the global gitignore or merged into this file. For a more nuclear# option (not recommended) you can uncomment the following to ignore the entire idea folder..idea/
# Logslogs*.lognpm-debug.log*yarn-debug.log*yarn-error.log*lerna-debug.log*.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime datapids*.pid*.seed*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCoverlib-cov
# Coverage directory used by tools like istanbulcoverage*.lcov
# nyc test coverage.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files).grunt
# Bower dependency directory (https://bower.io/)bower_components
# node-waf configuration.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)build/Release
# Dependency directoriesnode_modules/jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)web_modules/
# TypeScript cache*.tsbuildinfo
# Optional npm cache directory.npm
# Optional eslint cache.eslintcache
# Optional stylelint cache.stylelintcache
# Microbundle cache.rpt2_cache/.rts2_cache_cjs/.rts2_cache_es/.rts2_cache_umd/
# Optional REPL history.node_repl_history
# Output of 'npm pack'*.tgz
# Yarn Integrity file.yarn-integrity
# dotenv environment variable files.env.env.development.local.env.test.local.env.production.local.env.local
# parcel-bundler cache (https://parceljs.org/).cache.parcel-cache
# Next.js build output.nextout
# Nuxt.js build / generate output.nuxtdist
# Gatsby files.cache/# Comment in the public line in if your project uses Gatsby and not Next.js# https://nextjs.org/blog/next-9-1#public-directory-support# public
# vuepress build output.vuepress/dist
# vuepress v2.x temp and cache directory.temp.cache
# Docusaurus cache and generated files.docusaurus
# Serverless directories.serverless/
# FuseBox cache.fusebox/
# DynamoDB Local files.dynamodb/
# TernJS port file.tern-port
# Stores VSCode versions used for testing VSCode extensions.vscode-test
# yarn v2.yarn/cache.yarn/unplugged.yarn/build-state.yml.yarn/install-state.gz.pnp.*
# cypress artifactscypress/videoscypress/screenshots
/static/*12345678910{ "useTabs": true, "singleQuote": true, "trailingComma": "none", "printWidth": 100, "plugins": ["prettier-plugin-svelte"], "pluginSearchDirs": ["."], "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }], "endOfLine": "lf"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899# Contributor Covenant Code of Conduct
## Our Pledge
As members, contributors, and leaders of this community, we pledge to make participation in our project a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socioeconomic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
We are committed to creating and maintaining an open, respectful, and professional environment where positive contributions and meaningful discussions can flourish. By participating in this project, you agree to uphold these values and align your behavior to the standards outlined in this Code of Conduct.
## Why These Standards Are Important
Projects rely on a community of volunteers dedicating their time, expertise, and effort toward a shared goal. These projects are inherently collaborative but also fragile, as the success of the project depends on the goodwill, energy, and productivity of those involved.
Maintaining a positive and respectful environment is essential to safeguarding the integrity of this project and protecting contributors' efforts. Behavior that disrupts this atmosphere—whether through hostility, entitlement, or unprofessional conduct—can severely harm the morale and productivity of the community. **Strict enforcement of these standards ensures a safe and supportive space for meaningful collaboration.**
This is a community where **respect and professionalism are mandatory.** Violations of these standards will result in **zero tolerance** and immediate enforcement to prevent disruption and ensure the well-being of all participants.
## Our Standards
Examples of behavior that contribute to a positive and professional community include:
- **Respecting others.** Be considerate, listen actively, and engage with empathy toward others' viewpoints and experiences.- **Constructive feedback.** Provide actionable, thoughtful, and respectful feedback that helps improve the project and encourages collaboration. Avoid unproductive negativity or hypercriticism.- **Recognizing volunteer contributions.** Appreciate that contributors dedicate their free time and resources selflessly. Approach them with gratitude and patience.- **Focusing on shared goals.** Collaborate in ways that prioritize the health, success, and sustainability of the community over individual agendas.
Examples of unacceptable behavior include:
- The use of discriminatory, demeaning, or sexualized language or behavior.- Personal attacks, derogatory comments, trolling, or inflammatory political or ideological arguments.- Harassment, intimidation, or any behavior intended to create a hostile, uncomfortable, or unsafe environment.- Publishing others' private information (e.g., physical or email addresses) without explicit permission.- **Entitlement, demand, or aggression toward contributors.** Volunteers are under no obligation to provide immediate or personalized support. Rude or dismissive behavior will not be tolerated.- **Unproductive or destructive behavior.** This includes venting frustration as hostility ("tantrums"), hypercriticism, attention-seeking negativity, or anything that distracts from the project's goals.- **Spamming and promotional exploitation.** Sharing irrelevant product promotions or self-promotion in the community is not allowed unless it directly contributes value to the discussion.
### Feedback and Community Engagement
- **Constructive feedback is encouraged, but hostile or entitled behavior will result in immediate action.** If you disagree with elements of the project, we encourage you to offer meaningful improvements or fork the project if necessary. Healthy discussions and technical disagreements are welcome only when handled with professionalism.- **Respect contributors' time and efforts.** No one is entitled to personalized or on-demand assistance. This is a community built on collaboration and shared effort; demanding or demeaning behavior undermines that trust and will not be allowed.
### Zero Tolerance: No Warnings, Immediate Action
This community operates under a **zero-tolerance policy.** Any behavior deemed unacceptable under this Code of Conduct will result in **immediate enforcement, without prior warning.**
We employ this approach to ensure that unproductive or disruptive behavior does not escalate further or cause unnecessary harm to other contributors. The standards are clear, and violations of any kind—whether mild or severe—will be addressed decisively to protect the community.
## Enforcement Responsibilities
Community leaders are responsible for upholding and enforcing these standards. They are empowered to take **immediate and appropriate action** to address any behaviors they deem unacceptable under this Code of Conduct. These actions are taken with the goal of protecting the community and preserving its safe, positive, and productive environment.
## Scope
This Code of Conduct applies to all community spaces, including forums, repositories, social media accounts, and in-person events. It also applies when an individual represents the community in public settings, such as conferences or official communications.
Additionally, any behavior outside of these defined spaces that negatively impacts the community or its members may fall within the scope of this Code of Conduct.
## Reporting Violations
Instances of unacceptable behavior can be reported to the leadership team at **hello@openwebui.com**. Reports will be handled promptly, confidentially, and with consideration for the safety and well-being of the reporter.
All community leaders are required to uphold confidentiality and impartiality when addressing reports of violations.
## Enforcement Guidelines
### Ban
**Community Impact**: Community leaders will issue a ban to any participant whose behavior is deemed unacceptable according to this Code of Conduct. Bans are enforced immediately and without prior notice.
A ban may be temporary or permanent, depending on the severity of the violation. This includes—but is not limited to—behavior such as:
- Harassment or abusive behavior toward contributors.- Persistent negativity or hostility that disrupts the collaborative environment.- Disrespectful, demanding, or aggressive interactions with others.- Attempts to cause harm or sabotage the community.
**Consequence**: A banned individual is immediately removed from access to all community spaces, communication channels, and events. Community leaders reserve the right to enforce either a time-limited suspension or a permanent ban based on the specific circumstances of the violation.
This approach ensures that disruptive behaviors are addressed swiftly and decisively in order to maintain the integrity and productivity of the community.
## Why Zero Tolerance Is Necessary
Projects thrive on collaboration, goodwill, and mutual respect. Toxic behaviors—such as entitlement, hostility, or persistent negativity—threaten not just individual contributors but the health of the project as a whole. Allowing such behaviors to persist robs contributors of their time, energy, and enthusiasm for the work they do.
By enforcing a zero-tolerance policy, we ensure that the community remains a safe, welcoming space for all participants. These measures are not about harshness—they are about protecting contributors and fostering a productive environment where innovation can thrive.
Our expectations are clear, and our enforcement reflects our commitment to this project's long-term success.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.1234567# Open WebUI Contributor License Agreement
By submitting my contributions to Open WebUI, I grant Open WebUI full freedom to use my work in any way they choose, under any terms they like, both now and in the future. This approach helps ensure the project remains unified, flexible, and easy to maintain, while empowering Open WebUI to respond quickly to the needs of its users and the wider community.
Taking part in this process means my work can be seamlessly integrated and combined with others, ensuring longevity and adaptability for everyone who benefits from the Open WebUI project. This collaborative approach strengthens the project’s future and helps guarantee that improvements can always be shared and distributed in the most effective way possible.
**_To the fullest extent permitted by law, my contributions are provided on an “as is” basis, with no warranties or guarantees of any kind, and I disclaim any liability for any issues or damages arising from their use or incorporation into the project, regardless of the type of legal claim._**123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194# syntax=docker/dockerfile:1# Initialize device type args# use build args in the docker build command with --build-arg="BUILDARG=true"ARG USE_CUDA=falseARG USE_OLLAMA=falseARG USE_SLIM=falseARG USE_PERMISSION_HARDENING=false# Tested with cu117 for CUDA 11 and cu121 for CUDA 12 (default)ARG USE_CUDA_VER=cu128# any sentence transformer model; models to use can be found at https://huggingface.co/models?library=sentence-transformers# Leaderboard: https://huggingface.co/spaces/mteb/leaderboard # for better performance and multilangauge support use "intfloat/multilingual-e5-large" (~2.5GB) or "intfloat/multilingual-e5-base" (~1.5GB)# IMPORTANT: If you change the embedding model (sentence-transformers/all-MiniLM-L6-v2) and vice versa, you aren't able to use RAG Chat with your previous documents loaded in the WebUI! You need to re-embed them.ARG USE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2ARG USE_RERANKING_MODEL=""
# Tiktoken encoding name; models to use can be found at https://huggingface.co/models?library=tiktokenARG USE_TIKTOKEN_ENCODING_NAME="cl100k_base"
ARG BUILD_HASH=dev-build# Override at your own risk - non-root configurations are untestedARG UID=0ARG GID=0
######## WebUI frontend ########FROM --platform=$BUILDPLATFORM node:22-alpine3.20 AS buildARG BUILD_HASH
# Set Node.js options (heap limit Allocation failed - JavaScript heap out of memory)# ENV NODE_OPTIONS="--max-old-space-size=4096"
WORKDIR /app
# to store git revision in buildRUN apk add --no-cache git
COPY package.json package-lock.json ./RUN npm ci --force
COPY . .ENV APP_BUILD_HASH=${BUILD_HASH}RUN npm run build
######## WebUI backend ########FROM python:3.11-slim-bookworm AS base
# Use argsARG USE_CUDAARG USE_OLLAMAARG USE_CUDA_VERARG USE_SLIMARG USE_PERMISSION_HARDENINGARG USE_EMBEDDING_MODELARG USE_RERANKING_MODELARG UIDARG GID
# Python settingsENV PYTHONUNBUFFERED=1
## Basis ##ENV ENV=prod \ PORT=8080 \ # pass build args to the build USE_OLLAMA_DOCKER=${USE_OLLAMA} \ USE_CUDA_DOCKER=${USE_CUDA} \ USE_SLIM_DOCKER=${USE_SLIM} \ USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \ USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL} \ USE_RERANKING_MODEL_DOCKER=${USE_RERANKING_MODEL}
## Basis URL Config ##ENV OLLAMA_BASE_URL="/ollama" \ OPENAI_API_BASE_URL=""
## API Key and Security Config ##ENV OPENAI_API_KEY="" \ WEBUI_SECRET_KEY="" \ SCARF_NO_ANALYTICS=true \ DO_NOT_TRACK=true \ ANONYMIZED_TELEMETRY=false
#### Other models ########################################################### whisper TTS model settings ##ENV WHISPER_MODEL="base" \ WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
## RAG Embedding model settings ##ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \ RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \ SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
## Tiktoken model settings ##ENV TIKTOKEN_ENCODING_NAME="cl100k_base" \ TIKTOKEN_CACHE_DIR="/app/backend/data/cache/tiktoken"
## Hugging Face download cache ##ENV HF_HOME="/app/backend/data/cache/embedding/models"
## Torch Extensions ### ENV TORCH_EXTENSIONS_DIR="/.cache/torch_extensions"
#### Other models ##########################################################
WORKDIR /app/backend
ENV HOME=/root# Create user and group if not rootRUN if [ $UID -ne 0 ]; then \ if [ $GID -ne 0 ]; then \ addgroup --gid $GID app; \ fi; \ adduser --uid $UID --gid $GID --home $HOME --disabled-password --no-create-home app; \ fi
RUN mkdir -p $HOME/.cache/chromaRUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
# Make sure the user has access to the app and root directoryRUN chown -R $UID:$GID /app $HOME
# Install common system dependenciesRUN apt-get update && \ apt-get install -y --no-install-recommends \ git build-essential pandoc gcc netcat-openbsd curl jq \ python3-dev \ ffmpeg libsm6 libxext6 \ && rm -rf /var/lib/apt/lists/*
# install python dependenciesCOPY --chown=$UID:$GID ./backend/requirements.txt ./requirements.txt
RUN pip3 install --no-cache-dir uv && \ if [ "$USE_CUDA" = "true" ]; then \ # If you use CUDA the whisper and embedding model will be downloaded on first use pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \ uv pip install --system -r requirements.txt --no-cache-dir && \ python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \ python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \ python -c "import os; import tiktoken; tiktoken.get_encoding(os.environ['TIKTOKEN_ENCODING_NAME'])"; \ else \ pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \ uv pip install --system -r requirements.txt --no-cache-dir && \ if [ "$USE_SLIM" != "true" ]; then \ python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \ python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \ python -c "import os; import tiktoken; tiktoken.get_encoding(os.environ['TIKTOKEN_ENCODING_NAME'])"; \ fi; \ fi; \ mkdir -p /app/backend/data && chown -R $UID:$GID /app/backend/data/ && \ rm -rf /var/lib/apt/lists/*;
# Install Ollama if requestedRUN if [ "$USE_OLLAMA" = "true" ]; then \ date +%s > /tmp/ollama_build_hash && \ echo "Cache broken at timestamp: `cat /tmp/ollama_build_hash`" && \ curl -fsSL https://ollama.com/install.sh | sh && \ rm -rf /var/lib/apt/lists/*; \ fi
# copy embedding weight from build# RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2# COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
# copy built frontend filesCOPY --chown=$UID:$GID --from=build /app/build /app/buildCOPY --chown=$UID:$GID --from=build /app/CHANGELOG.md /app/CHANGELOG.mdCOPY --chown=$UID:$GID --from=build /app/package.json /app/package.json
# copy backend filesCOPY --chown=$UID:$GID ./backend .
EXPOSE 8080
HEALTHCHECK CMD curl --silent --fail http://localhost:${PORT:-8080}/health | jq -ne 'input.status == true' || exit 1
# Minimal, atomic permission hardening for OpenShift (arbitrary UID):# - Group 0 owns /app and /root# - Directories are group-writable and have SGID so new files inherit GID 0RUN if [ "$USE_PERMISSION_HARDENING" = "true" ]; then \ set -eux; \ chgrp -R 0 /app /root || true; \ chmod -R g+rwX /app /root || true; \ find /app -type d -exec chmod g+s {} + || true; \ find /root -type d -exec chmod g+s {} + || true; \ fi
USER $UID:$GID
ARG BUILD_HASHENV WEBUI_BUILD_VERSION=${BUILD_HASH}ENV DOCKER=true
CMD [ "bash", "start.sh"]123456789101112131415161718192021222324252627282930313233Copyright (c) 2023- Open WebUI Inc. [Created by Timothy Jaeryang Baek]All rights reserved.
Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
4. Notwithstanding any other provision of this License, and as a material condition of the rights granted herein, licensees are strictly prohibited from altering, removing, obscuring, or replacing any "Open WebUI" branding, including but not limited to the name, logo, or any visual, textual, or symbolic identifiers that distinguish the software and its interfaces, in any deployment or distribution, regardless of the number of users, except as explicitly set forth in Clauses 5 and 6 below.
5. The branding restriction enumerated in Clause 4 shall not apply in the following limited circumstances: (i) deployments or distributions where the total number of end users (defined as individual natural persons with direct access to the application) does not exceed fifty (50) within any rolling thirty (30) day period; (ii) cases in which the licensee is an official contributor to the codebase—with a substantive code change successfully merged into the main branch of the official codebase maintained by the copyright holder—who has obtained specific prior written permission for branding adjustment from the copyright holder; or (iii) where the licensee has obtained a duly executed enterprise license expressly permitting such modification. For all other cases, any removal or alteration of the "Open WebUI" branding shall constitute a material breach of license.
6. All code, modifications, or derivative works incorporated into this project prior to the incorporation of this branding clause remain licensed under the BSD 3-Clause License, and prior contributors retain all BSD-3 rights therein; if any such contributor requests the removal of their BSD-3-licensed code, the copyright holder will do so, and any replacement code will be licensed under the project's primary license then in effect. By contributing after this clause's adoption, you agree to the project's Contributor License Agreement (CLA) and to these updated terms for all new contributions.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253All code and materials created before commit `60d84a3aae9802339705826e9095e272e3c83623` are subject to the following copyright and license:
Copyright (c) 2023-2025 Timothy Jaeryang BaekAll rights reserved.
Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
All code and materials created before commit `a76068d69cd59568b920dfab85dc573dbbb8f131` are subject to the following copyright and license:
MIT License
Copyright (c) 2023 Timothy Jaeryang Baek
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.1234567891011# Open WebUI Multi-License Notice
This repository contains code governed by multiple licenses based on the date and origin of contribution:
1. All code committed prior to commit a76068d69cd59568b920dfab85dc573dbbb8f131 is licensed under the MIT License (see LICENSE_HISTORY).
2. All code committed from commit a76068d69cd59568b920dfab85dc573dbbb8f131 up to and including commit 60d84a3aae9802339705826e9095e272e3c83623 is licensed under the BSD 3-Clause License (see LICENSE_HISTORY).
3. All code contributed or modified after commit 60d84a3aae9802339705826e9095e272e3c83623 is licensed under the Open WebUI License (see LICENSE).
For details on which commits are covered by which license, refer to LICENSE_HISTORY.123456789101112131415161718192021222324252627282930313233
ifneq ($(shell which docker-compose 2>/dev/null),) DOCKER_COMPOSE := docker-composeelse DOCKER_COMPOSE := docker composeendif
install: $(DOCKER_COMPOSE) up -d
remove: @chmod +x confirm_remove.sh @./confirm_remove.sh
start: $(DOCKER_COMPOSE) startstartAndBuild: $(DOCKER_COMPOSE) up -d --build
stop: $(DOCKER_COMPOSE) stop
update: # Calls the LLM update script chmod +x update_ollama_models.sh @./update_ollama_models.sh @git pull $(DOCKER_COMPOSE) down # Make sure the ollama-webui container is stopped before rebuilding @docker stop open-webui || true $(DOCKER_COMPOSE) up --build -d $(DOCKER_COMPOSE) start
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245---title: Open WebUIemoji: 🐳colorFrom: purplecolorTo: graysdk: dockerapp_port: 8080---# Open WebUI 👋
[](https://discord.gg/5rJgQTnV4s)[](https://github.com/sponsors/tjbck)
**Open WebUI is an [extensible](https://docs.openwebui.com/features/plugin/), feature-rich, and user-friendly self-hosted AI platform designed to operate entirely offline.** It supports various LLM runners like **Ollama** and **OpenAI-compatible APIs**, with **built-in inference engine** for RAG, making it a **powerful AI deployment solution**.
Passionate about open-source AI? [Join our team →](https://careers.openwebui.com/)

> [!TIP] > **Looking for an [Enterprise Plan](https://docs.openwebui.com/enterprise)?** – **[Speak with Our Sales Team Today!](https://docs.openwebui.com/enterprise)**>> Get **enhanced capabilities**, including **custom theming and branding**, **Service Level Agreement (SLA) support**, **Long-Term Support (LTS) versions**, and **more!**
For more information, be sure to check out our [Open WebUI Documentation](https://docs.openwebui.com/).
## Key Features of Open WebUI ⭐
- 🚀 **Effortless Setup**: Install seamlessly using Docker or Kubernetes (kubectl, kustomize or helm) for a hassle-free experience with support for both `:ollama` and `:cuda` tagged images.
- 🤝 **Ollama/OpenAI API Integration**: Effortlessly integrate OpenAI-compatible APIs for versatile conversations alongside Ollama models. Customize the OpenAI API URL to link with **LMStudio, GroqCloud, Mistral, OpenRouter, and more**.
- 🛡️ **Granular Permissions and User Groups**: By allowing administrators to create detailed user roles and permissions, we ensure a secure user environment. This granularity not only enhances security but also allows for customized user experiences, fostering a sense of ownership and responsibility amongst users.
- 📱 **Responsive Design**: Enjoy a seamless experience across Desktop PC, Laptop, and Mobile devices.
- 📱 **Progressive Web App (PWA) for Mobile**: Enjoy a native app-like experience on your mobile device with our PWA, providing offline access on localhost and a seamless user interface.
- ✒️🔢 **Full Markdown and LaTeX Support**: Elevate your LLM experience with comprehensive Markdown and LaTeX capabilities for enriched interaction.
- 🎤📹 **Hands-Free Voice/Video Call**: Experience seamless communication with integrated hands-free voice and video call features using multiple Speech-to-Text providers (Local Whisper, OpenAI, Deepgram, Azure) and Text-to-Speech engines (Azure, ElevenLabs, OpenAI, Transformers, WebAPI), allowing for dynamic and interactive chat environments.
- 🛠️ **Model Builder**: Easily create Ollama models via the Web UI. Create and add custom characters/agents, customize chat elements, and import models effortlessly through [Open WebUI Community](https://openwebui.com/) integration.
- 🐍 **Native Python Function Calling Tool**: Enhance your LLMs with built-in code editor support in the tools workspace. Bring Your Own Function (BYOF) by simply adding your pure Python functions, enabling seamless integration with LLMs.
- 💾 **Persistent Artifact Storage**: Built-in key-value storage API for artifacts, enabling features like journals, trackers, leaderboards, and collaborative tools with both personal and shared data scopes across sessions.
- 📚 **Local RAG Integration**: Dive into the future of chat interactions with groundbreaking Retrieval Augmented Generation (RAG) support using your choice of 9 vector databases and multiple content extraction engines (Tika, Docling, Document Intelligence, Mistral OCR, External loaders). Load documents directly into chat or add files to your document library, effortlessly accessing them using the `#` command before a query.
- 🔍 **Web Search for RAG**: Perform web searches using 15+ providers including `SearXNG`, `Google PSE`, `Brave Search`, `Kagi`, `Mojeek`, `Tavily`, `Perplexity`, `serpstack`, `serper`, `Serply`, `DuckDuckGo`, `SearchApi`, `SerpApi`, `Bing`, `Jina`, `Exa`, `Sougou`, `Azure AI Search`, and `Ollama Cloud`, injecting results directly into your chat experience.
- 🌐 **Web Browsing Capability**: Seamlessly integrate websites into your chat experience using the `#` command followed by a URL. This feature allows you to incorporate web content directly into your conversations, enhancing the richness and depth of your interactions.
- 🎨 **Image Generation & Editing Integration**: Create and edit images using multiple engines including OpenAI's DALL-E, Gemini, ComfyUI (local), and AUTOMATIC1111 (local), with support for both generation and prompt-based editing workflows.
- ⚙️ **Many Models Conversations**: Effortlessly engage with various models simultaneously, harnessing their unique strengths for optimal responses. Enhance your experience by leveraging a diverse set of models in parallel.
- 🔐 **Role-Based Access Control (RBAC)**: Ensure secure access with restricted permissions; only authorized individuals can access your Ollama, and exclusive model creation/pulling rights are reserved for administrators.
- 🗄️ **Flexible Database & Storage Options**: Choose from SQLite (with optional encryption), PostgreSQL, or configure cloud storage backends (S3, Google Cloud Storage, Azure Blob Storage) for scalable deployments.
- 🔍 **Advanced Vector Database Support**: Select from 9 vector database options including ChromaDB, PGVector, Qdrant, Milvus, Elasticsearch, OpenSearch, Pinecone, S3Vector, and Oracle 23ai for optimal RAG performance.
- 🔐 **Enterprise Authentication**: Full support for LDAP/Active Directory integration, SCIM 2.0 automated provisioning, and SSO via trusted headers alongside OAuth providers. Enterprise-grade user and group provisioning through SCIM 2.0 protocol, enabling seamless integration with identity providers like Okta, Azure AD, and Google Workspace for automated user lifecycle management.
- ☁️ **Cloud-Native Integration**: Native support for Google Drive and OneDrive/SharePoint file picking, enabling seamless document import from enterprise cloud storage.
- 📊 **Production Observability**: Built-in OpenTelemetry support for traces, metrics, and logs, enabling comprehensive monitoring with your existing observability stack.
- ⚖️ **Horizontal Scalability**: Redis-backed session management and WebSocket support for multi-worker and multi-node deployments behind load balancers.
- 🌐🌍 **Multilingual Support**: Experience Open WebUI in your preferred language with our internationalization (i18n) support. Join us in expanding our supported languages! We're actively seeking contributors!
- 🧩 **Pipelines, Open WebUI Plugin Support**: Seamlessly integrate custom logic and Python libraries into Open WebUI using [Pipelines Plugin Framework](https://github.com/open-webui/pipelines). Launch your Pipelines instance, set the OpenAI URL to the Pipelines URL, and explore endless possibilities. [Examples](https://github.com/open-webui/pipelines/tree/main/examples) include **Function Calling**, User **Rate Limiting** to control access, **Usage Monitoring** with tools like Langfuse, **Live Translation with LibreTranslate** for multilingual support, **Toxic Message Filtering** and much more.
- 🌟 **Continuous Updates**: We are committed to improving Open WebUI with regular updates, fixes, and new features.
Want to learn more about Open WebUI's features? Check out our [Open WebUI documentation](https://docs.openwebui.com/features) for a comprehensive overview!
---
We are incredibly grateful for the generous support of our sponsors. Their contributions help us to maintain and improve our project, ensuring we can continue to deliver quality work to our community. Thank you!
## How to Install 🚀
### Installation via Python pip 🐍
Open WebUI can be installed using pip, the Python package installer. Before proceeding, ensure you're using **Python 3.11** to avoid compatibility issues.
1. **Install Open WebUI**: Open your terminal and run the following command to install Open WebUI:
```bash pip install open-webui ```
2. **Running Open WebUI**: After installation, you can start Open WebUI by executing:
```bash open-webui serve ```
This will start the Open WebUI server, which you can access at [http://localhost:8080](http://localhost:8080)
### Quick Start with Docker 🐳
> [!NOTE] > Please note that for certain Docker environments, additional configurations might be needed. If you encounter any connection issues, our detailed guide on [Open WebUI Documentation](https://docs.openwebui.com/) is ready to assist you.
> [!WARNING]> When using Docker to install Open WebUI, make sure to include the `-v open-webui:/app/backend/data` in your Docker command. This step is crucial as it ensures your database is properly mounted and prevents any loss of data.
> [!TIP] > If you wish to utilize Open WebUI with Ollama included or CUDA acceleration, we recommend utilizing our official images tagged with either `:cuda` or `:ollama`. To enable CUDA, you must install the [Nvidia CUDA container toolkit](https://docs.nvidia.com/dgx/nvidia-container-runtime-upgrade/) on your Linux/WSL system.
### Installation with Default Configuration
- **If Ollama is on your computer**, use this command:
```bash docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main ```
- **If Ollama is on a Different Server**, use this command:
To connect to Ollama on another server, change the `OLLAMA_BASE_URL` to the server's URL:
```bash docker run -d -p 3000:8080 -e OLLAMA_BASE_URL=https://example.com -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main ```
- **To run Open WebUI with Nvidia GPU support**, use this command:
```bash docker run -d -p 3000:8080 --gpus all --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:cuda ```
### Installation for OpenAI API Usage Only
- **If you're only using OpenAI API**, use this command:
```bash docker run -d -p 3000:8080 -e OPENAI_API_KEY=your_secret_key -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main ```
### Installing Open WebUI with Bundled Ollama Support
This installation method uses a single container image that bundles Open WebUI with Ollama, allowing for a streamlined setup via a single command. Choose the appropriate command based on your hardware setup:
- **With GPU Support**: Utilize GPU resources by running the following command:
```bash docker run -d -p 3000:8080 --gpus=all -v ollama:/root/.ollama -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:ollama ```
- **For CPU Only**: If you're not using a GPU, use this command instead:
```bash docker run -d -p 3000:8080 -v ollama:/root/.ollama -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:ollama ```
Both commands facilitate a built-in, hassle-free installation of both Open WebUI and Ollama, ensuring that you can get everything up and running swiftly.
After installation, you can access Open WebUI at [http://localhost:3000](http://localhost:3000). Enjoy! 😄
### Other Installation Methods
We offer various installation alternatives, including non-Docker native installation methods, Docker Compose, Kustomize, and Helm. Visit our [Open WebUI Documentation](https://docs.openwebui.com/getting-started/) or join our [Discord community](https://discord.gg/5rJgQTnV4s) for comprehensive guidance.
Look at the [Local Development Guide](https://docs.openwebui.com/getting-started/advanced-topics/development) for instructions on setting up a local development environment.
### Troubleshooting
Encountering connection issues? Our [Open WebUI Documentation](https://docs.openwebui.com/troubleshooting/) has got you covered. For further assistance and to join our vibrant community, visit the [Open WebUI Discord](https://discord.gg/5rJgQTnV4s).
#### Open WebUI: Server Connection Error
If you're experiencing connection issues, it’s often due to the WebUI docker container not being able to reach the Ollama server at 127.0.0.1:11434 (host.docker.internal:11434) inside the container . Use the `--network=host` flag in your docker command to resolve this. Note that the port changes from 3000 to 8080, resulting in the link: `http://localhost:8080`.
**Example Docker Command**:
```bashdocker run -d --network=host -v open-webui:/app/backend/data -e OLLAMA_BASE_URL=http://127.0.0.1:11434 --name open-webui --restart always ghcr.io/open-webui/open-webui:main```
### Keeping Your Docker Installation Up-to-Date
Check our Updating Guide available in our [Open WebUI Documentation](https://docs.openwebui.com/getting-started/updating).
### Using the Dev Branch 🌙
> [!WARNING]> The `:dev` branch contains the latest unstable features and changes. Use it at your own risk as it may have bugs or incomplete features.
If you want to try out the latest bleeding-edge features and are okay with occasional instability, you can use the `:dev` tag like this:
```bashdocker run -d -p 3000:8080 -v open-webui:/app/backend/data --name open-webui --add-host=host.docker.internal:host-gateway --restart always ghcr.io/open-webui/open-webui:dev```
### Offline Mode
If you are running Open WebUI in an offline environment, you can set the `HF_HUB_OFFLINE` environment variable to `1` to prevent attempts to download models from the internet.
```bashexport HF_HUB_OFFLINE=1```
## What's Next? 🌟
Discover upcoming features on our roadmap in the [Open WebUI Documentation](https://docs.openwebui.com/roadmap/).
## License 📜
This project contains code under multiple licenses. The current codebase includes components licensed under the Open WebUI License with an additional requirement to preserve the "Open WebUI" branding, as well as prior contributions under their respective original licenses. For a detailed record of license changes and the applicable terms for each section of the code, please refer to [LICENSE_HISTORY](./LICENSE_HISTORY). For complete and updated licensing details, please see the [LICENSE](./LICENSE) and [LICENSE_HISTORY](./LICENSE_HISTORY) files.
## Support 💬
If you have any questions, suggestions, or need assistance, please open an issue or join our[Open WebUI Discord community](https://discord.gg/5rJgQTnV4s) to connect with us! 🤝
## Star History
<a href="https://star-history.com/#open-webui/open-webui&Date"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=open-webui/open-webui&type=Date&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=open-webui/open-webui&type=Date" /> <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=open-webui/open-webui&type=Date" /> </picture></a>
---
Created by [Timothy Jaeryang Baek](https://github.com/tjbck) - Let's make Open WebUI even more amazing together! 💪123456789101112131415161718192021222324252627282930313233343536# Open WebUI Troubleshooting Guide
## Understanding the Open WebUI Architecture
The Open WebUI system is designed to streamline interactions between the client (your browser) and the Ollama API. At the heart of this design is a backend reverse proxy, enhancing security and resolving CORS issues.
- **How it Works**: The Open WebUI is designed to interact with the Ollama API through a specific route. When a request is made from the WebUI to Ollama, it is not directly sent to the Ollama API. Initially, the request is sent to the Open WebUI backend via `/ollama` route. From there, the backend is responsible for forwarding the request to the Ollama API. This forwarding is accomplished by using the route specified in the `OLLAMA_BASE_URL` environment variable. Therefore, a request made to `/ollama` in the WebUI is effectively the same as making a request to `OLLAMA_BASE_URL` in the backend. For instance, a request to `/ollama/api/tags` in the WebUI is equivalent to `OLLAMA_BASE_URL/api/tags` in the backend.
- **Security Benefits**: This design prevents direct exposure of the Ollama API to the frontend, safeguarding against potential CORS (Cross-Origin Resource Sharing) issues and unauthorized access. Requiring authentication to access the Ollama API further enhances this security layer.
## Open WebUI: Server Connection Error
If you're experiencing connection issues, it’s often due to the WebUI docker container not being able to reach the Ollama server at 127.0.0.1:11434 (host.docker.internal:11434) inside the container . Use the `--network=host` flag in your docker command to resolve this. Note that the port changes from 3000 to 8080, resulting in the link: `http://localhost:8080`.
**Example Docker Command**:
```bashdocker run -d --network=host -v open-webui:/app/backend/data -e OLLAMA_BASE_URL=http://127.0.0.1:11434 --name open-webui --restart always ghcr.io/open-webui/open-webui:main```
### Error on Slow Responses for Ollama
Open WebUI has a default timeout of 5 minutes for Ollama to finish generating the response. If needed, this can be adjusted via the environment variable AIOHTTP_CLIENT_TIMEOUT, which sets the timeout in seconds.
### General Connection Errors
**Ensure Ollama Version is Up-to-Date**: Always start by checking that you have the latest version of Ollama. Visit [Ollama's official site](https://ollama.com/) for the latest updates.
**Troubleshooting Steps**:
1. **Verify Ollama URL Format**: - When running the Web UI container, ensure the `OLLAMA_BASE_URL` is correctly set. (e.g., `http://192.168.1.1:11434` for different host setups). - In the Open WebUI, navigate to "Settings" > "General". - Confirm that the Ollama Server URL is correctly set to `[OLLAMA URL]` (e.g., `http://localhost:11434`).
By following these enhanced troubleshooting steps, connection issues should be effectively resolved. For further assistance or queries, feel free to reach out to us on our community Discord.1234567891011121314__pycache__.env_olduploads.ipynb_checkpoints*.db_test!/data/data/*!/data/litellm/data/litellm/*!data/litellm/config.yaml
!data/config.json123456789101112__pycache__.env_olduploads.ipynb_checkpoints*.db_testPipfile!/data/data/*/open_webui/data/*.webui_secret_key123export CORS_ALLOW_ORIGIN="http://localhost:5173;http://localhost:8080"PORT="${PORT:-8080}"uvicorn open_webui.main:app --port $PORT --host 0.0.0.0 --forwarded-allow-ips '*' --reload123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import base64import osimport randomfrom pathlib import Path
import typerimport uvicornfrom typing import Optionalfrom typing_extensions import Annotated
app = typer.Typer()
KEY_FILE = Path.cwd() / ".webui_secret_key"
def version_callback(value: bool): if value: from open_webui.env import VERSION
typer.echo(f"Open WebUI version: {VERSION}") raise typer.Exit()
@app.command()def main( version: Annotated[ Optional[bool], typer.Option("--version", callback=version_callback) ] = None,): pass
@app.command()def serve( host: str = "0.0.0.0", port: int = 8080,): os.environ["FROM_INIT_PY"] = "true" if os.getenv("WEBUI_SECRET_KEY") is None: typer.echo( "Loading WEBUI_SECRET_KEY from file, not provided as an environment variable." ) if not KEY_FILE.exists(): typer.echo(f"Generating a new secret key and saving it to {KEY_FILE}") KEY_FILE.write_bytes(base64.b64encode(random.randbytes(12))) typer.echo(f"Loading WEBUI_SECRET_KEY from {KEY_FILE}") os.environ["WEBUI_SECRET_KEY"] = KEY_FILE.read_text()
if os.getenv("USE_CUDA_DOCKER", "false") == "true": typer.echo( "CUDA is enabled, appending LD_LIBRARY_PATH to include torch/cudnn & cublas libraries." ) LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH", "").split(":") os.environ["LD_LIBRARY_PATH"] = ":".join( LD_LIBRARY_PATH + [ "/usr/local/lib/python3.11/site-packages/torch/lib", "/usr/local/lib/python3.11/site-packages/nvidia/cudnn/lib", ] ) try: import torch
assert torch.cuda.is_available(), "CUDA not available" typer.echo("CUDA seems to be working") except Exception as e: typer.echo( "Error when testing CUDA but USE_CUDA_DOCKER is true. " "Resetting USE_CUDA_DOCKER to false and removing " f"LD_LIBRARY_PATH modifications: {e}" ) os.environ["USE_CUDA_DOCKER"] = "false" os.environ["LD_LIBRARY_PATH"] = ":".join(LD_LIBRARY_PATH)
import open_webui.main # we need set environment variables before importing main from open_webui.env import UVICORN_WORKERS # Import the workers setting
uvicorn.run( "open_webui.main:app", host=host, port=port, forwarded_allow_ips="*", workers=UVICORN_WORKERS, )
@app.command()def dev( host: str = "0.0.0.0", port: int = 8080, reload: bool = True,): uvicorn.run( "open_webui.main:app", host=host, port=port, reload=reload, forwarded_allow_ips="*", )
if __name__ == "__main__": app()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114# A generic, single database configuration.
[alembic]# path to migration scriptsscript_location = migrations
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s# Uncomment the line below if you want the files to be prepended with date and time# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
# sys.path path, will be prepended to sys.path if present.# defaults to the current working directory.prepend_sys_path = ..
# timezone to use when rendering the date within the migration file# as well as the filename.# If specified, requires the python>=3.9 or backports.zoneinfo library.# Any required deps can installed by adding `alembic[tz]` to the pip requirements# string value is passed to ZoneInfo()# leave blank for localtime# timezone =
# max length of characters to apply to the# "slug" field# truncate_slug_length = 40
# set to 'true' to run the environment during# the 'revision' command, regardless of autogenerate# revision_environment = false
# set to 'true' to allow .pyc and .pyo files without# a source .py file to be detected as revisions in the# versions/ directory# sourceless = false
# version location specification; This defaults# to migrations/versions. When using multiple version# directories, initial revisions must be specified with --version-path.# The path separator used here should be the separator specified by "version_path_separator" below.# version_locations = %(here)s/bar:%(here)s/bat:migrations/versions
# version path separator; As mentioned above, this is the character used to split# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.# Valid values for version_path_separator are:## version_path_separator = :# version_path_separator = ;# version_path_separator = spaceversion_path_separator = os # Use os.pathsep. Default configuration used for new projects.
# set to 'true' to search source files recursively# in each "version_locations" directory# new in Alembic version 1.10# recursive_version_locations = false
# the output encoding used when revision files# are written from script.py.mako# output_encoding = utf-8
# sqlalchemy.url = REPLACE_WITH_DATABASE_URL
[post_write_hooks]# post_write_hooks defines scripts or Python functions that are run# on newly generated revision scripts. See the documentation for further# detail and examples
# format using "black" - use the console_scripts runner, against the "black" entrypoint# hooks = black# black.type = console_scripts# black.entrypoint = black# black.options = -l 79 REVISION_SCRIPT_FILENAME
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary# hooks = ruff# ruff.type = exec# ruff.executable = %(here)s/.venv/bin/ruff# ruff.options = --fix REVISION_SCRIPT_FILENAME
# Logging configuration[loggers]keys = root,sqlalchemy,alembic
[handlers]keys = console
[formatters]keys = generic
[logger_root]level = WARNhandlers = consolequalname =
[logger_sqlalchemy]level = WARNhandlers =qualname = sqlalchemy.engine
[logger_alembic]level = INFOhandlers =qualname = alembic
[handler_console]class = StreamHandlerargs = (sys.stderr,)level = NOTSETformatter = generic
[formatter_generic]format = %(levelname)-5.5s [%(name)s] %(message)sdatefmt = %H:%M:%S123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126from enum import Enum
class MESSAGES(str, Enum): DEFAULT = lambda msg="": f"{msg if msg else ''}" MODEL_ADDED = lambda model="": f"The model '{model}' has been added successfully." MODEL_DELETED = ( lambda model="": f"The model '{model}' has been deleted successfully." )
class WEBHOOK_MESSAGES(str, Enum): DEFAULT = lambda msg="": f"{msg if msg else ''}" USER_SIGNUP = lambda username="": ( f"New user signed up: {username}" if username else "New user signed up" )
class ERROR_MESSAGES(str, Enum): def __str__(self) -> str: return super().__str__()
DEFAULT = ( lambda err="": f'{"Something went wrong :/" if err == "" else "[ERROR: " + str(err) + "]"}' ) ENV_VAR_NOT_FOUND = "Required environment variable not found. Terminating now." CREATE_USER_ERROR = "Oops! Something went wrong while creating your account. Please try again later. If the issue persists, contact support for assistance." DELETE_USER_ERROR = "Oops! Something went wrong. We encountered an issue while trying to delete the user. Please give it another shot." EMAIL_MISMATCH = "Uh-oh! This email does not match the email your provider is registered with. Please check your email and try again." EMAIL_TAKEN = "Uh-oh! This email is already registered. Sign in with your existing account or choose another email to start anew." USERNAME_TAKEN = ( "Uh-oh! This username is already registered. Please choose another username." ) PASSWORD_TOO_LONG = "Uh-oh! The password you entered is too long. Please make sure your password is less than 72 bytes long." COMMAND_TAKEN = "Uh-oh! This command is already registered. Please choose another command string." FILE_EXISTS = "Uh-oh! This file is already registered. Please choose another file."
ID_TAKEN = "Uh-oh! This id is already registered. Please choose another id string." MODEL_ID_TAKEN = "Uh-oh! This model id is already registered. Please choose another model id string." NAME_TAG_TAKEN = "Uh-oh! This name tag is already registered. Please choose another name tag string." MODEL_ID_TOO_LONG = "The model id is too long. Please make sure your model id is less than 256 characters long."
INVALID_TOKEN = ( "Your session has expired or the token is invalid. Please sign in again." ) INVALID_CRED = "The email or password provided is incorrect. Please check for typos and try logging in again." INVALID_EMAIL_FORMAT = "The email format you entered is invalid. Please double-check and make sure you're using a valid email address (e.g., yourname@example.com)." INCORRECT_PASSWORD = ( "The password provided is incorrect. Please check for typos and try again." ) INVALID_TRUSTED_HEADER = "Your provider has not provided a trusted header. Please contact your administrator for assistance."
EXISTING_USERS = "You can't turn off authentication because there are existing users. If you want to disable WEBUI_AUTH, make sure your web interface doesn't have any existing users and is a fresh installation."
UNAUTHORIZED = "401 Unauthorized" ACCESS_PROHIBITED = "You do not have permission to access this resource. Please contact your administrator for assistance." ACTION_PROHIBITED = ( "The requested action has been restricted as a security measure." )
FILE_NOT_SENT = "FILE_NOT_SENT" FILE_NOT_SUPPORTED = "Oops! It seems like the file format you're trying to upload is not supported. Please upload a file with a supported format and try again."
NOT_FOUND = "We could not find what you're looking for :/" USER_NOT_FOUND = "We could not find what you're looking for :/" API_KEY_NOT_FOUND = "Oops! It looks like there's a hiccup. The API key is missing. Please make sure to provide a valid API key to access this feature." API_KEY_NOT_ALLOWED = "Use of API key is not enabled in the environment."
MALICIOUS = "Unusual activities detected, please try again in a few minutes."
PANDOC_NOT_INSTALLED = "Pandoc is not installed on the server. Please contact your administrator for assistance." INCORRECT_FORMAT = ( lambda err="": f"Invalid format. Please use the correct format{err}" ) RATE_LIMIT_EXCEEDED = "API rate limit exceeded"
MODEL_NOT_FOUND = lambda name="": f"Model '{name}' was not found" OPENAI_NOT_FOUND = lambda name="": "OpenAI API was not found" OLLAMA_NOT_FOUND = "WebUI could not connect to Ollama" CREATE_API_KEY_ERROR = "Oops! Something went wrong while creating your API key. Please try again later. If the issue persists, contact support for assistance." API_KEY_CREATION_NOT_ALLOWED = "API key creation is not allowed in the environment."
EMPTY_CONTENT = "The content provided is empty. Please ensure that there is text or data present before proceeding."
DB_NOT_SQLITE = "This feature is only available when running with SQLite databases."
INVALID_URL = ( "Oops! The URL you provided is invalid. Please double-check and try again." )
WEB_SEARCH_ERROR = ( lambda err="": f"{err if err else 'Oops! Something went wrong while searching the web.'}" )
OLLAMA_API_DISABLED = ( "The Ollama API is disabled. Please enable it to use this feature." )
FILE_TOO_LARGE = ( lambda size="": f"Oops! The file you're trying to upload is too large. Please upload a file that is less than {size}." )
DUPLICATE_CONTENT = ( "Duplicate content detected. Please provide unique content to proceed." ) FILE_NOT_PROCESSED = "Extracted content is not available for this file. Please ensure that the file is processed before proceeding."
INVALID_PASSWORD = lambda err="": ( err if err else "The password does not meet the required validation criteria." )
class TASKS(str, Enum): def __str__(self) -> str: return super().__str__()
DEFAULT = lambda task="": f"{task if task else 'generation'}" TITLE_GENERATION = "title_generation" FOLLOW_UP_GENERATION = "follow_up_generation" TAGS_GENERATION = "tags_generation" EMOJI_GENERATION = "emoji_generation" QUERY_GENERATION = "query_generation" IMAGE_PROMPT_GENERATION = "image_prompt_generation" AUTOCOMPLETE_GENERATION = "autocomplete_generation" FUNCTION_CALLING = "function_calling" MOA_RESPONSE_GENERATION = "moa_response_generation"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877import importlib.metadataimport jsonimport loggingimport osimport pkgutilimport sysimport shutilfrom uuid import uuid4from pathlib import Pathfrom cryptography.hazmat.primitives import serializationimport re
import markdownfrom bs4 import BeautifulSoupfrom open_webui.constants import ERROR_MESSAGES
##################################### Load .env file####################################
# Use .resolve() to get the canonical path, removing any '..' or '.' componentsENV_FILE_PATH = Path(__file__).resolve()
# OPEN_WEBUI_DIR should be the directory where env.py resides (open_webui/)OPEN_WEBUI_DIR = ENV_FILE_PATH.parent
# BACKEND_DIR is the parent of OPEN_WEBUI_DIR (backend/)BACKEND_DIR = OPEN_WEBUI_DIR.parent
# BASE_DIR is the parent of BACKEND_DIR (open-webui-dev/)BASE_DIR = BACKEND_DIR.parent
try: from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv(str(BASE_DIR / ".env")))except ImportError: print("dotenv not installed, skipping...")
DOCKER = os.environ.get("DOCKER", "False").lower() == "true"
# device type embedding models - "cpu" (default), "cuda" (nvidia gpu required) or "mps" (apple silicon) - choosing this right can lead to better performanceUSE_CUDA = os.environ.get("USE_CUDA_DOCKER", "false")
if USE_CUDA.lower() == "true": try: import torch
assert torch.cuda.is_available(), "CUDA not available" DEVICE_TYPE = "cuda" except Exception as e: cuda_error = ( "Error when testing CUDA but USE_CUDA_DOCKER is true. " f"Resetting USE_CUDA_DOCKER to false: {e}" ) os.environ["USE_CUDA_DOCKER"] = "false" USE_CUDA = "false" DEVICE_TYPE = "cpu"else: DEVICE_TYPE = "cpu"
try: import torch
if torch.backends.mps.is_available() and torch.backends.mps.is_built(): DEVICE_TYPE = "mps"except Exception: pass
##################################### LOGGING####################################
GLOBAL_LOG_LEVEL = os.environ.get("GLOBAL_LOG_LEVEL", "").upper()if GLOBAL_LOG_LEVEL in logging.getLevelNamesMapping(): logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL, force=True)else: GLOBAL_LOG_LEVEL = "INFO"
log = logging.getLogger(__name__)log.info(f"GLOBAL_LOG_LEVEL: {GLOBAL_LOG_LEVEL}")
if "cuda_error" in locals(): log.exception(cuda_error) del cuda_error
WEBUI_NAME = os.environ.get("WEBUI_NAME", "Open WebUI")if WEBUI_NAME != "Open WebUI": WEBUI_NAME += " (Open WebUI)"
WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png"
TRUSTED_SIGNATURE_KEY = os.environ.get("TRUSTED_SIGNATURE_KEY", "")
##################################### ENV (dev,test,prod)####################################
ENV = os.environ.get("ENV", "dev")
FROM_INIT_PY = os.environ.get("FROM_INIT_PY", "False").lower() == "true"
if FROM_INIT_PY: PACKAGE_DATA = {"version": importlib.metadata.version("open-webui")}else: try: PACKAGE_DATA = json.loads((BASE_DIR / "package.json").read_text()) except Exception: PACKAGE_DATA = {"version": "0.0.0"}
VERSION = PACKAGE_DATA["version"]
DEPLOYMENT_ID = os.environ.get("DEPLOYMENT_ID", "")INSTANCE_ID = os.environ.get("INSTANCE_ID", str(uuid4()))
# Function to parse each sectiondef parse_section(section): items = [] for li in section.find_all("li"): # Extract raw HTML string raw_html = str(li)
# Extract text without HTML tags text = li.get_text(separator=" ", strip=True)
# Split into title and content parts = text.split(": ", 1) title = parts[0].strip() if len(parts) > 1 else "" content = parts[1].strip() if len(parts) > 1 else text
items.append({"title": title, "content": content, "raw": raw_html}) return items
try: changelog_path = BASE_DIR / "CHANGELOG.md" with open(str(changelog_path.absolute()), "r", encoding="utf8") as file: changelog_content = file.read()
except Exception: changelog_content = (pkgutil.get_data("open_webui", "CHANGELOG.md") or b"").decode()
# Convert markdown content to HTMLhtml_content = markdown.markdown(changelog_content)
# Parse the HTML contentsoup = BeautifulSoup(html_content, "html.parser")
# Initialize JSON structurechangelog_json = {}
# Iterate over each versionfor version in soup.find_all("h2"): version_number = version.get_text().strip().split(" - ")[0][1:-1] # Remove brackets date = version.get_text().strip().split(" - ")[1]
version_data = {"date": date}
# Find the next sibling that is a h3 tag (section title) current = version.find_next_sibling()
while current and current.name != "h2": if current.name == "h3": section_title = current.get_text().lower() # e.g., "added", "fixed" section_items = parse_section(current.find_next_sibling("ul")) version_data[section_title] = section_items
# Move to the next element current = current.find_next_sibling()
changelog_json[version_number] = version_data
CHANGELOG = changelog_json
##################################### SAFE_MODE####################################
SAFE_MODE = os.environ.get("SAFE_MODE", "false").lower() == "true"
##################################### ENABLE_FORWARD_USER_INFO_HEADERS####################################
ENABLE_FORWARD_USER_INFO_HEADERS = ( os.environ.get("ENABLE_FORWARD_USER_INFO_HEADERS", "False").lower() == "true")
# Experimental feature, may be removed in futureENABLE_STAR_SESSIONS_MIDDLEWARE = ( os.environ.get("ENABLE_STAR_SESSIONS_MIDDLEWARE", "False").lower() == "true")
##################################### WEBUI_BUILD_HASH####################################
WEBUI_BUILD_HASH = os.environ.get("WEBUI_BUILD_HASH", "dev-build")
##################################### DATA/FRONTEND BUILD DIR####################################
DATA_DIR = Path(os.getenv("DATA_DIR", BACKEND_DIR / "data")).resolve()
if FROM_INIT_PY: NEW_DATA_DIR = Path(os.getenv("DATA_DIR", OPEN_WEBUI_DIR / "data")).resolve() NEW_DATA_DIR.mkdir(parents=True, exist_ok=True)
# Check if the data directory exists in the package directory if DATA_DIR.exists() and DATA_DIR != NEW_DATA_DIR: log.info(f"Moving {DATA_DIR} to {NEW_DATA_DIR}") for item in DATA_DIR.iterdir(): dest = NEW_DATA_DIR / item.name if item.is_dir(): shutil.copytree(item, dest, dirs_exist_ok=True) else: shutil.copy2(item, dest)
# Zip the data directory shutil.make_archive(DATA_DIR.parent / "open_webui_data", "zip", DATA_DIR)
# Remove the old data directory shutil.rmtree(DATA_DIR)
DATA_DIR = Path(os.getenv("DATA_DIR", OPEN_WEBUI_DIR / "data"))
STATIC_DIR = Path(os.getenv("STATIC_DIR", OPEN_WEBUI_DIR / "static"))
FONTS_DIR = Path(os.getenv("FONTS_DIR", OPEN_WEBUI_DIR / "static" / "fonts"))
FRONTEND_BUILD_DIR = Path(os.getenv("FRONTEND_BUILD_DIR", BASE_DIR / "build")).resolve()
if FROM_INIT_PY: FRONTEND_BUILD_DIR = Path( os.getenv("FRONTEND_BUILD_DIR", OPEN_WEBUI_DIR / "frontend") ).resolve()
##################################### Database####################################
# Check if the file existsif os.path.exists(f"{DATA_DIR}/ollama.db"): # Rename the file os.rename(f"{DATA_DIR}/ollama.db", f"{DATA_DIR}/webui.db") log.info("Database migrated from Ollama-WebUI successfully.")else: pass
DATABASE_URL = os.environ.get("DATABASE_URL", f"sqlite:///{DATA_DIR}/webui.db")
DATABASE_TYPE = os.environ.get("DATABASE_TYPE")DATABASE_USER = os.environ.get("DATABASE_USER")DATABASE_PASSWORD = os.environ.get("DATABASE_PASSWORD")
DATABASE_CRED = ""if DATABASE_USER: DATABASE_CRED += f"{DATABASE_USER}"if DATABASE_PASSWORD: DATABASE_CRED += f":{DATABASE_PASSWORD}"
DB_VARS = { "db_type": DATABASE_TYPE, "db_cred": DATABASE_CRED, "db_host": os.environ.get("DATABASE_HOST"), "db_port": os.environ.get("DATABASE_PORT"), "db_name": os.environ.get("DATABASE_NAME"),}
if all(DB_VARS.values()): DATABASE_URL = f"{DB_VARS['db_type']}://{DB_VARS['db_cred']}@{DB_VARS['db_host']}:{DB_VARS['db_port']}/{DB_VARS['db_name']}"elif DATABASE_TYPE == "sqlite+sqlcipher" and not os.environ.get("DATABASE_URL"): # Handle SQLCipher with local file when DATABASE_URL wasn't explicitly set DATABASE_URL = f"sqlite+sqlcipher:///{DATA_DIR}/webui.db"
# Replace the postgres:// with postgresql://if "postgres://" in DATABASE_URL: DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://")
DATABASE_SCHEMA = os.environ.get("DATABASE_SCHEMA", None)
DATABASE_POOL_SIZE = os.environ.get("DATABASE_POOL_SIZE", None)
if DATABASE_POOL_SIZE != None: try: DATABASE_POOL_SIZE = int(DATABASE_POOL_SIZE) except Exception: DATABASE_POOL_SIZE = None
DATABASE_POOL_MAX_OVERFLOW = os.environ.get("DATABASE_POOL_MAX_OVERFLOW", 0)
if DATABASE_POOL_MAX_OVERFLOW == "": DATABASE_POOL_MAX_OVERFLOW = 0else: try: DATABASE_POOL_MAX_OVERFLOW = int(DATABASE_POOL_MAX_OVERFLOW) except Exception: DATABASE_POOL_MAX_OVERFLOW = 0
DATABASE_POOL_TIMEOUT = os.environ.get("DATABASE_POOL_TIMEOUT", 30)
if DATABASE_POOL_TIMEOUT == "": DATABASE_POOL_TIMEOUT = 30else: try: DATABASE_POOL_TIMEOUT = int(DATABASE_POOL_TIMEOUT) except Exception: DATABASE_POOL_TIMEOUT = 30
DATABASE_POOL_RECYCLE = os.environ.get("DATABASE_POOL_RECYCLE", 3600)
if DATABASE_POOL_RECYCLE == "": DATABASE_POOL_RECYCLE = 3600else: try: DATABASE_POOL_RECYCLE = int(DATABASE_POOL_RECYCLE) except Exception: DATABASE_POOL_RECYCLE = 3600
DATABASE_ENABLE_SQLITE_WAL = ( os.environ.get("DATABASE_ENABLE_SQLITE_WAL", "False").lower() == "true")
DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = os.environ.get( "DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL", None)if DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL is not None: try: DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = float( DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL ) except Exception: DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL = 0.0
# Enable public visibility of active user count (when disabled, only admins can see it)ENABLE_PUBLIC_ACTIVE_USERS_COUNT = ( os.environ.get("ENABLE_PUBLIC_ACTIVE_USERS_COUNT", "True").lower() == "true")
RESET_CONFIG_ON_START = ( os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true")
ENABLE_REALTIME_CHAT_SAVE = ( os.environ.get("ENABLE_REALTIME_CHAT_SAVE", "False").lower() == "true")
ENABLE_QUERIES_CACHE = os.environ.get("ENABLE_QUERIES_CACHE", "False").lower() == "true"
##################################### REDIS####################################
REDIS_URL = os.environ.get("REDIS_URL", "")REDIS_CLUSTER = os.environ.get("REDIS_CLUSTER", "False").lower() == "true"
REDIS_KEY_PREFIX = os.environ.get("REDIS_KEY_PREFIX", "open-webui")
REDIS_SENTINEL_HOSTS = os.environ.get("REDIS_SENTINEL_HOSTS", "")REDIS_SENTINEL_PORT = os.environ.get("REDIS_SENTINEL_PORT", "26379")
# Maximum number of retries for Redis operations when using Sentinel fail-overREDIS_SENTINEL_MAX_RETRY_COUNT = os.environ.get("REDIS_SENTINEL_MAX_RETRY_COUNT", "2")try: REDIS_SENTINEL_MAX_RETRY_COUNT = int(REDIS_SENTINEL_MAX_RETRY_COUNT) if REDIS_SENTINEL_MAX_RETRY_COUNT < 1: REDIS_SENTINEL_MAX_RETRY_COUNT = 2except ValueError: REDIS_SENTINEL_MAX_RETRY_COUNT = 2
REDIS_SOCKET_CONNECT_TIMEOUT = os.environ.get("REDIS_SOCKET_CONNECT_TIMEOUT", "")try: REDIS_SOCKET_CONNECT_TIMEOUT = float(REDIS_SOCKET_CONNECT_TIMEOUT)except ValueError: REDIS_SOCKET_CONNECT_TIMEOUT = None
##################################### UVICORN WORKERS####################################
# Number of uvicorn worker processes for handling requestsUVICORN_WORKERS = os.environ.get("UVICORN_WORKERS", "1")try: UVICORN_WORKERS = int(UVICORN_WORKERS) if UVICORN_WORKERS < 1: UVICORN_WORKERS = 1except ValueError: UVICORN_WORKERS = 1 log.info(f"Invalid UVICORN_WORKERS value, defaulting to {UVICORN_WORKERS}")
##################################### WEBUI_AUTH (Required for security)####################################
WEBUI_AUTH = os.environ.get("WEBUI_AUTH", "True").lower() == "true"
ENABLE_INITIAL_ADMIN_SIGNUP = ( os.environ.get("ENABLE_INITIAL_ADMIN_SIGNUP", "False").lower() == "true")ENABLE_SIGNUP_PASSWORD_CONFIRMATION = ( os.environ.get("ENABLE_SIGNUP_PASSWORD_CONFIRMATION", "False").lower() == "true")
WEBUI_AUTH_TRUSTED_EMAIL_HEADER = os.environ.get( "WEBUI_AUTH_TRUSTED_EMAIL_HEADER", None)WEBUI_AUTH_TRUSTED_NAME_HEADER = os.environ.get("WEBUI_AUTH_TRUSTED_NAME_HEADER", None)WEBUI_AUTH_TRUSTED_GROUPS_HEADER = os.environ.get( "WEBUI_AUTH_TRUSTED_GROUPS_HEADER", None)
ENABLE_PASSWORD_VALIDATION = ( os.environ.get("ENABLE_PASSWORD_VALIDATION", "False").lower() == "true")PASSWORD_VALIDATION_REGEX_PATTERN = os.environ.get( "PASSWORD_VALIDATION_REGEX_PATTERN", "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$",)
PASSWORD_VALIDATION_REGEX_PATTERN = re.compile(PASSWORD_VALIDATION_REGEX_PATTERN)
BYPASS_MODEL_ACCESS_CONTROL = ( os.environ.get("BYPASS_MODEL_ACCESS_CONTROL", "False").lower() == "true")
WEBUI_AUTH_SIGNOUT_REDIRECT_URL = os.environ.get( "WEBUI_AUTH_SIGNOUT_REDIRECT_URL", None)
##################################### WEBUI_SECRET_KEY####################################
WEBUI_SECRET_KEY = os.environ.get( "WEBUI_SECRET_KEY", os.environ.get( "WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t" ), # DEPRECATED: remove at next major version)
WEBUI_SESSION_COOKIE_SAME_SITE = os.environ.get("WEBUI_SESSION_COOKIE_SAME_SITE", "lax")
WEBUI_SESSION_COOKIE_SECURE = ( os.environ.get("WEBUI_SESSION_COOKIE_SECURE", "false").lower() == "true")
WEBUI_AUTH_COOKIE_SAME_SITE = os.environ.get( "WEBUI_AUTH_COOKIE_SAME_SITE", WEBUI_SESSION_COOKIE_SAME_SITE)
WEBUI_AUTH_COOKIE_SECURE = ( os.environ.get( "WEBUI_AUTH_COOKIE_SECURE", os.environ.get("WEBUI_SESSION_COOKIE_SECURE", "false"), ).lower() == "true")
if WEBUI_AUTH and WEBUI_SECRET_KEY == "": raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
ENABLE_COMPRESSION_MIDDLEWARE = ( os.environ.get("ENABLE_COMPRESSION_MIDDLEWARE", "True").lower() == "true")
##################################### OAUTH Configuration####################################ENABLE_OAUTH_EMAIL_FALLBACK = ( os.environ.get("ENABLE_OAUTH_EMAIL_FALLBACK", "False").lower() == "true")
ENABLE_OAUTH_ID_TOKEN_COOKIE = ( os.environ.get("ENABLE_OAUTH_ID_TOKEN_COOKIE", "True").lower() == "true")
OAUTH_CLIENT_INFO_ENCRYPTION_KEY = os.environ.get( "OAUTH_CLIENT_INFO_ENCRYPTION_KEY", WEBUI_SECRET_KEY)
OAUTH_SESSION_TOKEN_ENCRYPTION_KEY = os.environ.get( "OAUTH_SESSION_TOKEN_ENCRYPTION_KEY", WEBUI_SECRET_KEY)
##################################### SCIM Configuration####################################
ENABLE_SCIM = ( os.environ.get("ENABLE_SCIM", os.environ.get("SCIM_ENABLED", "False")).lower() == "true")SCIM_TOKEN = os.environ.get("SCIM_TOKEN", "")
##################################### LICENSE_KEY####################################
LICENSE_KEY = os.environ.get("LICENSE_KEY", "")
LICENSE_BLOB = NoneLICENSE_BLOB_PATH = os.environ.get("LICENSE_BLOB_PATH", DATA_DIR / "l.data")if LICENSE_BLOB_PATH and os.path.exists(LICENSE_BLOB_PATH): with open(LICENSE_BLOB_PATH, "rb") as f: LICENSE_BLOB = f.read()
LICENSE_PUBLIC_KEY = os.environ.get("LICENSE_PUBLIC_KEY", "")
pk = Noneif LICENSE_PUBLIC_KEY: pk = serialization.load_pem_public_key( f"""-----BEGIN PUBLIC KEY-----{LICENSE_PUBLIC_KEY}-----END PUBLIC KEY-----""".encode( "utf-8" ) )
##################################### MODELS####################################
MODELS_CACHE_TTL = os.environ.get("MODELS_CACHE_TTL", "1")if MODELS_CACHE_TTL == "": MODELS_CACHE_TTL = Noneelse: try: MODELS_CACHE_TTL = int(MODELS_CACHE_TTL) except Exception: MODELS_CACHE_TTL = 1
##################################### CHAT####################################
ENABLE_CHAT_RESPONSE_BASE64_IMAGE_URL_CONVERSION = ( os.environ.get("ENABLE_CHAT_RESPONSE_BASE64_IMAGE_URL_CONVERSION", "False").lower() == "true")
CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE = os.environ.get( "CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE", "1")
if CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE == "": CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE = 1else: try: CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE = int( CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE ) except Exception: CHAT_RESPONSE_STREAM_DELTA_CHUNK_SIZE = 1
CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES = os.environ.get( "CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES", "30")
if CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES == "": CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES = 30else: try: CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES = int(CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES) except Exception: CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES = 30
CHAT_STREAM_RESPONSE_CHUNK_MAX_BUFFER_SIZE = os.environ.get( "CHAT_STREAM_RESPONSE_CHUNK_MAX_BUFFER_SIZE", "")
if CHAT_STREAM_RESPONSE_CHUNK_MAX_BUFFER_SIZE == "": CHAT_STREAM_RESPONSE_CHUNK_MAX_BUFFER_SIZE = Noneelse: try: CHAT_STREAM_RESPONSE_CHUNK_MAX_BUFFER_SIZE = int( CHAT_STREAM_RESPONSE_CHUNK_MAX_BUFFER_SIZE ) except Exception: CHAT_STREAM_RESPONSE_CHUNK_MAX_BUFFER_SIZE = None
##################################### WEBSOCKET SUPPORT####################################
ENABLE_WEBSOCKET_SUPPORT = ( os.environ.get("ENABLE_WEBSOCKET_SUPPORT", "True").lower() == "true")
WEBSOCKET_MANAGER = os.environ.get("WEBSOCKET_MANAGER", "")
WEBSOCKET_REDIS_OPTIONS = os.environ.get("WEBSOCKET_REDIS_OPTIONS", "")
if WEBSOCKET_REDIS_OPTIONS == "": if REDIS_SOCKET_CONNECT_TIMEOUT: WEBSOCKET_REDIS_OPTIONS = { "socket_connect_timeout": REDIS_SOCKET_CONNECT_TIMEOUT } else: log.debug("No WEBSOCKET_REDIS_OPTIONS provided, defaulting to None") WEBSOCKET_REDIS_OPTIONS = Noneelse: try: WEBSOCKET_REDIS_OPTIONS = json.loads(WEBSOCKET_REDIS_OPTIONS) except Exception: log.warning("Invalid WEBSOCKET_REDIS_OPTIONS, defaulting to None") WEBSOCKET_REDIS_OPTIONS = None
WEBSOCKET_REDIS_URL = os.environ.get("WEBSOCKET_REDIS_URL", REDIS_URL)WEBSOCKET_REDIS_CLUSTER = ( os.environ.get("WEBSOCKET_REDIS_CLUSTER", str(REDIS_CLUSTER)).lower() == "true")
websocket_redis_lock_timeout = os.environ.get("WEBSOCKET_REDIS_LOCK_TIMEOUT", "60")
try: WEBSOCKET_REDIS_LOCK_TIMEOUT = int(websocket_redis_lock_timeout)except ValueError: WEBSOCKET_REDIS_LOCK_TIMEOUT = 60
WEBSOCKET_SENTINEL_HOSTS = os.environ.get("WEBSOCKET_SENTINEL_HOSTS", "")WEBSOCKET_SENTINEL_PORT = os.environ.get("WEBSOCKET_SENTINEL_PORT", "26379")WEBSOCKET_SERVER_LOGGING = ( os.environ.get("WEBSOCKET_SERVER_LOGGING", "False").lower() == "true")WEBSOCKET_SERVER_ENGINEIO_LOGGING = ( os.environ.get("WEBSOCKET_SERVER_LOGGING", "False").lower() == "true")WEBSOCKET_SERVER_PING_TIMEOUT = os.environ.get("WEBSOCKET_SERVER_PING_TIMEOUT", "20")try: WEBSOCKET_SERVER_PING_TIMEOUT = int(WEBSOCKET_SERVER_PING_TIMEOUT)except ValueError: WEBSOCKET_SERVER_PING_TIMEOUT = 20
WEBSOCKET_SERVER_PING_INTERVAL = os.environ.get("WEBSOCKET_SERVER_PING_INTERVAL", "25")try: WEBSOCKET_SERVER_PING_INTERVAL = int(WEBSOCKET_SERVER_PING_INTERVAL)except ValueError: WEBSOCKET_SERVER_PING_INTERVAL = 25
AIOHTTP_CLIENT_TIMEOUT = os.environ.get("AIOHTTP_CLIENT_TIMEOUT", "")
if AIOHTTP_CLIENT_TIMEOUT == "": AIOHTTP_CLIENT_TIMEOUT = Noneelse: try: AIOHTTP_CLIENT_TIMEOUT = int(AIOHTTP_CLIENT_TIMEOUT) except Exception: AIOHTTP_CLIENT_TIMEOUT = 300
AIOHTTP_CLIENT_SESSION_SSL = ( os.environ.get("AIOHTTP_CLIENT_SESSION_SSL", "True").lower() == "true")
AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST = os.environ.get( "AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST", os.environ.get("AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST", "10"),)
if AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST == "": AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST = Noneelse: try: AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST = int(AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST) except Exception: AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST = 10
AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA = os.environ.get( "AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA", "10")
if AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA == "": AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA = Noneelse: try: AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA = int( AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA ) except Exception: AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA = 10
AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL = ( os.environ.get("AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL", "True").lower() == "true")
##################################### SENTENCE TRANSFORMERS####################################
SENTENCE_TRANSFORMERS_BACKEND = os.environ.get("SENTENCE_TRANSFORMERS_BACKEND", "")if SENTENCE_TRANSFORMERS_BACKEND == "": SENTENCE_TRANSFORMERS_BACKEND = "torch"
SENTENCE_TRANSFORMERS_MODEL_KWARGS = os.environ.get( "SENTENCE_TRANSFORMERS_MODEL_KWARGS", "")if SENTENCE_TRANSFORMERS_MODEL_KWARGS == "": SENTENCE_TRANSFORMERS_MODEL_KWARGS = Noneelse: try: SENTENCE_TRANSFORMERS_MODEL_KWARGS = json.loads( SENTENCE_TRANSFORMERS_MODEL_KWARGS ) except Exception: SENTENCE_TRANSFORMERS_MODEL_KWARGS = None
SENTENCE_TRANSFORMERS_CROSS_ENCODER_BACKEND = os.environ.get( "SENTENCE_TRANSFORMERS_CROSS_ENCODER_BACKEND", "")if SENTENCE_TRANSFORMERS_CROSS_ENCODER_BACKEND == "": SENTENCE_TRANSFORMERS_CROSS_ENCODER_BACKEND = "torch"
SENTENCE_TRANSFORMERS_CROSS_ENCODER_MODEL_KWARGS = os.environ.get( "SENTENCE_TRANSFORMERS_CROSS_ENCODER_MODEL_KWARGS", "")if SENTENCE_TRANSFORMERS_CROSS_ENCODER_MODEL_KWARGS == "": SENTENCE_TRANSFORMERS_CROSS_ENCODER_MODEL_KWARGS = Noneelse: try: SENTENCE_TRANSFORMERS_CROSS_ENCODER_MODEL_KWARGS = json.loads( SENTENCE_TRANSFORMERS_CROSS_ENCODER_MODEL_KWARGS ) except Exception: SENTENCE_TRANSFORMERS_CROSS_ENCODER_MODEL_KWARGS = None
##################################### OFFLINE_MODE####################################
ENABLE_VERSION_UPDATE_CHECK = ( os.environ.get("ENABLE_VERSION_UPDATE_CHECK", "true").lower() == "true")OFFLINE_MODE = os.environ.get("OFFLINE_MODE", "false").lower() == "true"
if OFFLINE_MODE: os.environ["HF_HUB_OFFLINE"] = "1" ENABLE_VERSION_UPDATE_CHECK = False
##################################### AUDIT LOGGING##################################### Where to store log file# Defaults to the DATA_DIR/audit.log. To set AUDIT_LOGS_FILE_PATH you need to# provide the whole path, like: /app/audit.logAUDIT_LOGS_FILE_PATH = os.getenv("AUDIT_LOGS_FILE_PATH", f"{DATA_DIR}/audit.log")# Maximum size of a file before rotating into a new log fileAUDIT_LOG_FILE_ROTATION_SIZE = os.getenv("AUDIT_LOG_FILE_ROTATION_SIZE", "10MB")
# Comma separated list of logger names to use for audit logging# Default is "uvicorn.access" which is the access log for Uvicorn# You can add more logger names to this list if you want to capture more logsAUDIT_UVICORN_LOGGER_NAMES = os.getenv( "AUDIT_UVICORN_LOGGER_NAMES", "uvicorn.access").split(",")
# METADATA | REQUEST | REQUEST_RESPONSEAUDIT_LOG_LEVEL = os.getenv("AUDIT_LOG_LEVEL", "NONE").upper()try: MAX_BODY_LOG_SIZE = int(os.environ.get("MAX_BODY_LOG_SIZE") or 2048)except ValueError: MAX_BODY_LOG_SIZE = 2048
# Comma separated list for urls to exclude from auditAUDIT_EXCLUDED_PATHS = os.getenv("AUDIT_EXCLUDED_PATHS", "/chats,/chat,/folders").split( ",")AUDIT_EXCLUDED_PATHS = [path.strip() for path in AUDIT_EXCLUDED_PATHS]AUDIT_EXCLUDED_PATHS = [path.lstrip("/") for path in AUDIT_EXCLUDED_PATHS]
##################################### OPENTELEMETRY####################################
ENABLE_OTEL = os.environ.get("ENABLE_OTEL", "False").lower() == "true"ENABLE_OTEL_TRACES = os.environ.get("ENABLE_OTEL_TRACES", "False").lower() == "true"ENABLE_OTEL_METRICS = os.environ.get("ENABLE_OTEL_METRICS", "False").lower() == "true"ENABLE_OTEL_LOGS = os.environ.get("ENABLE_OTEL_LOGS", "False").lower() == "true"
OTEL_EXPORTER_OTLP_ENDPOINT = os.environ.get( "OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4317")OTEL_METRICS_EXPORTER_OTLP_ENDPOINT = os.environ.get( "OTEL_METRICS_EXPORTER_OTLP_ENDPOINT", OTEL_EXPORTER_OTLP_ENDPOINT)OTEL_LOGS_EXPORTER_OTLP_ENDPOINT = os.environ.get( "OTEL_LOGS_EXPORTER_OTLP_ENDPOINT", OTEL_EXPORTER_OTLP_ENDPOINT)OTEL_EXPORTER_OTLP_INSECURE = ( os.environ.get("OTEL_EXPORTER_OTLP_INSECURE", "False").lower() == "true")OTEL_METRICS_EXPORTER_OTLP_INSECURE = ( os.environ.get( "OTEL_METRICS_EXPORTER_OTLP_INSECURE", str(OTEL_EXPORTER_OTLP_INSECURE) ).lower() == "true")OTEL_LOGS_EXPORTER_OTLP_INSECURE = ( os.environ.get( "OTEL_LOGS_EXPORTER_OTLP_INSECURE", str(OTEL_EXPORTER_OTLP_INSECURE) ).lower() == "true")OTEL_SERVICE_NAME = os.environ.get("OTEL_SERVICE_NAME", "open-webui")OTEL_RESOURCE_ATTRIBUTES = os.environ.get( "OTEL_RESOURCE_ATTRIBUTES", "") # e.g. key1=val1,key2=val2OTEL_TRACES_SAMPLER = os.environ.get( "OTEL_TRACES_SAMPLER", "parentbased_always_on").lower()OTEL_BASIC_AUTH_USERNAME = os.environ.get("OTEL_BASIC_AUTH_USERNAME", "")OTEL_BASIC_AUTH_PASSWORD = os.environ.get("OTEL_BASIC_AUTH_PASSWORD", "")
OTEL_METRICS_BASIC_AUTH_USERNAME = os.environ.get( "OTEL_METRICS_BASIC_AUTH_USERNAME", OTEL_BASIC_AUTH_USERNAME)OTEL_METRICS_BASIC_AUTH_PASSWORD = os.environ.get( "OTEL_METRICS_BASIC_AUTH_PASSWORD", OTEL_BASIC_AUTH_PASSWORD)OTEL_LOGS_BASIC_AUTH_USERNAME = os.environ.get( "OTEL_LOGS_BASIC_AUTH_USERNAME", OTEL_BASIC_AUTH_USERNAME)OTEL_LOGS_BASIC_AUTH_PASSWORD = os.environ.get( "OTEL_LOGS_BASIC_AUTH_PASSWORD", OTEL_BASIC_AUTH_PASSWORD)
OTEL_OTLP_SPAN_EXPORTER = os.environ.get( "OTEL_OTLP_SPAN_EXPORTER", "grpc").lower() # grpc or http
OTEL_METRICS_OTLP_SPAN_EXPORTER = os.environ.get( "OTEL_METRICS_OTLP_SPAN_EXPORTER", OTEL_OTLP_SPAN_EXPORTER).lower() # grpc or http
OTEL_LOGS_OTLP_SPAN_EXPORTER = os.environ.get( "OTEL_LOGS_OTLP_SPAN_EXPORTER", OTEL_OTLP_SPAN_EXPORTER).lower() # grpc or http
##################################### TOOLS/FUNCTIONS PIP OPTIONS####################################
PIP_OPTIONS = os.getenv("PIP_OPTIONS", "").split()PIP_PACKAGE_INDEX_OPTIONS = os.getenv("PIP_PACKAGE_INDEX_OPTIONS", "").split()
##################################### PROGRESSIVE WEB APP OPTIONS####################################
EXTERNAL_PWA_MANIFEST_URL = os.environ.get("EXTERNAL_PWA_MANIFEST_URL")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352import loggingimport sysimport inspectimport jsonimport asyncio
from pydantic import BaseModelfrom typing import AsyncGenerator, Generator, Iteratorfrom fastapi import ( Depends, FastAPI, File, Form, HTTPException, Request, UploadFile, status,)from starlette.responses import Response, StreamingResponse
from open_webui.constants import ERROR_MESSAGESfrom open_webui.socket.main import ( get_event_call, get_event_emitter,)
from open_webui.models.users import UserModelfrom open_webui.models.functions import Functionsfrom open_webui.models.models import Models
from open_webui.utils.plugin import ( load_function_module_by_id, get_function_module_from_cache,)from open_webui.utils.tools import get_toolsfrom open_webui.utils.access_control import has_access
from open_webui.env import GLOBAL_LOG_LEVEL
from open_webui.utils.misc import ( add_or_update_system_message, get_last_user_message, prepend_to_first_user_message_content, openai_chat_chunk_message_template, openai_chat_completion_message_template,)from open_webui.utils.payload import ( apply_model_params_to_body_openai, apply_system_prompt_to_body,)
logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL)log = logging.getLogger(__name__)
def get_function_module_by_id(request: Request, pipe_id: str): function_module, _, _ = get_function_module_from_cache(request, pipe_id)
if hasattr(function_module, "valves") and hasattr(function_module, "Valves"): Valves = function_module.Valves valves = Functions.get_function_valves_by_id(pipe_id)
if valves: try: function_module.valves = Valves( **{k: v for k, v in valves.items() if v is not None} ) except Exception as e: log.exception(f"Error loading valves for function {pipe_id}: {e}") raise e else: function_module.valves = Valves()
return function_module
async def get_function_models(request): pipes = Functions.get_functions_by_type("pipe", active_only=True) pipe_models = []
for pipe in pipes: try: function_module = get_function_module_by_id(request, pipe.id)
has_user_valves = False if hasattr(function_module, "UserValves"): has_user_valves = True
# Check if function is a manifold if hasattr(function_module, "pipes"): sub_pipes = []
# Handle pipes being a list, sync function, or async function try: if callable(function_module.pipes): if asyncio.iscoroutinefunction(function_module.pipes): sub_pipes = await function_module.pipes() else: sub_pipes = function_module.pipes() else: sub_pipes = function_module.pipes except Exception as e: log.exception(e) sub_pipes = []
log.debug( f"get_function_models: function '{pipe.id}' is a manifold of {sub_pipes}" )
for p in sub_pipes: sub_pipe_id = f'{pipe.id}.{p["id"]}' sub_pipe_name = p["name"]
if hasattr(function_module, "name"): sub_pipe_name = f"{function_module.name}{sub_pipe_name}"
pipe_flag = {"type": pipe.type}
pipe_models.append( { "id": sub_pipe_id, "name": sub_pipe_name, "object": "model", "created": pipe.created_at, "owned_by": "openai", "pipe": pipe_flag, "has_user_valves": has_user_valves, } ) else: pipe_flag = {"type": "pipe"}
log.debug( f"get_function_models: function '{pipe.id}' is a single pipe {{ 'id': {pipe.id}, 'name': {pipe.name} }}" )
pipe_models.append( { "id": pipe.id, "name": pipe.name, "object": "model", "created": pipe.created_at, "owned_by": "openai", "pipe": pipe_flag, "has_user_valves": has_user_valves, } ) except Exception as e: log.exception(e) continue
return pipe_models
async def generate_function_chat_completion( request, form_data, user, models: dict = {}): async def execute_pipe(pipe, params): if inspect.iscoroutinefunction(pipe): return await pipe(**params) else: return pipe(**params)
async def get_message_content(res: str | Generator | AsyncGenerator) -> str: if isinstance(res, str): return res if isinstance(res, Generator): return "".join(map(str, res)) if isinstance(res, AsyncGenerator): return "".join([str(stream) async for stream in res])
def process_line(form_data: dict, line): if isinstance(line, BaseModel): line = line.model_dump_json() line = f"data: {line}" if isinstance(line, dict): line = f"data: {json.dumps(line)}"
try: line = line.decode("utf-8") except Exception: pass
if line.startswith("data:"): return f"{line}\n\n" else: line = openai_chat_chunk_message_template(form_data["model"], line) return f"data: {json.dumps(line)}\n\n"
def get_pipe_id(form_data: dict) -> str: pipe_id = form_data["model"] if "." in pipe_id: pipe_id, _ = pipe_id.split(".", 1) return pipe_id
def get_function_params(function_module, form_data, user, extra_params=None): if extra_params is None: extra_params = {}
pipe_id = get_pipe_id(form_data)
# Get the signature of the function sig = inspect.signature(function_module.pipe) params = {"body": form_data} | { k: v for k, v in extra_params.items() if k in sig.parameters }
if "__user__" in params and hasattr(function_module, "UserValves"): user_valves = Functions.get_user_valves_by_id_and_user_id(pipe_id, user.id) try: params["__user__"]["valves"] = function_module.UserValves(**user_valves) except Exception as e: log.exception(e) params["__user__"]["valves"] = function_module.UserValves()
return params
model_id = form_data.get("model") model_info = Models.get_model_by_id(model_id)
metadata = form_data.pop("metadata", {})
files = metadata.get("files", []) tool_ids = metadata.get("tool_ids", []) # Check if tool_ids is None if tool_ids is None: tool_ids = []
__event_emitter__ = None __event_call__ = None __task__ = None __task_body__ = None
if metadata: if all(k in metadata for k in ("session_id", "chat_id", "message_id")): __event_emitter__ = get_event_emitter(metadata) __event_call__ = get_event_call(metadata) __task__ = metadata.get("task", None) __task_body__ = metadata.get("task_body", None)
oauth_token = None try: if request.cookies.get("oauth_session_id", None): oauth_token = await request.app.state.oauth_manager.get_oauth_token( user.id, request.cookies.get("oauth_session_id", None), ) except Exception as e: log.error(f"Error getting OAuth token: {e}")
extra_params = { "__event_emitter__": __event_emitter__, "__event_call__": __event_call__, "__chat_id__": metadata.get("chat_id", None), "__session_id__": metadata.get("session_id", None), "__message_id__": metadata.get("message_id", None), "__task__": __task__, "__task_body__": __task_body__, "__files__": files, "__user__": user.model_dump() if isinstance(user, UserModel) else {}, "__metadata__": metadata, "__oauth_token__": oauth_token, "__request__": request, } extra_params["__tools__"] = await get_tools( request, tool_ids, user, { **extra_params, "__model__": models.get(form_data["model"], None), "__messages__": form_data["messages"], "__files__": files, }, )
if model_info: if model_info.base_model_id: form_data["model"] = model_info.base_model_id
params = model_info.params.model_dump()
if params: system = params.pop("system", None) form_data = apply_model_params_to_body_openai(params, form_data) form_data = apply_system_prompt_to_body(system, form_data, metadata, user)
pipe_id = get_pipe_id(form_data) function_module = get_function_module_by_id(request, pipe_id)
pipe = function_module.pipe params = get_function_params(function_module, form_data, user, extra_params)
if form_data.get("stream", False):
async def stream_content(): try: res = await execute_pipe(pipe, params)
# Directly return if the response is a StreamingResponse if isinstance(res, StreamingResponse): async for data in res.body_iterator: yield data return if isinstance(res, dict): yield f"data: {json.dumps(res)}\n\n" return
except Exception as e: log.error(f"Error: {e}") yield f"data: {json.dumps({'error': {'detail':str(e)}})}\n\n" return
if isinstance(res, str): message = openai_chat_chunk_message_template(form_data["model"], res) yield f"data: {json.dumps(message)}\n\n"
if isinstance(res, Iterator): for line in res: yield process_line(form_data, line)
if isinstance(res, AsyncGenerator): async for line in res: yield process_line(form_data, line)
if isinstance(res, str) or isinstance(res, Generator): finish_message = openai_chat_chunk_message_template( form_data["model"], "" ) finish_message["choices"][0]["finish_reason"] = "stop" yield f"data: {json.dumps(finish_message)}\n\n" yield "data: [DONE]"
return StreamingResponse(stream_content(), media_type="text/event-stream") else: try: res = await execute_pipe(pipe, params)
except Exception as e: log.error(f"Error: {e}") return {"error": {"detail": str(e)}}
if isinstance(res, StreamingResponse) or isinstance(res, dict): return res if isinstance(res, BaseModel): return res.model_dump()
message = await get_message_content(res) return openai_chat_completion_message_template(form_data["model"], message)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162import osimport jsonimport loggingfrom contextlib import contextmanagerfrom typing import Any, Optional
from open_webui.internal.wrappers import register_connectionfrom open_webui.env import ( OPEN_WEBUI_DIR, DATABASE_URL, DATABASE_SCHEMA, DATABASE_POOL_MAX_OVERFLOW, DATABASE_POOL_RECYCLE, DATABASE_POOL_SIZE, DATABASE_POOL_TIMEOUT, DATABASE_ENABLE_SQLITE_WAL,)from peewee_migrate import Routerfrom sqlalchemy import Dialect, create_engine, MetaData, event, typesfrom sqlalchemy.ext.declarative import declarative_basefrom sqlalchemy.orm import scoped_session, sessionmakerfrom sqlalchemy.pool import QueuePool, NullPoolfrom sqlalchemy.sql.type_api import _Tfrom typing_extensions import Self
log = logging.getLogger(__name__)
class JSONField(types.TypeDecorator): impl = types.Text cache_ok = True
def process_bind_param(self, value: Optional[_T], dialect: Dialect) -> Any: return json.dumps(value)
def process_result_value(self, value: Optional[_T], dialect: Dialect) -> Any: if value is not None: return json.loads(value)
def copy(self, **kw: Any) -> Self: return JSONField(self.impl.length)
def db_value(self, value): return json.dumps(value)
def python_value(self, value): if value is not None: return json.loads(value)
# Workaround to handle the peewee migration# This is required to ensure the peewee migration is handled before the alembic migrationdef handle_peewee_migration(DATABASE_URL): # db = None try: # Replace the postgresql:// with postgres:// to handle the peewee migration db = register_connection(DATABASE_URL.replace("postgresql://", "postgres://")) migrate_dir = OPEN_WEBUI_DIR / "internal" / "migrations" router = Router(db, logger=log, migrate_dir=migrate_dir) router.run() db.close()
except Exception as e: log.error(f"Failed to initialize the database connection: {e}") log.warning( "Hint: If your database password contains special characters, you may need to URL-encode it." ) raise finally: # Properly closing the database connection if db and not db.is_closed(): db.close()
# Assert if db connection has been closed assert db.is_closed(), "Database connection is still open."
handle_peewee_migration(DATABASE_URL)
SQLALCHEMY_DATABASE_URL = DATABASE_URL
# Handle SQLCipher URLsif SQLALCHEMY_DATABASE_URL.startswith("sqlite+sqlcipher://"): database_password = os.environ.get("DATABASE_PASSWORD") if not database_password or database_password.strip() == "": raise ValueError( "DATABASE_PASSWORD is required when using sqlite+sqlcipher:// URLs" )
# Extract database path from SQLCipher URL db_path = SQLALCHEMY_DATABASE_URL.replace("sqlite+sqlcipher://", "") if db_path.startswith("/"): db_path = db_path[1:] # Remove leading slash for relative paths
# Create a custom creator function that uses sqlcipher3 def create_sqlcipher_connection(): import sqlcipher3
conn = sqlcipher3.connect(db_path, check_same_thread=False) conn.execute(f"PRAGMA key = '{database_password}'") return conn
engine = create_engine( "sqlite://", # Dummy URL since we're using creator creator=create_sqlcipher_connection, echo=False, )
log.info("Connected to encrypted SQLite database using SQLCipher")
elif "sqlite" in SQLALCHEMY_DATABASE_URL: engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} )
def on_connect(dbapi_connection, connection_record): cursor = dbapi_connection.cursor() if DATABASE_ENABLE_SQLITE_WAL: cursor.execute("PRAGMA journal_mode=WAL") else: cursor.execute("PRAGMA journal_mode=DELETE") cursor.close()
event.listen(engine, "connect", on_connect)else: if isinstance(DATABASE_POOL_SIZE, int): if DATABASE_POOL_SIZE > 0: engine = create_engine( SQLALCHEMY_DATABASE_URL, pool_size=DATABASE_POOL_SIZE, max_overflow=DATABASE_POOL_MAX_OVERFLOW, pool_timeout=DATABASE_POOL_TIMEOUT, pool_recycle=DATABASE_POOL_RECYCLE, pool_pre_ping=True, poolclass=QueuePool, ) else: engine = create_engine( SQLALCHEMY_DATABASE_URL, pool_pre_ping=True, poolclass=NullPool ) else: engine = create_engine(SQLALCHEMY_DATABASE_URL, pool_pre_ping=True)
SessionLocal = sessionmaker( autocommit=False, autoflush=False, bind=engine, expire_on_commit=False)metadata_obj = MetaData(schema=DATABASE_SCHEMA)Base = declarative_base(metadata=metadata_obj)Session = scoped_session(SessionLocal)
def get_session(): db = SessionLocal() try: yield db finally: db.close()
get_db = contextmanager(get_session)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254"""Peewee migrations -- 001_initial_schema.py.
Some examples (model - class or model name)::
> Model = migrator.orm['table_name'] # Return model in current state by name > Model = migrator.ModelClass # Return model in current state by name
> migrator.sql(sql) # Run custom SQL > migrator.run(func, *args, **kwargs) # Run python function with the given args > migrator.create_model(Model) # Create a model (could be used as decorator) > migrator.remove_model(model, cascade=True) # Remove a model > migrator.add_fields(model, **fields) # Add fields to a model > migrator.change_fields(model, **fields) # Change fields > migrator.remove_fields(model, *field_names, cascade=True) > migrator.rename_field(model, old_field_name, new_field_name) > migrator.rename_table(model, new_table_name) > migrator.add_index(model, *col_names, unique=False) > migrator.add_not_null(model, *field_names) > migrator.add_default(model, field_name, default) > migrator.add_constraint(model, name, sql) > migrator.drop_index(model, *col_names) > migrator.drop_not_null(model, *field_names) > migrator.drop_constraints(model, *constraints)
"""
from contextlib import suppress
import peewee as pwfrom peewee_migrate import Migrator
with suppress(ImportError): import playhouse.postgres_ext as pw_pext
def migrate(migrator: Migrator, database: pw.Database, *, fake=False): """Write your migrations here."""
# We perform different migrations for SQLite and other databases # This is because SQLite is very loose with enforcing its schema, and trying to migrate other databases like SQLite # will require per-database SQL queries. # Instead, we assume that because external DB support was added at a later date, it is safe to assume a newer base # schema instead of trying to migrate from an older schema. if isinstance(database, pw.SqliteDatabase): migrate_sqlite(migrator, database, fake=fake) else: migrate_external(migrator, database, fake=fake)
def migrate_sqlite(migrator: Migrator, database: pw.Database, *, fake=False): @migrator.create_model class Auth(pw.Model): id = pw.CharField(max_length=255, unique=True) email = pw.CharField(max_length=255) password = pw.CharField(max_length=255) active = pw.BooleanField()
class Meta: table_name = "auth"
@migrator.create_model class Chat(pw.Model): id = pw.CharField(max_length=255, unique=True) user_id = pw.CharField(max_length=255) title = pw.CharField() chat = pw.TextField() timestamp = pw.BigIntegerField()
class Meta: table_name = "chat"
@migrator.create_model class ChatIdTag(pw.Model): id = pw.CharField(max_length=255, unique=True) tag_name = pw.CharField(max_length=255) chat_id = pw.CharField(max_length=255) user_id = pw.CharField(max_length=255) timestamp = pw.BigIntegerField()
class Meta: table_name = "chatidtag"
@migrator.create_model class Document(pw.Model): id = pw.AutoField() collection_name = pw.CharField(max_length=255, unique=True) name = pw.CharField(max_length=255, unique=True) title = pw.CharField() filename = pw.CharField() content = pw.TextField(null=True) user_id = pw.CharField(max_length=255) timestamp = pw.BigIntegerField()
class Meta: table_name = "document"
@migrator.create_model class Modelfile(pw.Model): id = pw.AutoField() tag_name = pw.CharField(max_length=255, unique=True) user_id = pw.CharField(max_length=255) modelfile = pw.TextField() timestamp = pw.BigIntegerField()
class Meta: table_name = "modelfile"
@migrator.create_model class Prompt(pw.Model): id = pw.AutoField() command = pw.CharField(max_length=255, unique=True) user_id = pw.CharField(max_length=255) title = pw.CharField() content = pw.TextField() timestamp = pw.BigIntegerField()
class Meta: table_name = "prompt"
@migrator.create_model class Tag(pw.Model): id = pw.CharField(max_length=255, unique=True) name = pw.CharField(max_length=255) user_id = pw.CharField(max_length=255) data = pw.TextField(null=True)
class Meta: table_name = "tag"
@migrator.create_model class User(pw.Model): id = pw.CharField(max_length=255, unique=True) name = pw.CharField(max_length=255) email = pw.CharField(max_length=255) role = pw.CharField(max_length=255) profile_image_url = pw.CharField(max_length=255) timestamp = pw.BigIntegerField()
class Meta: table_name = "user"
def migrate_external(migrator: Migrator, database: pw.Database, *, fake=False): @migrator.create_model class Auth(pw.Model): id = pw.CharField(max_length=255, unique=True) email = pw.CharField(max_length=255) password = pw.TextField() active = pw.BooleanField()
class Meta: table_name = "auth"
@migrator.create_model class Chat(pw.Model): id = pw.CharField(max_length=255, unique=True) user_id = pw.CharField(max_length=255) title = pw.TextField() chat = pw.TextField() timestamp = pw.BigIntegerField()
class Meta: table_name = "chat"
@migrator.create_model class ChatIdTag(pw.Model): id = pw.CharField(max_length=255, unique=True) tag_name = pw.CharField(max_length=255) chat_id = pw.CharField(max_length=255) user_id = pw.CharField(max_length=255) timestamp = pw.BigIntegerField()
class Meta: table_name = "chatidtag"
@migrator.create_model class Document(pw.Model): id = pw.AutoField() collection_name = pw.CharField(max_length=255, unique=True) name = pw.CharField(max_length=255, unique=True) title = pw.TextField() filename = pw.TextField() content = pw.TextField(null=True) user_id = pw.CharField(max_length=255) timestamp = pw.BigIntegerField()
class Meta: table_name = "document"
@migrator.create_model class Modelfile(pw.Model): id = pw.AutoField() tag_name = pw.CharField(max_length=255, unique=True) user_id = pw.CharField(max_length=255) modelfile = pw.TextField() timestamp = pw.BigIntegerField()
class Meta: table_name = "modelfile"
@migrator.create_model class Prompt(pw.Model): id = pw.AutoField() command = pw.CharField(max_length=255, unique=True) user_id = pw.CharField(max_length=255) title = pw.TextField() content = pw.TextField() timestamp = pw.BigIntegerField()
class Meta: table_name = "prompt"
@migrator.create_model class Tag(pw.Model): id = pw.CharField(max_length=255, unique=True) name = pw.CharField(max_length=255) user_id = pw.CharField(max_length=255) data = pw.TextField(null=True)
class Meta: table_name = "tag"
@migrator.create_model class User(pw.Model): id = pw.CharField(max_length=255, unique=True) name = pw.CharField(max_length=255) email = pw.CharField(max_length=255) role = pw.CharField(max_length=255) profile_image_url = pw.TextField() timestamp = pw.BigIntegerField()
class Meta: table_name = "user"
def rollback(migrator: Migrator, database: pw.Database, *, fake=False): """Write your rollback migrations here."""
migrator.remove_model("user")
migrator.remove_model("tag")
migrator.remove_model("prompt")
migrator.remove_model("modelfile")
migrator.remove_model("document")
migrator.remove_model("chatidtag")
migrator.remove_model("chat")
migrator.remove_model("auth")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748"""Peewee migrations -- 002_add_local_sharing.py.
Some examples (model - class or model name)::
> Model = migrator.orm['table_name'] # Return model in current state by name > Model = migrator.ModelClass # Return model in current state by name
> migrator.sql(sql) # Run custom SQL > migrator.run(func, *args, **kwargs) # Run python function with the given args > migrator.create_model(Model) # Create a model (could be used as decorator) > migrator.remove_model(model, cascade=True) # Remove a model > migrator.add_fields(model, **fields) # Add fields to a model > migrator.change_fields(model, **fields) # Change fields > migrator.remove_fields(model, *field_names, cascade=True) > migrator.rename_field(model, old_field_name, new_field_name) > migrator.rename_table(model, new_table_name) > migrator.add_index(model, *col_names, unique=False) > migrator.add_not_null(model, *field_names) > migrator.add_default(model, field_name, default) > migrator.add_constraint(model, name, sql) > migrator.drop_index(model, *col_names) > migrator.drop_not_null(model, *field_names) > migrator.drop_constraints(model, *constraints)
"""
from contextlib import suppress
import peewee as pwfrom peewee_migrate import Migrator
with suppress(ImportError): import playhouse.postgres_ext as pw_pext
def migrate(migrator: Migrator, database: pw.Database, *, fake=False): """Write your migrations here."""
migrator.add_fields( "chat", share_id=pw.CharField(max_length=255, null=True, unique=True) )
def rollback(migrator: Migrator, database: pw.Database, *, fake=False): """Write your rollback migrations here."""
migrator.remove_fields("chat", "share_id")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748"""Peewee migrations -- 002_add_local_sharing.py.
Some examples (model - class or model name)::
> Model = migrator.orm['table_name'] # Return model in current state by name > Model = migrator.ModelClass # Return model in current state by name
> migrator.sql(sql) # Run custom SQL > migrator.run(func, *args, **kwargs) # Run python function with the given args > migrator.create_model(Model) # Create a model (could be used as decorator) > migrator.remove_model(model, cascade=True) # Remove a model > migrator.add_fields(model, **fields) # Add fields to a model > migrator.change_fields(model, **fields) # Change fields > migrator.remove_fields(model, *field_names, cascade=True) > migrator.rename_field(model, old_field_name, new_field_name) > migrator.rename_table(model, new_table_name) > migrator.add_index(model, *col_names, unique=False) > migrator.add_not_null(model, *field_names) > migrator.add_default(model, field_name, default) > migrator.add_constraint(model, name, sql) > migrator.drop_index(model, *col_names) > migrator.drop_not_null(model, *field_names) > migrator.drop_constraints(model, *constraints)
"""
from contextlib import suppress
import peewee as pwfrom peewee_migrate import Migrator
with suppress(ImportError): import playhouse.postgres_ext as pw_pext
def migrate(migrator: Migrator, database: pw.Database, *, fake=False): """Write your migrations here."""
migrator.add_fields( "user", api_key=pw.CharField(max_length=255, null=True, unique=True) )
def rollback(migrator: Migrator, database: pw.Database, *, fake=False): """Write your rollback migrations here."""
migrator.remove_fields("user", "api_key")12345678910111213141516171819202122232425262728293031323334353637383940414243444546"""Peewee migrations -- 002_add_local_sharing.py.
Some examples (model - class or model name)::
> Model = migrator.orm['table_name'] # Return model in current state by name > Model = migrator.ModelClass # Return model in current state by name
> migrator.sql(sql) # Run custom SQL > migrator.run(func, *args, **kwargs) # Run python function with the given args > migrator.create_model(Model) # Create a model (could be used as decorator) > migrator.remove_model(model, cascade=True) # Remove a model > migrator.add_fields(model, **fields) # Add fields to a model > migrator.change_fields(model, **fields) # Change fields > migrator.remove_fields(model, *field_names, cascade=True) > migrator.rename_field(model, old_field_name, new_field_name) > migrator.rename_table(model, new_table_name) > migrator.add_index(model, *col_names, unique=False) > migrator.add_not_null(model, *field_names) > migrator.add_default(model, field_name, default) > migrator.add_constraint(model, name, sql) > migrator.drop_index(model, *col_names) > migrator.drop_not_null(model, *field_names) > migrator.drop_constraints(model, *constraints)
"""
from contextlib import suppress
import peewee as pwfrom peewee_migrate import Migrator
with suppress(ImportError): import playhouse.postgres_ext as pw_pext
def migrate(migrator: Migrator, database: pw.Database, *, fake=False): """Write your migrations here."""
migrator.add_fields("chat", archived=pw.BooleanField(default=False))
def rollback(migrator: Migrator, database: pw.Database, *, fake=False): """Write your rollback migrations here."""
migrator.remove_fields("chat", "archived")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130"""Peewee migrations -- 002_add_local_sharing.py.
Some examples (model - class or model name)::
> Model = migrator.orm['table_name'] # Return model in current state by name > Model = migrator.ModelClass # Return model in current state by name
> migrator.sql(sql) # Run custom SQL > migrator.run(func, *args, **kwargs) # Run python function with the given args > migrator.create_model(Model) # Create a model (could be used as decorator) > migrator.remove_model(model, cascade=True) # Remove a model > migrator.add_fields(model, **fields) # Add fields to a model > migrator.change_fields(model, **fields) # Change fields > migrator.remove_fields(model, *field_names, cascade=True) > migrator.rename_field(model, old_field_name, new_field_name) > migrator.rename_table(model, new_table_name) > migrator.add_index(model, *col_names, unique=False) > migrator.add_not_null(model, *field_names) > migrator.add_default(model, field_name, default) > migrator.add_constraint(model, name, sql) > migrator.drop_index(model, *col_names) > migrator.drop_not_null(model, *field_names) > migrator.drop_constraints(model, *constraints)
"""
from contextlib import suppress
import peewee as pwfrom peewee_migrate import Migrator
with suppress(ImportError): import playhouse.postgres_ext as pw_pext
def migrate(migrator: Migrator, database: pw.Database, *, fake=False): """Write your migrations here."""
if isinstance(database, pw.SqliteDatabase): migrate_sqlite(migrator, database, fake=fake) else: migrate_external(migrator, database, fake=fake)
def migrate_sqlite(migrator: Migrator, database: pw.Database, *, fake=False): # Adding fields created_at and updated_at to the 'chat' table migrator.add_fields( "chat", created_at=pw.DateTimeField(null=True), # Allow null for transition updated_at=pw.DateTimeField(null=True), # Allow null for transition )
# Populate the new fields from an existing 'timestamp' field migrator.sql( "UPDATE chat SET created_at = timestamp, updated_at = timestamp WHERE timestamp IS NOT NULL" )
# Now that the data has been copied, remove the original 'timestamp' field migrator.remove_fields("chat", "timestamp")
# Update the fields to be not null now that they are populated migrator.change_fields( "chat", created_at=pw.DateTimeField(null=False), updated_at=pw.DateTimeField(null=False), )
def migrate_external(migrator: Migrator, database: pw.Database, *, fake=False): # Adding fields created_at and updated_at to the 'chat' table migrator.add_fields( "chat", created_at=pw.BigIntegerField(null=True), # Allow null for transition updated_at=pw.BigIntegerField(null=True), # Allow null for transition )
# Populate the new fields from an existing 'timestamp' field migrator.sql( "UPDATE chat SET created_at = timestamp, updated_at = timestamp WHERE timestamp IS NOT NULL" )
# Now that the data has been copied, remove the original 'timestamp' field migrator.remove_fields("chat", "timestamp")
# Update the fields to be not null now that they are populated migrator.change_fields( "chat", created_at=pw.BigIntegerField(null=False), updated_at=pw.BigIntegerField(null=False), )
def rollback(migrator: Migrator, database: pw.Database, *, fake=False): """Write your rollback migrations here."""
if isinstance(database, pw.SqliteDatabase): rollback_sqlite(migrator, database, fake=fake) else: rollback_external(migrator, database, fake=fake)
def rollback_sqlite(migrator: Migrator, database: pw.Database, *, fake=False): # Recreate the timestamp field initially allowing null values for safe transition migrator.add_fields("chat", timestamp=pw.DateTimeField(null=True))
# Copy the earliest created_at date back into the new timestamp field # This assumes created_at was originally a copy of timestamp migrator.sql("UPDATE chat SET timestamp = created_at")
# Remove the created_at and updated_at fields migrator.remove_fields("chat", "created_at", "updated_at")
# Finally, alter the timestamp field to not allow nulls if that was the original setting migrator.change_fields("chat", timestamp=pw.DateTimeField(null=False))
def rollback_external(migrator: Migrator, database: pw.Database, *, fake=False): # Recreate the timestamp field initially allowing null values for safe transition migrator.add_fields("chat", timestamp=pw.BigIntegerField(null=True))
# Copy the earliest created_at date back into the new timestamp field # This assumes created_at was originally a copy of timestamp migrator.sql("UPDATE chat SET timestamp = created_at")
# Remove the created_at and updated_at fields migrator.remove_fields("chat", "created_at", "updated_at")
# Finally, alter the timestamp field to not allow nulls if that was the original setting migrator.change_fields("chat", timestamp=pw.BigIntegerField(null=False)).dockerignoreAdded+20
.env.exampleAdded+22
.eslintignoreAdded+13
.eslintrc.cjsAdded+31
.gitattributesAdded+42
.github/FUNDING.ymlAdded+1
.github/ISSUE_TEMPLATE/bug_report.yamlAdded+176
.github/ISSUE_TEMPLATE/config.ymlAdded+1
.github/ISSUE_TEMPLATE/feature_request.yamlAdded+82
.github/dependabot.ymlAdded+20
.github/pull_request_template.mdAdded+82
.github/workflows/build-release.ymlAdded+72
.github/workflows/codespell.disabledAdded+25
.github/workflows/deploy-to-hf-spaces.ymlAdded+63
.github/workflows/docker-build.yamlAdded+806
.github/workflows/format-backend.yamlAdded+49
.github/workflows/format-build-frontend.yamlAdded+65
.github/workflows/integration-test.disabledAdded+255
.github/workflows/lint-backend.disabledAdded+27
.github/workflows/lint-frontend.disabledAdded+21
.github/workflows/release-pypi.ymlAdded+36
.gitignoreAdded+312
.npmrcAdded+1
.prettierignoreAdded+314
.prettierrcAdded+10
CHANGELOG.mdAdded
CODE_OF_CONDUCT.mdAdded+99
CONTRIBUTOR_LICENSE_AGREEMENTAdded+7
DockerfileAdded+194
LICENSEAdded+33
LICENSE_HISTORYAdded+53
LICENSE_NOTICEAdded+11
MakefileAdded+33
README.mdAdded+245
TROUBLESHOOTING.mdAdded+36
backend/.dockerignoreAdded+14
backend/.gitignoreAdded+12
backend/dev.shAdded+3
backend/open_webui/__init__.pyAdded+103
backend/open_webui/alembic.iniAdded+114
backend/open_webui/config.pyAdded
backend/open_webui/constants.pyAdded+126
backend/open_webui/env.pyAdded+877
backend/open_webui/functions.pyAdded+352
backend/open_webui/internal/db.pyAdded+162
backend/open_webui/internal/migrations/001_initial_schema.pyAdded+254
backend/open_webui/internal/migrations/002_add_local_sharing.pyAdded+48
backend/open_webui/internal/migrations/003_add_auth_api_key.pyAdded+48
backend/open_webui/internal/migrations/004_add_archived.pyAdded+46
backend/open_webui/internal/migrations/005_add_updated_at.pyAdded+130