github-actions[bot] commited on
Commit
4c3ddbb
0 Parent(s):

GitHub deploy: 8345bb55d4f0266b504bcd1c014f448b82d94527

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .dockerignore +18 -0
  2. .env.example +13 -0
  3. .eslintignore +13 -0
  4. .eslintrc.cjs +31 -0
  5. .gitattributes +2 -0
  6. .github/FUNDING.yml +1 -0
  7. .github/ISSUE_TEMPLATE/bug_report.md +63 -0
  8. .github/ISSUE_TEMPLATE/feature_request.md +19 -0
  9. .github/dependabot.disabled +11 -0
  10. .github/pull_request_template.md +72 -0
  11. .github/workflows/build-release.yml +70 -0
  12. .github/workflows/deploy-to-hf-spaces.yml +59 -0
  13. .github/workflows/docker-build.yaml +478 -0
  14. .github/workflows/format-backend.yaml +39 -0
  15. .github/workflows/format-build-frontend.yaml +57 -0
  16. .github/workflows/integration-test.yml +217 -0
  17. .github/workflows/lint-backend.disabled +27 -0
  18. .github/workflows/lint-frontend.disabled +21 -0
  19. .github/workflows/release-pypi.yml +31 -0
  20. .gitignore +308 -0
  21. .npmrc +1 -0
  22. .prettierignore +316 -0
  23. .prettierrc +9 -0
  24. CHANGELOG.md +632 -0
  25. CODE_OF_CONDUCT.md +77 -0
  26. Caddyfile.localhost +64 -0
  27. Dockerfile +159 -0
  28. INSTALLATION.md +35 -0
  29. LICENSE +21 -0
  30. Makefile +33 -0
  31. README.md +211 -0
  32. TROUBLESHOOTING.md +36 -0
  33. backend/.dockerignore +14 -0
  34. backend/.gitignore +16 -0
  35. backend/apps/audio/main.py +374 -0
  36. backend/apps/images/main.py +547 -0
  37. backend/apps/images/utils/comfyui.py +250 -0
  38. backend/apps/ollama/main.py +1214 -0
  39. backend/apps/openai/main.py +569 -0
  40. backend/apps/rag/main.py +1368 -0
  41. backend/apps/rag/search/brave.py +42 -0
  42. backend/apps/rag/search/duckduckgo.py +49 -0
  43. backend/apps/rag/search/google_pse.py +51 -0
  44. backend/apps/rag/search/main.py +20 -0
  45. backend/apps/rag/search/searxng.py +92 -0
  46. backend/apps/rag/search/serper.py +43 -0
  47. backend/apps/rag/search/serply.py +70 -0
  48. backend/apps/rag/search/serpstack.py +49 -0
  49. backend/apps/rag/search/tavily.py +39 -0
  50. backend/apps/rag/search/testdata/brave.json +998 -0
.dockerignore ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .github
2
+ .DS_Store
3
+ docs
4
+ kubernetes
5
+ node_modules
6
+ /.svelte-kit
7
+ /package
8
+ .env
9
+ .env.*
10
+ vite.config.js.timestamp-*
11
+ vite.config.ts.timestamp-*
12
+ __pycache__
13
+ .env
14
+ _old
15
+ uploads
16
+ .ipynb_checkpoints
17
+ **/*.db
18
+ _test
.env.example ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ollama URL for the backend to connect
2
+ # The path '/ollama' will be redirected to the specified backend URL
3
+ OLLAMA_BASE_URL='http://localhost:11434'
4
+
5
+ OPENAI_API_BASE_URL=''
6
+ OPENAI_API_KEY=''
7
+
8
+ # AUTOMATIC1111_BASE_URL="http://localhost:7860"
9
+
10
+ # DO NOT TRACK
11
+ SCARF_NO_ANALYTICS=true
12
+ DO_NOT_TRACK=true
13
+ ANONYMIZED_TELEMETRY=false
.eslintignore ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+
10
+ # Ignore files for PNPM, NPM and YARN
11
+ pnpm-lock.yaml
12
+ package-lock.json
13
+ yarn.lock
.eslintrc.cjs ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = {
2
+ root: true,
3
+ extends: [
4
+ 'eslint:recommended',
5
+ 'plugin:@typescript-eslint/recommended',
6
+ 'plugin:svelte/recommended',
7
+ 'plugin:cypress/recommended',
8
+ 'prettier'
9
+ ],
10
+ parser: '@typescript-eslint/parser',
11
+ plugins: ['@typescript-eslint'],
12
+ parserOptions: {
13
+ sourceType: 'module',
14
+ ecmaVersion: 2020,
15
+ extraFileExtensions: ['.svelte']
16
+ },
17
+ env: {
18
+ browser: true,
19
+ es2017: true,
20
+ node: true
21
+ },
22
+ overrides: [
23
+ {
24
+ files: ['*.svelte'],
25
+ parser: 'svelte-eslint-parser',
26
+ parserOptions: {
27
+ parser: '@typescript-eslint/parser'
28
+ }
29
+ }
30
+ ]
31
+ };
.gitattributes ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *.sh text eol=lf
2
+ *.ttf filter=lfs diff=lfs merge=lfs -text
.github/FUNDING.yml ADDED
@@ -0,0 +1 @@
 
 
1
+ github: tjbck
.github/ISSUE_TEMPLATE/bug_report.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+ ---
8
+
9
+ # Bug Report
10
+
11
+ ## Description
12
+
13
+ **Bug Summary:**
14
+ [Provide a brief but clear summary of the bug]
15
+
16
+ **Steps to Reproduce:**
17
+ [Outline the steps to reproduce the bug. Be as detailed as possible.]
18
+
19
+ **Expected Behavior:**
20
+ [Describe what you expected to happen.]
21
+
22
+ **Actual Behavior:**
23
+ [Describe what actually happened.]
24
+
25
+ ## Environment
26
+
27
+ - **Open WebUI Version:** [e.g., 0.1.120]
28
+ - **Ollama (if applicable):** [e.g., 0.1.30, 0.1.32-rc1]
29
+
30
+ - **Operating System:** [e.g., Windows 10, macOS Big Sur, Ubuntu 20.04]
31
+ - **Browser (if applicable):** [e.g., Chrome 100.0, Firefox 98.0]
32
+
33
+ ## Reproduction Details
34
+
35
+ **Confirmation:**
36
+
37
+ - [ ] I have read and followed all the instructions provided in the README.md.
38
+ - [ ] I am on the latest version of both Open WebUI and Ollama.
39
+ - [ ] I have included the browser console logs.
40
+ - [ ] I have included the Docker container logs.
41
+
42
+ ## Logs and Screenshots
43
+
44
+ **Browser Console Logs:**
45
+ [Include relevant browser console logs, if applicable]
46
+
47
+ **Docker Container Logs:**
48
+ [Include relevant Docker container logs, if applicable]
49
+
50
+ **Screenshots (if applicable):**
51
+ [Attach any relevant screenshots to help illustrate the issue]
52
+
53
+ ## Installation Method
54
+
55
+ [Describe the method you used to install the project, e.g., manual installation, Docker, package manager, etc.]
56
+
57
+ ## Additional Information
58
+
59
+ [Include any additional details that may help in understanding and reproducing the issue. This could include specific configurations, error messages, or anything else relevant to the bug.]
60
+
61
+ ## Note
62
+
63
+ If the bug report is incomplete or does not follow the provided instructions, it may not be addressed. Please ensure that you have followed the steps outlined in the README.md and troubleshooting.md documents, and provide all necessary information for us to reproduce and address the issue. Thank you!
.github/ISSUE_TEMPLATE/feature_request.md ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+ ---
8
+
9
+ **Is your feature request related to a problem? Please describe.**
10
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11
+
12
+ **Describe the solution you'd like**
13
+ A clear and concise description of what you want to happen.
14
+
15
+ **Describe alternatives you've considered**
16
+ A clear and concise description of any alternative solutions or features you've considered.
17
+
18
+ **Additional context**
19
+ Add any other context or screenshots about the feature request here.
.github/dependabot.disabled ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: pip
4
+ directory: '/backend'
5
+ schedule:
6
+ interval: weekly
7
+ - package-ecosystem: 'github-actions'
8
+ directory: '/'
9
+ schedule:
10
+ # Check for updates to GitHub Actions every week
11
+ interval: 'weekly'
.github/pull_request_template.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pull Request Checklist
2
+
3
+ ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request.
4
+
5
+ **Before submitting, make sure you've checked the following:**
6
+
7
+ - [ ] **Target branch:** Please verify that the pull request targets the `dev` branch.
8
+ - [ ] **Description:** Provide a concise description of the changes made in this pull request.
9
+ - [ ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
10
+ - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
11
+ - [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
12
+ - [ ] **Testing:** Have you written and run sufficient tests for validating the changes?
13
+ - [ ] **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?
14
+ - [ ] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following:
15
+ - **BREAKING CHANGE**: Significant changes that may affect compatibility
16
+ - **build**: Changes that affect the build system or external dependencies
17
+ - **ci**: Changes to our continuous integration processes or workflows
18
+ - **chore**: Refactor, cleanup, or other non-functional code changes
19
+ - **docs**: Documentation update or addition
20
+ - **feat**: Introduces a new feature or enhancement to the codebase
21
+ - **fix**: Bug fix or error correction
22
+ - **i18n**: Internationalization or localization changes
23
+ - **perf**: Performance improvement
24
+ - **refactor**: Code restructuring for better maintainability, readability, or scalability
25
+ - **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
26
+ - **test**: Adding missing tests or correcting existing tests
27
+ - **WIP**: Work in progress, a temporary label for incomplete or ongoing work
28
+
29
+ # Changelog Entry
30
+
31
+ ### Description
32
+
33
+ - [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)]
34
+
35
+ ### Added
36
+
37
+ - [List any new features, functionalities, or additions]
38
+
39
+ ### Changed
40
+
41
+ - [List any changes, updates, refactorings, or optimizations]
42
+
43
+ ### Deprecated
44
+
45
+ - [List any deprecated functionality or features that have been removed]
46
+
47
+ ### Removed
48
+
49
+ - [List any removed features, files, or functionalities]
50
+
51
+ ### Fixed
52
+
53
+ - [List any fixes, corrections, or bug fixes]
54
+
55
+ ### Security
56
+
57
+ - [List any new or updated security-related changes, including vulnerability fixes]
58
+
59
+ ### Breaking Changes
60
+
61
+ - **BREAKING CHANGE**: [List any breaking changes affecting compatibility or functionality]
62
+
63
+ ---
64
+
65
+ ### Additional Information
66
+
67
+ - [Insert any additional context, notes, or explanations for the changes]
68
+ - [Reference any related issues, commits, or other relevant information]
69
+
70
+ ### Screenshots or Videos
71
+
72
+ - [Attach any relevant screenshots or videos demonstrating the changes]
.github/workflows/build-release.yml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main # or whatever branch you want to use
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout repository
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Check for changes in package.json
17
+ run: |
18
+ git diff --cached --diff-filter=d package.json || {
19
+ echo "No changes to package.json"
20
+ exit 1
21
+ }
22
+
23
+ - name: Get version number from package.json
24
+ id: get_version
25
+ run: |
26
+ VERSION=$(jq -r '.version' package.json)
27
+ echo "::set-output name=version::$VERSION"
28
+
29
+ - name: Extract latest CHANGELOG entry
30
+ id: changelog
31
+ run: |
32
+ CHANGELOG_CONTENT=$(awk 'BEGIN {print_section=0;} /^## \[/ {if (print_section == 0) {print_section=1;} else {exit;}} print_section {print;}' CHANGELOG.md)
33
+ CHANGELOG_ESCAPED=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\n/%0A/g')
34
+ echo "Extracted latest release notes from CHANGELOG.md:"
35
+ echo -e "$CHANGELOG_CONTENT"
36
+ echo "::set-output name=content::$CHANGELOG_ESCAPED"
37
+
38
+ - name: Create GitHub release
39
+ uses: actions/github-script@v7
40
+ with:
41
+ github-token: ${{ secrets.GITHUB_TOKEN }}
42
+ script: |
43
+ const changelog = `${{ steps.changelog.outputs.content }}`;
44
+ const release = await github.rest.repos.createRelease({
45
+ owner: context.repo.owner,
46
+ repo: context.repo.repo,
47
+ tag_name: `v${{ steps.get_version.outputs.version }}`,
48
+ name: `v${{ steps.get_version.outputs.version }}`,
49
+ body: changelog,
50
+ })
51
+ console.log(`Created release ${release.data.html_url}`)
52
+
53
+ - name: Upload package to GitHub release
54
+ uses: actions/upload-artifact@v4
55
+ with:
56
+ name: package
57
+ path: .
58
+ env:
59
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60
+
61
+ - name: Trigger Docker build workflow
62
+ uses: actions/github-script@v7
63
+ with:
64
+ script: |
65
+ github.rest.actions.createWorkflowDispatch({
66
+ owner: context.repo.owner,
67
+ repo: context.repo.repo,
68
+ workflow_id: 'docker-build.yaml',
69
+ ref: 'v${{ steps.get_version.outputs.version }}',
70
+ })
.github/workflows/deploy-to-hf-spaces.yml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deploy to HuggingFace Spaces
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - dev
7
+ - main
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ check-secret:
12
+ runs-on: ubuntu-latest
13
+ outputs:
14
+ token-set: ${{ steps.check-key.outputs.defined }}
15
+ steps:
16
+ - id: check-key
17
+ env:
18
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
+ if: "${{ env.HF_TOKEN != '' }}"
20
+ run: echo "defined=true" >> $GITHUB_OUTPUT
21
+
22
+ deploy:
23
+ runs-on: ubuntu-latest
24
+ needs: [check-secret]
25
+ if: needs.check-secret.outputs.token-set == 'true'
26
+ env:
27
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
28
+ steps:
29
+ - name: Checkout repository
30
+ uses: actions/checkout@v4
31
+
32
+ - name: Remove git history
33
+ run: rm -rf .git
34
+
35
+ - name: Prepend YAML front matter to README.md
36
+ run: |
37
+ echo "---" > temp_readme.md
38
+ echo "title: Open WebUI" >> temp_readme.md
39
+ echo "emoji: 🐳" >> temp_readme.md
40
+ echo "colorFrom: purple" >> temp_readme.md
41
+ echo "colorTo: gray" >> temp_readme.md
42
+ echo "sdk: docker" >> temp_readme.md
43
+ echo "app_port: 8080" >> temp_readme.md
44
+ echo "---" >> temp_readme.md
45
+ cat README.md >> temp_readme.md
46
+ mv temp_readme.md README.md
47
+
48
+ - name: Configure git
49
+ run: |
50
+ git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
51
+ git config --global user.name "github-actions[bot]"
52
+ - name: Set up Git and push to Space
53
+ run: |
54
+ git init --initial-branch=main
55
+ git lfs track "*.ttf"
56
+ rm demo.gif
57
+ git add .
58
+ git commit -m "GitHub deploy: ${{ github.sha }}"
59
+ git push --force https://open-webui:${HF_TOKEN}@huggingface.co/spaces/open-webui/open-webui main
.github/workflows/docker-build.yaml ADDED
@@ -0,0 +1,478 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Create and publish Docker images with specific build args
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - main
8
+ - dev
9
+ tags:
10
+ - v*
11
+
12
+ env:
13
+ REGISTRY: ghcr.io
14
+
15
+ jobs:
16
+ build-main-image:
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ contents: read
20
+ packages: write
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ platform:
25
+ - linux/amd64
26
+ - linux/arm64
27
+
28
+ steps:
29
+ # GitHub Packages requires the entire repository name to be in lowercase
30
+ # although the repository owner has a lowercase username, this prevents some people from running actions after forking
31
+ - name: Set repository and image name to lowercase
32
+ run: |
33
+ echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
34
+ echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
35
+ env:
36
+ IMAGE_NAME: '${{ github.repository }}'
37
+
38
+ - name: Prepare
39
+ run: |
40
+ platform=${{ matrix.platform }}
41
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
42
+
43
+ - name: Checkout repository
44
+ uses: actions/checkout@v4
45
+
46
+ - name: Set up QEMU
47
+ uses: docker/setup-qemu-action@v3
48
+
49
+ - name: Set up Docker Buildx
50
+ uses: docker/setup-buildx-action@v3
51
+
52
+ - name: Log in to the Container registry
53
+ uses: docker/login-action@v3
54
+ with:
55
+ registry: ${{ env.REGISTRY }}
56
+ username: ${{ github.actor }}
57
+ password: ${{ secrets.GITHUB_TOKEN }}
58
+
59
+ - name: Extract metadata for Docker images (default latest tag)
60
+ id: meta
61
+ uses: docker/metadata-action@v5
62
+ with:
63
+ images: ${{ env.FULL_IMAGE_NAME }}
64
+ tags: |
65
+ type=ref,event=branch
66
+ type=ref,event=tag
67
+ type=sha,prefix=git-
68
+ type=semver,pattern={{version}}
69
+ type=semver,pattern={{major}}.{{minor}}
70
+ flavor: |
71
+ latest=${{ github.ref == 'refs/heads/main' }}
72
+
73
+ - name: Extract metadata for Docker cache
74
+ id: cache-meta
75
+ uses: docker/metadata-action@v5
76
+ with:
77
+ images: ${{ env.FULL_IMAGE_NAME }}
78
+ tags: |
79
+ type=ref,event=branch
80
+ ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }}
81
+ flavor: |
82
+ prefix=cache-${{ matrix.platform }}-
83
+ latest=false
84
+
85
+ - name: Build Docker image (latest)
86
+ uses: docker/build-push-action@v5
87
+ id: build
88
+ with:
89
+ context: .
90
+ push: true
91
+ platforms: ${{ matrix.platform }}
92
+ labels: ${{ steps.meta.outputs.labels }}
93
+ outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
94
+ cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
95
+ cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
96
+ build-args: |
97
+ BUILD_HASH=${{ github.sha }}
98
+
99
+ - name: Export digest
100
+ run: |
101
+ mkdir -p /tmp/digests
102
+ digest="${{ steps.build.outputs.digest }}"
103
+ touch "/tmp/digests/${digest#sha256:}"
104
+
105
+ - name: Upload digest
106
+ uses: actions/upload-artifact@v4
107
+ with:
108
+ name: digests-main-${{ env.PLATFORM_PAIR }}
109
+ path: /tmp/digests/*
110
+ if-no-files-found: error
111
+ retention-days: 1
112
+
113
+ build-cuda-image:
114
+ runs-on: ubuntu-latest
115
+ permissions:
116
+ contents: read
117
+ packages: write
118
+ strategy:
119
+ fail-fast: false
120
+ matrix:
121
+ platform:
122
+ - linux/amd64
123
+ - linux/arm64
124
+
125
+ steps:
126
+ # GitHub Packages requires the entire repository name to be in lowercase
127
+ # although the repository owner has a lowercase username, this prevents some people from running actions after forking
128
+ - name: Set repository and image name to lowercase
129
+ run: |
130
+ echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
131
+ echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
132
+ env:
133
+ IMAGE_NAME: '${{ github.repository }}'
134
+
135
+ - name: Prepare
136
+ run: |
137
+ platform=${{ matrix.platform }}
138
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
139
+
140
+ - name: Checkout repository
141
+ uses: actions/checkout@v4
142
+
143
+ - name: Set up QEMU
144
+ uses: docker/setup-qemu-action@v3
145
+
146
+ - name: Set up Docker Buildx
147
+ uses: docker/setup-buildx-action@v3
148
+
149
+ - name: Log in to the Container registry
150
+ uses: docker/login-action@v3
151
+ with:
152
+ registry: ${{ env.REGISTRY }}
153
+ username: ${{ github.actor }}
154
+ password: ${{ secrets.GITHUB_TOKEN }}
155
+
156
+ - name: Extract metadata for Docker images (cuda tag)
157
+ id: meta
158
+ uses: docker/metadata-action@v5
159
+ with:
160
+ images: ${{ env.FULL_IMAGE_NAME }}
161
+ tags: |
162
+ type=ref,event=branch
163
+ type=ref,event=tag
164
+ type=sha,prefix=git-
165
+ type=semver,pattern={{version}}
166
+ type=semver,pattern={{major}}.{{minor}}
167
+ type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda
168
+ flavor: |
169
+ latest=${{ github.ref == 'refs/heads/main' }}
170
+ suffix=-cuda,onlatest=true
171
+
172
+ - name: Extract metadata for Docker cache
173
+ id: cache-meta
174
+ uses: docker/metadata-action@v5
175
+ with:
176
+ images: ${{ env.FULL_IMAGE_NAME }}
177
+ tags: |
178
+ type=ref,event=branch
179
+ ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }}
180
+ flavor: |
181
+ prefix=cache-cuda-${{ matrix.platform }}-
182
+ latest=false
183
+
184
+ - name: Build Docker image (cuda)
185
+ uses: docker/build-push-action@v5
186
+ id: build
187
+ with:
188
+ context: .
189
+ push: true
190
+ platforms: ${{ matrix.platform }}
191
+ labels: ${{ steps.meta.outputs.labels }}
192
+ outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
193
+ cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
194
+ cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
195
+ build-args: |
196
+ BUILD_HASH=${{ github.sha }}
197
+ USE_CUDA=true
198
+
199
+ - name: Export digest
200
+ run: |
201
+ mkdir -p /tmp/digests
202
+ digest="${{ steps.build.outputs.digest }}"
203
+ touch "/tmp/digests/${digest#sha256:}"
204
+
205
+ - name: Upload digest
206
+ uses: actions/upload-artifact@v4
207
+ with:
208
+ name: digests-cuda-${{ env.PLATFORM_PAIR }}
209
+ path: /tmp/digests/*
210
+ if-no-files-found: error
211
+ retention-days: 1
212
+
213
+ build-ollama-image:
214
+ runs-on: ubuntu-latest
215
+ permissions:
216
+ contents: read
217
+ packages: write
218
+ strategy:
219
+ fail-fast: false
220
+ matrix:
221
+ platform:
222
+ - linux/amd64
223
+ - linux/arm64
224
+
225
+ steps:
226
+ # GitHub Packages requires the entire repository name to be in lowercase
227
+ # although the repository owner has a lowercase username, this prevents some people from running actions after forking
228
+ - name: Set repository and image name to lowercase
229
+ run: |
230
+ echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
231
+ echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
232
+ env:
233
+ IMAGE_NAME: '${{ github.repository }}'
234
+
235
+ - name: Prepare
236
+ run: |
237
+ platform=${{ matrix.platform }}
238
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
239
+
240
+ - name: Checkout repository
241
+ uses: actions/checkout@v4
242
+
243
+ - name: Set up QEMU
244
+ uses: docker/setup-qemu-action@v3
245
+
246
+ - name: Set up Docker Buildx
247
+ uses: docker/setup-buildx-action@v3
248
+
249
+ - name: Log in to the Container registry
250
+ uses: docker/login-action@v3
251
+ with:
252
+ registry: ${{ env.REGISTRY }}
253
+ username: ${{ github.actor }}
254
+ password: ${{ secrets.GITHUB_TOKEN }}
255
+
256
+ - name: Extract metadata for Docker images (ollama tag)
257
+ id: meta
258
+ uses: docker/metadata-action@v5
259
+ with:
260
+ images: ${{ env.FULL_IMAGE_NAME }}
261
+ tags: |
262
+ type=ref,event=branch
263
+ type=ref,event=tag
264
+ type=sha,prefix=git-
265
+ type=semver,pattern={{version}}
266
+ type=semver,pattern={{major}}.{{minor}}
267
+ type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama
268
+ flavor: |
269
+ latest=${{ github.ref == 'refs/heads/main' }}
270
+ suffix=-ollama,onlatest=true
271
+
272
+ - name: Extract metadata for Docker cache
273
+ id: cache-meta
274
+ uses: docker/metadata-action@v5
275
+ with:
276
+ images: ${{ env.FULL_IMAGE_NAME }}
277
+ tags: |
278
+ type=ref,event=branch
279
+ ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }}
280
+ flavor: |
281
+ prefix=cache-ollama-${{ matrix.platform }}-
282
+ latest=false
283
+
284
+ - name: Build Docker image (ollama)
285
+ uses: docker/build-push-action@v5
286
+ id: build
287
+ with:
288
+ context: .
289
+ push: true
290
+ platforms: ${{ matrix.platform }}
291
+ labels: ${{ steps.meta.outputs.labels }}
292
+ outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
293
+ cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
294
+ cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
295
+ build-args: |
296
+ BUILD_HASH=${{ github.sha }}
297
+ USE_OLLAMA=true
298
+
299
+ - name: Export digest
300
+ run: |
301
+ mkdir -p /tmp/digests
302
+ digest="${{ steps.build.outputs.digest }}"
303
+ touch "/tmp/digests/${digest#sha256:}"
304
+
305
+ - name: Upload digest
306
+ uses: actions/upload-artifact@v4
307
+ with:
308
+ name: digests-ollama-${{ env.PLATFORM_PAIR }}
309
+ path: /tmp/digests/*
310
+ if-no-files-found: error
311
+ retention-days: 1
312
+
313
+ merge-main-images:
314
+ runs-on: ubuntu-latest
315
+ needs: [ build-main-image ]
316
+ steps:
317
+ # GitHub Packages requires the entire repository name to be in lowercase
318
+ # although the repository owner has a lowercase username, this prevents some people from running actions after forking
319
+ - name: Set repository and image name to lowercase
320
+ run: |
321
+ echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
322
+ echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
323
+ env:
324
+ IMAGE_NAME: '${{ github.repository }}'
325
+
326
+ - name: Download digests
327
+ uses: actions/download-artifact@v4
328
+ with:
329
+ pattern: digests-main-*
330
+ path: /tmp/digests
331
+ merge-multiple: true
332
+
333
+ - name: Set up Docker Buildx
334
+ uses: docker/setup-buildx-action@v3
335
+
336
+ - name: Log in to the Container registry
337
+ uses: docker/login-action@v3
338
+ with:
339
+ registry: ${{ env.REGISTRY }}
340
+ username: ${{ github.actor }}
341
+ password: ${{ secrets.GITHUB_TOKEN }}
342
+
343
+ - name: Extract metadata for Docker images (default latest tag)
344
+ id: meta
345
+ uses: docker/metadata-action@v5
346
+ with:
347
+ images: ${{ env.FULL_IMAGE_NAME }}
348
+ tags: |
349
+ type=ref,event=branch
350
+ type=ref,event=tag
351
+ type=sha,prefix=git-
352
+ type=semver,pattern={{version}}
353
+ type=semver,pattern={{major}}.{{minor}}
354
+ flavor: |
355
+ latest=${{ github.ref == 'refs/heads/main' }}
356
+
357
+ - name: Create manifest list and push
358
+ working-directory: /tmp/digests
359
+ run: |
360
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
361
+ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
362
+
363
+ - name: Inspect image
364
+ run: |
365
+ docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
366
+
367
+
368
+ merge-cuda-images:
369
+ runs-on: ubuntu-latest
370
+ needs: [ build-cuda-image ]
371
+ steps:
372
+ # GitHub Packages requires the entire repository name to be in lowercase
373
+ # although the repository owner has a lowercase username, this prevents some people from running actions after forking
374
+ - name: Set repository and image name to lowercase
375
+ run: |
376
+ echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
377
+ echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
378
+ env:
379
+ IMAGE_NAME: '${{ github.repository }}'
380
+
381
+ - name: Download digests
382
+ uses: actions/download-artifact@v4
383
+ with:
384
+ pattern: digests-cuda-*
385
+ path: /tmp/digests
386
+ merge-multiple: true
387
+
388
+ - name: Set up Docker Buildx
389
+ uses: docker/setup-buildx-action@v3
390
+
391
+ - name: Log in to the Container registry
392
+ uses: docker/login-action@v3
393
+ with:
394
+ registry: ${{ env.REGISTRY }}
395
+ username: ${{ github.actor }}
396
+ password: ${{ secrets.GITHUB_TOKEN }}
397
+
398
+ - name: Extract metadata for Docker images (default latest tag)
399
+ id: meta
400
+ uses: docker/metadata-action@v5
401
+ with:
402
+ images: ${{ env.FULL_IMAGE_NAME }}
403
+ tags: |
404
+ type=ref,event=branch
405
+ type=ref,event=tag
406
+ type=sha,prefix=git-
407
+ type=semver,pattern={{version}}
408
+ type=semver,pattern={{major}}.{{minor}}
409
+ type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda
410
+ flavor: |
411
+ latest=${{ github.ref == 'refs/heads/main' }}
412
+ suffix=-cuda,onlatest=true
413
+
414
+ - name: Create manifest list and push
415
+ working-directory: /tmp/digests
416
+ run: |
417
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
418
+ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
419
+
420
+ - name: Inspect image
421
+ run: |
422
+ docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
423
+
424
+ merge-ollama-images:
425
+ runs-on: ubuntu-latest
426
+ needs: [ build-ollama-image ]
427
+ steps:
428
+ # GitHub Packages requires the entire repository name to be in lowercase
429
+ # although the repository owner has a lowercase username, this prevents some people from running actions after forking
430
+ - name: Set repository and image name to lowercase
431
+ run: |
432
+ echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
433
+ echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
434
+ env:
435
+ IMAGE_NAME: '${{ github.repository }}'
436
+
437
+ - name: Download digests
438
+ uses: actions/download-artifact@v4
439
+ with:
440
+ pattern: digests-ollama-*
441
+ path: /tmp/digests
442
+ merge-multiple: true
443
+
444
+ - name: Set up Docker Buildx
445
+ uses: docker/setup-buildx-action@v3
446
+
447
+ - name: Log in to the Container registry
448
+ uses: docker/login-action@v3
449
+ with:
450
+ registry: ${{ env.REGISTRY }}
451
+ username: ${{ github.actor }}
452
+ password: ${{ secrets.GITHUB_TOKEN }}
453
+
454
+ - name: Extract metadata for Docker images (default ollama tag)
455
+ id: meta
456
+ uses: docker/metadata-action@v5
457
+ with:
458
+ images: ${{ env.FULL_IMAGE_NAME }}
459
+ tags: |
460
+ type=ref,event=branch
461
+ type=ref,event=tag
462
+ type=sha,prefix=git-
463
+ type=semver,pattern={{version}}
464
+ type=semver,pattern={{major}}.{{minor}}
465
+ type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama
466
+ flavor: |
467
+ latest=${{ github.ref == 'refs/heads/main' }}
468
+ suffix=-ollama,onlatest=true
469
+
470
+ - name: Create manifest list and push
471
+ working-directory: /tmp/digests
472
+ run: |
473
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
474
+ $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
475
+
476
+ - name: Inspect image
477
+ run: |
478
+ docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
.github/workflows/format-backend.yaml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Python CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - dev
8
+ pull_request:
9
+ branches:
10
+ - main
11
+ - dev
12
+
13
+ jobs:
14
+ build:
15
+ name: 'Format Backend'
16
+ runs-on: ubuntu-latest
17
+
18
+ strategy:
19
+ matrix:
20
+ python-version: [3.11]
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - name: Set up Python
26
+ uses: actions/setup-python@v4
27
+ with:
28
+ python-version: ${{ matrix.python-version }}
29
+
30
+ - name: Install dependencies
31
+ run: |
32
+ python -m pip install --upgrade pip
33
+ pip install black
34
+
35
+ - name: Format backend
36
+ run: npm run format:backend
37
+
38
+ - name: Check for changes after format
39
+ run: git diff --exit-code
.github/workflows/format-build-frontend.yaml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Frontend Build
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - dev
8
+ pull_request:
9
+ branches:
10
+ - main
11
+ - dev
12
+
13
+ jobs:
14
+ build:
15
+ name: 'Format & Build Frontend'
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - name: Checkout Repository
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Setup Node.js
22
+ uses: actions/setup-node@v4
23
+ with:
24
+ node-version: '20' # Or specify any other version you want to use
25
+
26
+ - name: Install Dependencies
27
+ run: npm install
28
+
29
+ - name: Format Frontend
30
+ run: npm run format
31
+
32
+ - name: Run i18next
33
+ run: npm run i18n:parse
34
+
35
+ - name: Check for Changes After Format
36
+ run: git diff --exit-code
37
+
38
+ - name: Build Frontend
39
+ run: npm run build
40
+
41
+ test-frontend:
42
+ name: 'Frontend Unit Tests'
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - name: Checkout Repository
46
+ uses: actions/checkout@v4
47
+
48
+ - name: Setup Node.js
49
+ uses: actions/setup-node@v4
50
+ with:
51
+ node-version: '20'
52
+
53
+ - name: Install Dependencies
54
+ run: npm ci
55
+
56
+ - name: Run vitest
57
+ run: npm run test:frontend
.github/workflows/integration-test.yml ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Integration Test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - dev
8
+ pull_request:
9
+ branches:
10
+ - main
11
+ - dev
12
+
13
+ jobs:
14
+ cypress-run:
15
+ name: Run Cypress Integration Tests
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - name: Checkout Repository
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Build and run Compose Stack
22
+ run: |
23
+ docker compose \
24
+ --file docker-compose.yaml \
25
+ --file docker-compose.api.yaml \
26
+ --file docker-compose.a1111-test.yaml \
27
+ up --detach --build
28
+
29
+ - name: Wait for Ollama to be up
30
+ timeout-minutes: 5
31
+ run: |
32
+ until curl --output /dev/null --silent --fail http://localhost:11434; do
33
+ printf '.'
34
+ sleep 1
35
+ done
36
+ echo "Service is up!"
37
+
38
+ - name: Preload Ollama model
39
+ run: |
40
+ docker exec ollama ollama pull qwen:0.5b-chat-v1.5-q2_K
41
+
42
+ - name: Cypress run
43
+ uses: cypress-io/github-action@v6
44
+ with:
45
+ browser: chrome
46
+ wait-on: "http://localhost:3000"
47
+ config: baseUrl=http://localhost:3000
48
+
49
+ - uses: actions/upload-artifact@v4
50
+ if: always()
51
+ name: Upload Cypress videos
52
+ with:
53
+ name: cypress-videos
54
+ path: cypress/videos
55
+ if-no-files-found: ignore
56
+
57
+ - name: Extract Compose logs
58
+ if: always()
59
+ run: |
60
+ docker compose logs > compose-logs.txt
61
+
62
+ - uses: actions/upload-artifact@v4
63
+ if: always()
64
+ name: Upload Compose logs
65
+ with:
66
+ name: compose-logs
67
+ path: compose-logs.txt
68
+ if-no-files-found: ignore
69
+
70
+ migration_test:
71
+ name: Run Migration Tests
72
+ runs-on: ubuntu-latest
73
+ services:
74
+ postgres:
75
+ image: postgres
76
+ env:
77
+ POSTGRES_PASSWORD: postgres
78
+ options: >-
79
+ --health-cmd pg_isready
80
+ --health-interval 10s
81
+ --health-timeout 5s
82
+ --health-retries 5
83
+ ports:
84
+ - 5432:5432
85
+ # mysql:
86
+ # image: mysql
87
+ # env:
88
+ # MYSQL_ROOT_PASSWORD: mysql
89
+ # MYSQL_DATABASE: mysql
90
+ # options: >-
91
+ # --health-cmd "mysqladmin ping -h localhost"
92
+ # --health-interval 10s
93
+ # --health-timeout 5s
94
+ # --health-retries 5
95
+ # ports:
96
+ # - 3306:3306
97
+ steps:
98
+ - name: Checkout Repository
99
+ uses: actions/checkout@v4
100
+
101
+ - name: Set up Python
102
+ uses: actions/setup-python@v5
103
+ with:
104
+ python-version: ${{ matrix.python-version }}
105
+
106
+ - name: Set up uv
107
+ uses: yezz123/setup-uv@v4
108
+ with:
109
+ uv-venv: venv
110
+
111
+ - name: Activate virtualenv
112
+ run: |
113
+ . venv/bin/activate
114
+ echo PATH=$PATH >> $GITHUB_ENV
115
+
116
+ - name: Install dependencies
117
+ run: |
118
+ uv pip install -r backend/requirements.txt
119
+
120
+ - name: Test backend with SQLite
121
+ id: sqlite
122
+ env:
123
+ WEBUI_SECRET_KEY: secret-key
124
+ GLOBAL_LOG_LEVEL: debug
125
+ run: |
126
+ cd backend
127
+ uvicorn main:app --port "8080" --forwarded-allow-ips '*' &
128
+ UVICORN_PID=$!
129
+ # Wait up to 20 seconds for the server to start
130
+ for i in {1..20}; do
131
+ curl -s http://localhost:8080/api/config > /dev/null && break
132
+ sleep 1
133
+ if [ $i -eq 20 ]; then
134
+ echo "Server failed to start"
135
+ kill -9 $UVICORN_PID
136
+ exit 1
137
+ fi
138
+ done
139
+ # Check that the server is still running after 5 seconds
140
+ sleep 5
141
+ if ! kill -0 $UVICORN_PID; then
142
+ echo "Server has stopped"
143
+ exit 1
144
+ fi
145
+
146
+ - name: Test backend with Postgres
147
+ if: success() || steps.sqlite.conclusion == 'failure'
148
+ env:
149
+ WEBUI_SECRET_KEY: secret-key
150
+ GLOBAL_LOG_LEVEL: debug
151
+ DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
152
+ run: |
153
+ cd backend
154
+ uvicorn main:app --port "8081" --forwarded-allow-ips '*' &
155
+ UVICORN_PID=$!
156
+ # Wait up to 20 seconds for the server to start
157
+ for i in {1..20}; do
158
+ curl -s http://localhost:8081/api/config > /dev/null && break
159
+ sleep 1
160
+ if [ $i -eq 20 ]; then
161
+ echo "Server failed to start"
162
+ kill -9 $UVICORN_PID
163
+ exit 1
164
+ fi
165
+ done
166
+ # Check that the server is still running after 5 seconds
167
+ sleep 5
168
+ if ! kill -0 $UVICORN_PID; then
169
+ echo "Server has stopped"
170
+ exit 1
171
+ fi
172
+
173
+ # Check that service will reconnect to postgres when connection will be closed
174
+ status_code=$(curl --write-out %{http_code} -s --output /dev/null http://localhost:8081/health)
175
+ if [[ "$status_code" -ne 200 ]] ; then
176
+ echo "Server has failed before postgres reconnect check"
177
+ exit 1
178
+ fi
179
+
180
+ echo "Terminating all connections to postgres..."
181
+ python -c "import os, psycopg2 as pg2; \
182
+ conn = pg2.connect(dsn=os.environ['DATABASE_URL'].replace('+pool', '')); \
183
+ cur = conn.cursor(); \
184
+ cur.execute('SELECT pg_terminate_backend(psa.pid) FROM pg_stat_activity psa WHERE datname = current_database() AND pid <> pg_backend_pid();')"
185
+
186
+ status_code=$(curl --write-out %{http_code} -s --output /dev/null http://localhost:8081/health)
187
+ if [[ "$status_code" -ne 200 ]] ; then
188
+ echo "Server has not reconnected to postgres after connection was closed: returned status $status_code"
189
+ exit 1
190
+ fi
191
+
192
+ # - name: Test backend with MySQL
193
+ # if: success() || steps.sqlite.conclusion == 'failure' || steps.postgres.conclusion == 'failure'
194
+ # env:
195
+ # WEBUI_SECRET_KEY: secret-key
196
+ # GLOBAL_LOG_LEVEL: debug
197
+ # DATABASE_URL: mysql://root:mysql@localhost:3306/mysql
198
+ # run: |
199
+ # cd backend
200
+ # uvicorn main:app --port "8083" --forwarded-allow-ips '*' &
201
+ # UVICORN_PID=$!
202
+ # # Wait up to 20 seconds for the server to start
203
+ # for i in {1..20}; do
204
+ # curl -s http://localhost:8083/api/config > /dev/null && break
205
+ # sleep 1
206
+ # if [ $i -eq 20 ]; then
207
+ # echo "Server failed to start"
208
+ # kill -9 $UVICORN_PID
209
+ # exit 1
210
+ # fi
211
+ # done
212
+ # # Check that the server is still running after 5 seconds
213
+ # sleep 5
214
+ # if ! kill -0 $UVICORN_PID; then
215
+ # echo "Server has stopped"
216
+ # exit 1
217
+ # fi
.github/workflows/lint-backend.disabled ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Python CI
2
+ on:
3
+ push:
4
+ branches: ['main']
5
+ pull_request:
6
+ jobs:
7
+ build:
8
+ name: 'Lint Backend'
9
+ env:
10
+ PUBLIC_API_BASE_URL: ''
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ node-version:
15
+ - latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - name: Use Python
19
+ uses: actions/setup-python@v4
20
+ - name: Use Bun
21
+ uses: oven-sh/setup-bun@v1
22
+ - name: Install dependencies
23
+ run: |
24
+ python -m pip install --upgrade pip
25
+ pip install pylint
26
+ - name: Lint backend
27
+ run: bun run lint:backend
.github/workflows/lint-frontend.disabled ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Bun CI
2
+ on:
3
+ push:
4
+ branches: ['main']
5
+ pull_request:
6
+ jobs:
7
+ build:
8
+ name: 'Lint Frontend'
9
+ env:
10
+ PUBLIC_API_BASE_URL: ''
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Use Bun
15
+ uses: oven-sh/setup-bun@v1
16
+ - run: bun --version
17
+ - name: Install frontend dependencies
18
+ run: bun install --frozen-lockfile
19
+ - run: bun run lint:frontend
20
+ - run: bun run lint:types
21
+ if: success() || failure()
.github/workflows/release-pypi.yml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main # or whatever branch you want to use
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ environment:
12
+ name: pypi
13
+ url: https://pypi.org/p/open-webui
14
+ permissions:
15
+ id-token: write
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v4
19
+ - uses: actions/setup-node@v4
20
+ with:
21
+ node-version: 18
22
+ - uses: actions/setup-python@v5
23
+ with:
24
+ python-version: 3.11
25
+ - name: Build
26
+ run: |
27
+ python -m pip install --upgrade pip
28
+ pip install build
29
+ python -m build .
30
+ - name: Publish package distributions to PyPI
31
+ uses: pypa/gh-action-pypi-publish@release/v1
.gitignore ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ node_modules
3
+ /build
4
+ /.svelte-kit
5
+ /package
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+ vite.config.js.timestamp-*
10
+ vite.config.ts.timestamp-*
11
+ # Byte-compiled / optimized / DLL files
12
+ __pycache__/
13
+ *.py[cod]
14
+ *$py.class
15
+
16
+ # C extensions
17
+ *.so
18
+
19
+ # Pyodide distribution
20
+ static/pyodide/*
21
+ !static/pyodide/pyodide-lock.json
22
+
23
+ # Distribution / packaging
24
+ .Python
25
+ build/
26
+ develop-eggs/
27
+ dist/
28
+ downloads/
29
+ eggs/
30
+ .eggs/
31
+ lib64/
32
+ parts/
33
+ sdist/
34
+ var/
35
+ wheels/
36
+ share/python-wheels/
37
+ *.egg-info/
38
+ .installed.cfg
39
+ *.egg
40
+ MANIFEST
41
+
42
+ # PyInstaller
43
+ # Usually these files are written by a python script from a template
44
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
45
+ *.manifest
46
+ *.spec
47
+
48
+ # Installer logs
49
+ pip-log.txt
50
+ pip-delete-this-directory.txt
51
+
52
+ # Unit test / coverage reports
53
+ htmlcov/
54
+ .tox/
55
+ .nox/
56
+ .coverage
57
+ .coverage.*
58
+ .cache
59
+ nosetests.xml
60
+ coverage.xml
61
+ *.cover
62
+ *.py,cover
63
+ .hypothesis/
64
+ .pytest_cache/
65
+ cover/
66
+
67
+ # Translations
68
+ *.mo
69
+ *.pot
70
+
71
+ # Django stuff:
72
+ *.log
73
+ local_settings.py
74
+ db.sqlite3
75
+ db.sqlite3-journal
76
+
77
+ # Flask stuff:
78
+ instance/
79
+ .webassets-cache
80
+
81
+ # Scrapy stuff:
82
+ .scrapy
83
+
84
+ # Sphinx documentation
85
+ docs/_build/
86
+
87
+ # PyBuilder
88
+ .pybuilder/
89
+ target/
90
+
91
+ # Jupyter Notebook
92
+ .ipynb_checkpoints
93
+
94
+ # IPython
95
+ profile_default/
96
+ ipython_config.py
97
+
98
+ # pyenv
99
+ # For a library or package, you might want to ignore these files since the code is
100
+ # intended to run in multiple environments; otherwise, check them in:
101
+ # .python-version
102
+
103
+ # pipenv
104
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
105
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
106
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
107
+ # install all needed dependencies.
108
+ #Pipfile.lock
109
+
110
+ # poetry
111
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
112
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
113
+ # commonly ignored for libraries.
114
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
115
+ #poetry.lock
116
+
117
+ # pdm
118
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
119
+ #pdm.lock
120
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
121
+ # in version control.
122
+ # https://pdm.fming.dev/#use-with-ide
123
+ .pdm.toml
124
+
125
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
126
+ __pypackages__/
127
+
128
+ # Celery stuff
129
+ celerybeat-schedule
130
+ celerybeat.pid
131
+
132
+ # SageMath parsed files
133
+ *.sage.py
134
+
135
+ # Environments
136
+ .env
137
+ .venv
138
+ env/
139
+ venv/
140
+ ENV/
141
+ env.bak/
142
+ venv.bak/
143
+
144
+ # Spyder project settings
145
+ .spyderproject
146
+ .spyproject
147
+
148
+ # Rope project settings
149
+ .ropeproject
150
+
151
+ # mkdocs documentation
152
+ /site
153
+
154
+ # mypy
155
+ .mypy_cache/
156
+ .dmypy.json
157
+ dmypy.json
158
+
159
+ # Pyre type checker
160
+ .pyre/
161
+
162
+ # pytype static type analyzer
163
+ .pytype/
164
+
165
+ # Cython debug symbols
166
+ cython_debug/
167
+
168
+ # PyCharm
169
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
170
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
171
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
172
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
173
+ .idea/
174
+
175
+ # Logs
176
+ logs
177
+ *.log
178
+ npm-debug.log*
179
+ yarn-debug.log*
180
+ yarn-error.log*
181
+ lerna-debug.log*
182
+ .pnpm-debug.log*
183
+
184
+ # Diagnostic reports (https://nodejs.org/api/report.html)
185
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
186
+
187
+ # Runtime data
188
+ pids
189
+ *.pid
190
+ *.seed
191
+ *.pid.lock
192
+
193
+ # Directory for instrumented libs generated by jscoverage/JSCover
194
+ lib-cov
195
+
196
+ # Coverage directory used by tools like istanbul
197
+ coverage
198
+ *.lcov
199
+
200
+ # nyc test coverage
201
+ .nyc_output
202
+
203
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
204
+ .grunt
205
+
206
+ # Bower dependency directory (https://bower.io/)
207
+ bower_components
208
+
209
+ # node-waf configuration
210
+ .lock-wscript
211
+
212
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
213
+ build/Release
214
+
215
+ # Dependency directories
216
+ node_modules/
217
+ jspm_packages/
218
+
219
+ # Snowpack dependency directory (https://snowpack.dev/)
220
+ web_modules/
221
+
222
+ # TypeScript cache
223
+ *.tsbuildinfo
224
+
225
+ # Optional npm cache directory
226
+ .npm
227
+
228
+ # Optional eslint cache
229
+ .eslintcache
230
+
231
+ # Optional stylelint cache
232
+ .stylelintcache
233
+
234
+ # Microbundle cache
235
+ .rpt2_cache/
236
+ .rts2_cache_cjs/
237
+ .rts2_cache_es/
238
+ .rts2_cache_umd/
239
+
240
+ # Optional REPL history
241
+ .node_repl_history
242
+
243
+ # Output of 'npm pack'
244
+ *.tgz
245
+
246
+ # Yarn Integrity file
247
+ .yarn-integrity
248
+
249
+ # dotenv environment variable files
250
+ .env
251
+ .env.development.local
252
+ .env.test.local
253
+ .env.production.local
254
+ .env.local
255
+
256
+ # parcel-bundler cache (https://parceljs.org/)
257
+ .cache
258
+ .parcel-cache
259
+
260
+ # Next.js build output
261
+ .next
262
+ out
263
+
264
+ # Nuxt.js build / generate output
265
+ .nuxt
266
+ dist
267
+
268
+ # Gatsby files
269
+ .cache/
270
+ # Comment in the public line in if your project uses Gatsby and not Next.js
271
+ # https://nextjs.org/blog/next-9-1#public-directory-support
272
+ # public
273
+
274
+ # vuepress build output
275
+ .vuepress/dist
276
+
277
+ # vuepress v2.x temp and cache directory
278
+ .temp
279
+ .cache
280
+
281
+ # Docusaurus cache and generated files
282
+ .docusaurus
283
+
284
+ # Serverless directories
285
+ .serverless/
286
+
287
+ # FuseBox cache
288
+ .fusebox/
289
+
290
+ # DynamoDB Local files
291
+ .dynamodb/
292
+
293
+ # TernJS port file
294
+ .tern-port
295
+
296
+ # Stores VSCode versions used for testing VSCode extensions
297
+ .vscode-test
298
+
299
+ # yarn v2
300
+ .yarn/cache
301
+ .yarn/unplugged
302
+ .yarn/build-state.yml
303
+ .yarn/install-state.gz
304
+ .pnp.*
305
+
306
+ # cypress artifacts
307
+ cypress/videos
308
+ cypress/screenshots
.npmrc ADDED
@@ -0,0 +1 @@
 
 
1
+ engine-strict=true
.prettierignore ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ignore files for PNPM, NPM and YARN
2
+ pnpm-lock.yaml
3
+ package-lock.json
4
+ yarn.lock
5
+
6
+ kubernetes/
7
+
8
+ # Copy of .gitignore
9
+ .DS_Store
10
+ node_modules
11
+ /build
12
+ /.svelte-kit
13
+ /package
14
+ .env
15
+ .env.*
16
+ !.env.example
17
+ vite.config.js.timestamp-*
18
+ vite.config.ts.timestamp-*
19
+ # Byte-compiled / optimized / DLL files
20
+ __pycache__/
21
+ *.py[cod]
22
+ *$py.class
23
+
24
+ # C extensions
25
+ *.so
26
+
27
+ # Distribution / packaging
28
+ .Python
29
+ build/
30
+ develop-eggs/
31
+ dist/
32
+ downloads/
33
+ eggs/
34
+ .eggs/
35
+ lib64/
36
+ parts/
37
+ sdist/
38
+ var/
39
+ wheels/
40
+ share/python-wheels/
41
+ *.egg-info/
42
+ .installed.cfg
43
+ *.egg
44
+ MANIFEST
45
+
46
+ # PyInstaller
47
+ # Usually these files are written by a python script from a template
48
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
49
+ *.manifest
50
+ *.spec
51
+
52
+ # Installer logs
53
+ pip-log.txt
54
+ pip-delete-this-directory.txt
55
+
56
+ # Unit test / coverage reports
57
+ htmlcov/
58
+ .tox/
59
+ .nox/
60
+ .coverage
61
+ .coverage.*
62
+ .cache
63
+ nosetests.xml
64
+ coverage.xml
65
+ *.cover
66
+ *.py,cover
67
+ .hypothesis/
68
+ .pytest_cache/
69
+ cover/
70
+
71
+ # Translations
72
+ *.mo
73
+ *.pot
74
+
75
+ # Django stuff:
76
+ *.log
77
+ local_settings.py
78
+ db.sqlite3
79
+ db.sqlite3-journal
80
+
81
+ # Flask stuff:
82
+ instance/
83
+ .webassets-cache
84
+
85
+ # Scrapy stuff:
86
+ .scrapy
87
+
88
+ # Sphinx documentation
89
+ docs/_build/
90
+
91
+ # PyBuilder
92
+ .pybuilder/
93
+ target/
94
+
95
+ # Jupyter Notebook
96
+ .ipynb_checkpoints
97
+
98
+ # IPython
99
+ profile_default/
100
+ ipython_config.py
101
+
102
+ # pyenv
103
+ # For a library or package, you might want to ignore these files since the code is
104
+ # intended to run in multiple environments; otherwise, check them in:
105
+ # .python-version
106
+
107
+ # pipenv
108
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
109
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
110
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
111
+ # install all needed dependencies.
112
+ #Pipfile.lock
113
+
114
+ # poetry
115
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
116
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
117
+ # commonly ignored for libraries.
118
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
119
+ #poetry.lock
120
+
121
+ # pdm
122
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
123
+ #pdm.lock
124
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
125
+ # in version control.
126
+ # https://pdm.fming.dev/#use-with-ide
127
+ .pdm.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule
134
+ celerybeat.pid
135
+
136
+ # SageMath parsed files
137
+ *.sage.py
138
+
139
+ # Environments
140
+ .env
141
+ .venv
142
+ env/
143
+ venv/
144
+ ENV/
145
+ env.bak/
146
+ venv.bak/
147
+
148
+ # Spyder project settings
149
+ .spyderproject
150
+ .spyproject
151
+
152
+ # Rope project settings
153
+ .ropeproject
154
+
155
+ # mkdocs documentation
156
+ /site
157
+
158
+ # mypy
159
+ .mypy_cache/
160
+ .dmypy.json
161
+ dmypy.json
162
+
163
+ # Pyre type checker
164
+ .pyre/
165
+
166
+ # pytype static type analyzer
167
+ .pytype/
168
+
169
+ # Cython debug symbols
170
+ cython_debug/
171
+
172
+ # PyCharm
173
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
174
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
175
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
176
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
177
+ .idea/
178
+
179
+ # Logs
180
+ logs
181
+ *.log
182
+ npm-debug.log*
183
+ yarn-debug.log*
184
+ yarn-error.log*
185
+ lerna-debug.log*
186
+ .pnpm-debug.log*
187
+
188
+ # Diagnostic reports (https://nodejs.org/api/report.html)
189
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
190
+
191
+ # Runtime data
192
+ pids
193
+ *.pid
194
+ *.seed
195
+ *.pid.lock
196
+
197
+ # Directory for instrumented libs generated by jscoverage/JSCover
198
+ lib-cov
199
+
200
+ # Coverage directory used by tools like istanbul
201
+ coverage
202
+ *.lcov
203
+
204
+ # nyc test coverage
205
+ .nyc_output
206
+
207
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
208
+ .grunt
209
+
210
+ # Bower dependency directory (https://bower.io/)
211
+ bower_components
212
+
213
+ # node-waf configuration
214
+ .lock-wscript
215
+
216
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
217
+ build/Release
218
+
219
+ # Dependency directories
220
+ node_modules/
221
+ jspm_packages/
222
+
223
+ # Snowpack dependency directory (https://snowpack.dev/)
224
+ web_modules/
225
+
226
+ # TypeScript cache
227
+ *.tsbuildinfo
228
+
229
+ # Optional npm cache directory
230
+ .npm
231
+
232
+ # Optional eslint cache
233
+ .eslintcache
234
+
235
+ # Optional stylelint cache
236
+ .stylelintcache
237
+
238
+ # Microbundle cache
239
+ .rpt2_cache/
240
+ .rts2_cache_cjs/
241
+ .rts2_cache_es/
242
+ .rts2_cache_umd/
243
+
244
+ # Optional REPL history
245
+ .node_repl_history
246
+
247
+ # Output of 'npm pack'
248
+ *.tgz
249
+
250
+ # Yarn Integrity file
251
+ .yarn-integrity
252
+
253
+ # dotenv environment variable files
254
+ .env
255
+ .env.development.local
256
+ .env.test.local
257
+ .env.production.local
258
+ .env.local
259
+
260
+ # parcel-bundler cache (https://parceljs.org/)
261
+ .cache
262
+ .parcel-cache
263
+
264
+ # Next.js build output
265
+ .next
266
+ out
267
+
268
+ # Nuxt.js build / generate output
269
+ .nuxt
270
+ dist
271
+
272
+ # Gatsby files
273
+ .cache/
274
+ # Comment in the public line in if your project uses Gatsby and not Next.js
275
+ # https://nextjs.org/blog/next-9-1#public-directory-support
276
+ # public
277
+
278
+ # vuepress build output
279
+ .vuepress/dist
280
+
281
+ # vuepress v2.x temp and cache directory
282
+ .temp
283
+ .cache
284
+
285
+ # Docusaurus cache and generated files
286
+ .docusaurus
287
+
288
+ # Serverless directories
289
+ .serverless/
290
+
291
+ # FuseBox cache
292
+ .fusebox/
293
+
294
+ # DynamoDB Local files
295
+ .dynamodb/
296
+
297
+ # TernJS port file
298
+ .tern-port
299
+
300
+ # Stores VSCode versions used for testing VSCode extensions
301
+ .vscode-test
302
+
303
+ # yarn v2
304
+ .yarn/cache
305
+ .yarn/unplugged
306
+ .yarn/build-state.yml
307
+ .yarn/install-state.gz
308
+ .pnp.*
309
+
310
+ # cypress artifacts
311
+ cypress/videos
312
+ cypress/screenshots
313
+
314
+
315
+
316
+ /static/*
.prettierrc ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "useTabs": true,
3
+ "singleQuote": true,
4
+ "trailingComma": "none",
5
+ "printWidth": 100,
6
+ "plugins": ["prettier-plugin-svelte"],
7
+ "pluginSearchDirs": ["."],
8
+ "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
9
+ }
CHANGELOG.md ADDED
@@ -0,0 +1,632 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.5] - 2024-06-16
9
+
10
+ ### Added
11
+
12
+ - **📞 Enhanced Voice Call**: Text-to-speech (TTS) callback now operates in real-time for each sentence, reducing latency by not waiting for full completion.
13
+ - **👆 Tap to Interrupt**: During a call, you can now stop the assistant from speaking by simply tapping, instead of using voice. This resolves the issue of the speaker's voice being mistakenly registered as input.
14
+ - **😊 Emoji Call**: Toggle this feature on from the Settings > Interface, allowing LLMs to express emotions using emojis during voice calls for a more dynamic interaction.
15
+ - **🖱️ Quick Archive/Delete**: Use the Shift key + mouseover on the chat list to swiftly archive or delete items.
16
+ - **📝 Markdown Support in Model Descriptions**: You can now format model descriptions with markdown, enabling bold text, links, etc.
17
+ - **🧠 Editable Memories**: Adds the capability to modify memories.
18
+ - **📋 Admin Panel Sorting**: Introduces the ability to sort users/chats within the admin panel.
19
+ - **🌑 Dark Mode for Quick Selectors**: Dark mode now available for chat quick selectors (prompts, models, documents).
20
+ - **🔧 Advanced Parameters**: Adds 'num_keep' and 'num_batch' to advanced parameters for customization.
21
+ - **📅 Dynamic System Prompts**: New variables '{{CURRENT_DATETIME}}', '{{CURRENT_TIME}}', '{{USER_LOCATION}}' added for system prompts. Ensure '{{USER_LOCATION}}' is toggled on from Settings > Interface.
22
+ - **🌐 Tavily Web Search**: Includes Tavily as a web search provider option.
23
+ - **🖊️ Federated Auth Usernames**: Ability to set user names for federated authentication.
24
+ - **🔗 Auto Clean URLs**: When adding connection URLs, trailing slashes are now automatically removed.
25
+ - **🌐 Enhanced Translations**: Improved Chinese and Swedish translations.
26
+
27
+ ### Fixed
28
+
29
+ - **⏳ AIOHTTP_CLIENT_TIMEOUT**: Introduced a new environment variable 'AIOHTTP_CLIENT_TIMEOUT' for requests to Ollama lasting longer than 5 minutes. Default is 300 seconds; set to blank ('') for no timeout.
30
+ - **❌ Message Delete Freeze**: Resolved an issue where message deletion would sometimes cause the web UI to freeze.
31
+
32
+ ## [0.3.4] - 2024-06-12
33
+
34
+ ### Fixed
35
+
36
+ - **🔒 Mixed Content with HTTPS Issue**: Resolved a problem where mixed content (HTTP and HTTPS) was causing security warnings and blocking resources on HTTPS sites.
37
+ - **🔍 Web Search Issue**: Addressed the problem where web search functionality was not working correctly. The 'ENABLE_RAG_LOCAL_WEB_FETCH' option has been reintroduced to restore proper web searching capabilities.
38
+ - **💾 RAG Template Not Being Saved**: Fixed an issue where the RAG template was not being saved correctly, ensuring your custom templates are now preserved as expected.
39
+
40
+ ## [0.3.3] - 2024-06-12
41
+
42
+ ### Added
43
+
44
+ - **🛠️ Native Python Function Calling**: Introducing native Python function calling within Open WebUI. We’ve also included a built-in code editor to seamlessly develop and integrate function code within the 'Tools' workspace. With this, you can significantly enhance your LLM’s capabilities by creating custom RAG pipelines, web search tools, and even agent-like features such as sending Discord messages.
45
+ - **🌐 DuckDuckGo Integration**: Added DuckDuckGo as a web search provider, giving you more search options.
46
+ - **🌏 Enhanced Translations**: Improved translations for Vietnamese and Chinese languages, making the interface more accessible.
47
+
48
+ ### Fixed
49
+
50
+ - **🔗 Web Search URL Error Handling**: Fixed the issue where a single URL error would disrupt the data loading process in Web Search mode. Now, such errors will be handled gracefully to ensure uninterrupted data loading.
51
+ - **🖥️ Frontend Responsiveness**: Resolved the problem where the frontend would stop responding if the backend encounters an error while downloading a model. Improved error handling to maintain frontend stability.
52
+ - **🔧 Dependency Issues in pip**: Fixed issues related to pip installations, ensuring all dependencies are correctly managed to prevent installation errors.
53
+
54
+ ## [0.3.2] - 2024-06-10
55
+
56
+ ### Added
57
+
58
+ - **🔍 Web Search Query Status**: The web search query will now persist in the results section to aid in easier debugging and tracking of search queries.
59
+ - **🌐 New Web Search Provider**: We have added Serply as a new option for web search providers, giving you more choices for your search needs.
60
+ - **🌏 Improved Translations**: We've enhanced translations for Chinese and Portuguese.
61
+
62
+ ### Fixed
63
+
64
+ - **🎤 Audio File Upload Issue**: The bug that prevented audio files from being uploaded in chat input has been fixed, ensuring smooth communication.
65
+ - **💬 Message Input Handling**: Improved the handling of message inputs by instantly clearing images and text after sending, along with immediate visual indications when a response message is loading, enhancing user feedback.
66
+ - **⚙️ Parameter Registration and Validation**: Fixed the issue where parameters were not registering in certain cases and addressed the problem where users were unable to save due to invalid input errors.
67
+
68
+ ## [0.3.1] - 2024-06-09
69
+
70
+ ### Fixed
71
+
72
+ - **💬 Chat Functionality**: Resolved the issue where chat functionality was not working for specific models.
73
+
74
+ ## [0.3.0] - 2024-06-09
75
+
76
+ ### Added
77
+
78
+ - **📚 Knowledge Support for Models**: Attach documents directly to models from the models workspace, enhancing the information available to each model.
79
+ - **🎙️ Hands-Free Voice Call Feature**: Initiate voice calls without needing to use your hands, making interactions more seamless.
80
+ - **📹 Video Call Feature**: Enable video calls with supported vision models like Llava and GPT-4o, adding a visual dimension to your communications.
81
+ - **🎛️ Enhanced UI for Voice Recording**: Improved user interface for the voice recording feature, making it more intuitive and user-friendly.
82
+ - **🌐 External STT Support**: Now support for external Speech-To-Text services, providing more flexibility in choosing your STT provider.
83
+ - **⚙️ Unified Settings**: Consolidated settings including document settings under a new admin settings section for easier management.
84
+ - **🌑 Dark Mode Splash Screen**: A new splash screen for dark mode, ensuring a consistent and visually appealing experience for dark mode users.
85
+ - **📥 Upload Pipeline**: Directly upload pipelines from the admin settings > pipelines section, streamlining the pipeline management process.
86
+ - **🌍 Improved Language Support**: Enhanced support for Chinese and Ukrainian languages, better catering to a global user base.
87
+
88
+ ### Fixed
89
+
90
+ - **🛠️ Playground Issue**: Fixed the playground not functioning properly, ensuring a smoother user experience.
91
+ - **🔥 Temperature Parameter Issue**: Corrected the issue where the temperature value '0' was not being passed correctly.
92
+ - **📝 Prompt Input Clearing**: Resolved prompt input textarea not being cleared right away, ensuring a clean slate for new inputs.
93
+ - **✨ Various UI Styling Issues**: Fixed numerous user interface styling problems for a more cohesive look.
94
+ - **👥 Active Users Display**: Fixed active users showing active sessions instead of actual users, now reflecting accurate user activity.
95
+ - **🌐 Community Platform Compatibility**: The Community Platform is back online and fully compatible with Open WebUI.
96
+
97
+ ### Changed
98
+
99
+ - **📝 RAG Implementation**: Updated the RAG (Retrieval-Augmented Generation) implementation to use a system prompt for context, instead of overriding the user's prompt.
100
+ - **🔄 Settings Relocation**: Moved Models, Connections, Audio, and Images settings to the admin settings for better organization.
101
+ - **✍️ Improved Title Generation**: Enhanced the default prompt for title generation, yielding better results.
102
+ - **🔧 Backend Task Management**: Tasks like title generation and search query generation are now managed on the backend side and controlled only by the admin.
103
+ - **🔍 Editable Search Query Prompt**: You can now edit the search query generation prompt, offering more control over how queries are generated.
104
+ - **📏 Prompt Length Threshold**: Set the prompt length threshold for search query generation from the admin settings, giving more customization options.
105
+ - **📣 Settings Consolidation**: Merged the Banners admin setting with the Interface admin setting for a more streamlined settings area.
106
+
107
+ ## [0.2.5] - 2024-06-05
108
+
109
+ ### Added
110
+
111
+ - **👥 Active Users Indicator**: Now you can see how many people are currently active and what they are running. This helps you gauge when performance might slow down due to a high number of users.
112
+ - **🗂️ Create Ollama Modelfile**: The option to create a modelfile for Ollama has been reintroduced in the Settings > Models section, making it easier to manage your models.
113
+ - **⚙️ Default Model Setting**: Added an option to set the default model from Settings > Interface. This feature is now easily accessible, especially convenient for mobile users as it was previously hidden.
114
+ - **🌐 Enhanced Translations**: We've improved the Chinese translations and added support for Turkmen and Norwegian languages to make the interface more accessible globally.
115
+
116
+ ### Fixed
117
+
118
+ - **📱 Mobile View Improvements**: The UI now uses dvh (dynamic viewport height) instead of vh (viewport height), providing a better and more responsive experience for mobile users.
119
+
120
+ ## [0.2.4] - 2024-06-03
121
+
122
+ ### Added
123
+
124
+ - **👤 Improved Account Pending Page**: The account pending page now displays admin details by default to avoid confusion. You can disable this feature in the admin settings if needed.
125
+ - **🌐 HTTP Proxy Support**: We have enabled the use of the 'http_proxy' environment variable in OpenAI and Ollama API calls, making it easier to configure network settings.
126
+ - **❓ Quick Access to Documentation**: You can now easily access Open WebUI documents via a question mark button located at the bottom right corner of the screen (available on larger screens like PCs).
127
+ - **🌍 Enhanced Translation**: Improvements have been made to translations.
128
+
129
+ ### Fixed
130
+
131
+ - **🔍 SearxNG Web Search**: Fixed the issue where the SearxNG web search functionality was not working properly.
132
+
133
+ ## [0.2.3] - 2024-06-03
134
+
135
+ ### Added
136
+
137
+ - **📁 Export Chat as JSON**: You can now export individual chats as JSON files from the navbar menu by navigating to 'Download > Export Chat'. This makes sharing specific conversations easier.
138
+ - **✏️ Edit Titles with Double Click**: Double-click on titles to rename them quickly and efficiently.
139
+ - **🧩 Batch Multiple Embeddings**: Introduced 'RAG_EMBEDDING_OPENAI_BATCH_SIZE' to process multiple embeddings in a batch, enhancing performance for large datasets.
140
+ - **🌍 Improved Translations**: Enhanced the translation quality across various languages for a better user experience.
141
+
142
+ ### Fixed
143
+
144
+ - **🛠️ Modelfile Migration Script**: Fixed an issue where the modelfile migration script would fail if an invalid modelfile was encountered.
145
+ - **💬 Zhuyin Input Method on Mac**: Resolved an issue where using the Zhuyin input method in the Web UI on a Mac caused text to send immediately upon pressing the enter key, leading to incorrect input.
146
+ - **🔊 Local TTS Voice Selection**: Fixed the issue where the selected local Text-to-Speech (TTS) voice was not being displayed in settings.
147
+
148
+ ## [0.2.2] - 2024-06-02
149
+
150
+ ### Added
151
+
152
+ - **🌊 Mermaid Rendering Support**: We've included support for Mermaid rendering. This allows you to create beautiful diagrams and flowcharts directly within Open WebUI.
153
+ - **🔄 New Environment Variable 'RESET_CONFIG_ON_START'**: Introducing a new environment variable: 'RESET_CONFIG_ON_START'. Set this variable to reset your configuration settings upon starting the application, making it easier to revert to default settings.
154
+
155
+ ### Fixed
156
+
157
+ - **🔧 Pipelines Filter Issue**: We've addressed an issue with the pipelines where filters were not functioning as expected.
158
+
159
+ ## [0.2.1] - 2024-06-02
160
+
161
+ ### Added
162
+
163
+ - **🖱️ Single Model Export Button**: Easily export models with just one click using the new single model export button.
164
+ - **🖥️ Advanced Parameters Support**: Added support for 'num_thread', 'use_mmap', and 'use_mlock' parameters for Ollama.
165
+ - **🌐 Improved Vietnamese Translation**: Enhanced Vietnamese language support for a better user experience for our Vietnamese-speaking community.
166
+
167
+ ### Fixed
168
+
169
+ - **🔧 OpenAI URL API Save Issue**: Corrected a problem preventing the saving of OpenAI URL API settings.
170
+ - **🚫 Display Issue with Disabled Ollama API**: Fixed the display bug causing models to appear in settings when the Ollama API was disabled.
171
+
172
+ ### Changed
173
+
174
+ - **💡 Versioning Update**: As a reminder from our previous update, version 0.2.y will focus primarily on bug fixes, while major updates will be designated as 0.x from now on for better version tracking.
175
+
176
+ ## [0.2.0] - 2024-06-01
177
+
178
+ ### Added
179
+
180
+ - **🔧 Pipelines Support**: Open WebUI now includes a plugin framework for enhanced customization and functionality (https://github.com/open-webui/pipelines). Easily add custom logic and integrate Python libraries, from AI agents to home automation APIs.
181
+ - **🔗 Function Calling via Pipelines**: Integrate function calling seamlessly through Pipelines.
182
+ - **⚖️ User Rate Limiting via Pipelines**: Implement user-specific rate limits to manage API usage efficiently.
183
+ - **📊 Usage Monitoring with Langfuse**: Track and analyze usage statistics with Langfuse integration through Pipelines.
184
+ - **🕒 Conversation Turn Limits**: Set limits on conversation turns to manage interactions better through Pipelines.
185
+ - **🛡️ Toxic Message Filtering**: Automatically filter out toxic messages to maintain a safe environment using Pipelines.
186
+ - **🔍 Web Search Support**: Introducing built-in web search capabilities via RAG API, allowing users to search using SearXNG, Google Programmatic Search Engine, Brave Search, serpstack, and serper. Activate it effortlessly by adding necessary variables from Document settings > Web Params.
187
+ - **🗂️ Models Workspace**: Create and manage model presets for both Ollama/OpenAI API. Note: The old Modelfiles workspace is deprecated.
188
+ - **🛠️ Model Builder Feature**: Build and edit all models with persistent builder mode.
189
+ - **🏷️ Model Tagging Support**: Organize models with tagging features in the models workspace.
190
+ - **📋 Model Ordering Support**: Effortlessly organize models by dragging and dropping them into the desired positions within the models workspace.
191
+ - **📈 OpenAI Generation Stats**: Access detailed generation statistics for OpenAI models.
192
+ - **📅 System Prompt Variables**: New variables added: '{{CURRENT_DATE}}' and '{{USER_NAME}}' for dynamic prompts.
193
+ - **📢 Global Banner Support**: Manage global banners from admin settings > banners.
194
+ - **🗃️ Enhanced Archived Chats Modal**: Search and export archived chats easily.
195
+ - **📂 Archive All Button**: Quickly archive all chats from settings > chats.
196
+ - **🌐 Improved Translations**: Added and improved translations for French, Croatian, Cebuano, and Vietnamese.
197
+
198
+ ### Fixed
199
+
200
+ - **🔍 Archived Chats Visibility**: Resolved issue with archived chats not showing in the admin panel.
201
+ - **💬 Message Styling**: Fixed styling issues affecting message appearance.
202
+ - **🔗 Shared Chat Responses**: Corrected the issue where shared chat response messages were not readonly.
203
+ - **🖥️ UI Enhancement**: Fixed the scrollbar overlapping issue with the message box in the user interface.
204
+
205
+ ### Changed
206
+
207
+ - **💾 User Settings Storage**: User settings are now saved on the backend, ensuring consistency across all devices.
208
+ - **📡 Unified API Requests**: The API request for getting models is now unified to '/api/models' for easier usage.
209
+ - **🔄 Versioning Update**: Our versioning will now follow the format 0.x for major updates and 0.x.y for patches.
210
+ - **📦 Export All Chats (All Users)**: Moved this functionality to the Admin Panel settings for better organization and accessibility.
211
+
212
+ ### Removed
213
+
214
+ - **🚫 Bundled LiteLLM Support Deprecated**: Migrate your LiteLLM config.yaml to a self-hosted LiteLLM instance. LiteLLM can still be added via OpenAI Connections. Download the LiteLLM config.yaml from admin settings > database > export LiteLLM config.yaml.
215
+
216
+ ## [0.1.125] - 2024-05-19
217
+
218
+ ### Added
219
+
220
+ - **🔄 Updated UI**: Chat interface revamped with chat bubbles. Easily switch back to the old style via settings > interface > chat bubble UI.
221
+ - **📂 Enhanced Sidebar UI**: Model files, documents, prompts, and playground merged into Workspace for streamlined access.
222
+ - **🚀 Improved Many Model Interaction**: All responses now displayed simultaneously for a smoother experience.
223
+ - **🐍 Python Code Execution**: Execute Python code locally in the browser with libraries like 'requests', 'beautifulsoup4', 'numpy', 'pandas', 'seaborn', 'matplotlib', 'scikit-learn', 'scipy', 'regex'.
224
+ - **🧠 Experimental Memory Feature**: Manually input personal information you want LLMs to remember via settings > personalization > memory.
225
+ - **💾 Persistent Settings**: Settings now saved as config.json for convenience.
226
+ - **🩺 Health Check Endpoint**: Added for Docker deployment.
227
+ - **↕️ RTL Support**: Toggle chat direction via settings > interface > chat direction.
228
+ - **🖥️ PowerPoint Support**: RAG pipeline now supports PowerPoint documents.
229
+ - **🌐 Language Updates**: Ukrainian, Turkish, Arabic, Chinese, Serbian, Vietnamese updated; Punjabi added.
230
+
231
+ ### Changed
232
+
233
+ - **👤 Shared Chat Update**: Shared chat now includes creator user information.
234
+
235
+ ## [0.1.124] - 2024-05-08
236
+
237
+ ### Added
238
+
239
+ - **🖼️ Improved Chat Sidebar**: Now conveniently displays time ranges and organizes chats by today, yesterday, and more.
240
+ - **📜 Citations in RAG Feature**: Easily track the context fed to the LLM with added citations in the RAG feature.
241
+ - **🔒 Auth Disable Option**: Introducing the ability to disable authentication. Set 'WEBUI_AUTH' to False to disable authentication. Note: Only applicable for fresh installations without existing users.
242
+ - **📹 Enhanced YouTube RAG Pipeline**: Now supports non-English videos for an enriched experience.
243
+ - **🔊 Specify OpenAI TTS Models**: Customize your TTS experience by specifying OpenAI TTS models.
244
+ - **🔧 Additional Environment Variables**: Discover more environment variables in our comprehensive documentation at Open WebUI Documentation (https://docs.openwebui.com).
245
+ - **🌐 Language Support**: Arabic, Finnish, and Hindi added; Improved support for German, Vietnamese, and Chinese.
246
+
247
+ ### Fixed
248
+
249
+ - **🛠️ Model Selector Styling**: Addressed styling issues for improved user experience.
250
+ - **⚠️ Warning Messages**: Resolved backend warning messages.
251
+
252
+ ### Changed
253
+
254
+ - **📝 Title Generation**: Limited output to 50 tokens.
255
+ - **📦 Helm Charts**: Removed Helm charts, now available in a separate repository (https://github.com/open-webui/helm-charts).
256
+
257
+ ## [0.1.123] - 2024-05-02
258
+
259
+ ### Added
260
+
261
+ - **🎨 New Landing Page Design**: Refreshed design for a more modern look and optimized use of screen space.
262
+ - **📹 Youtube RAG Pipeline**: Introduces dedicated RAG pipeline for Youtube videos, enabling interaction with video transcriptions directly.
263
+ - **🔧 Enhanced Admin Panel**: Streamlined user management with options to add users directly or in bulk via CSV import.
264
+ - **👥 '@' Model Integration**: Easily switch to specific models during conversations; old collaborative chat feature phased out.
265
+ - **🌐 Language Enhancements**: Swedish translation added, plus improvements to German, Spanish, and the addition of Doge translation.
266
+
267
+ ### Fixed
268
+
269
+ - **🗑️ Delete Chat Shortcut**: Addressed issue where shortcut wasn't functioning.
270
+ - **🖼️ Modal Closing Bug**: Resolved unexpected closure of modal when dragging from within.
271
+ - **✏️ Edit Button Styling**: Fixed styling inconsistency with edit buttons.
272
+ - **🌐 Image Generation Compatibility Issue**: Rectified image generation compatibility issue with third-party APIs.
273
+ - **📱 iOS PWA Icon Fix**: Corrected iOS PWA home screen icon shape.
274
+ - **🔍 Scroll Gesture Bug**: Adjusted gesture sensitivity to prevent accidental activation when scrolling through code on mobile; now requires scrolling from the leftmost side to open the sidebar.
275
+
276
+ ### Changed
277
+
278
+ - **🔄 Unlimited Context Length**: Advanced settings now allow unlimited max context length (previously limited to 16000).
279
+ - **👑 Super Admin Assignment**: The first signup is automatically assigned a super admin role, unchangeable by other admins.
280
+ - **🛡️ Admin User Restrictions**: User action buttons from the admin panel are now disabled for users with admin roles.
281
+ - **🔝 Default Model Selector**: Set as default model option now exclusively available on the landing page.
282
+
283
+ ## [0.1.122] - 2024-04-27
284
+
285
+ ### Added
286
+
287
+ - **🌟 Enhanced RAG Pipeline**: Now with hybrid searching via 'BM25', reranking powered by 'CrossEncoder', and configurable relevance score thresholds.
288
+ - **🛢️ External Database Support**: Seamlessly connect to custom SQLite or Postgres databases using the 'DATABASE_URL' environment variable.
289
+ - **🌐 Remote ChromaDB Support**: Introducing the capability to connect to remote ChromaDB servers.
290
+ - **👨‍💼 Improved Admin Panel**: Admins can now conveniently check users' chat lists and last active status directly from the admin panel.
291
+ - **🎨 Splash Screen**: Introducing a loading splash screen for a smoother user experience.
292
+ - **🌍 Language Support Expansion**: Added support for Bangla (bn-BD), along with enhancements to Chinese, Spanish, and Ukrainian translations.
293
+ - **💻 Improved LaTeX Rendering Performance**: Enjoy faster rendering times for LaTeX equations.
294
+ - **🔧 More Environment Variables**: Explore additional environment variables in our documentation (https://docs.openwebui.com), including the 'ENABLE_LITELLM' option to manage memory usage.
295
+
296
+ ### Fixed
297
+
298
+ - **🔧 Ollama Compatibility**: Resolved errors occurring when Ollama server version isn't an integer, such as SHA builds or RCs.
299
+ - **🐛 Various OpenAI API Issues**: Addressed several issues related to the OpenAI API.
300
+ - **🛑 Stop Sequence Issue**: Fixed the problem where the stop sequence with a backslash '\' was not functioning.
301
+ - **🔤 Font Fallback**: Corrected font fallback issue.
302
+
303
+ ### Changed
304
+
305
+ - **⌨️ Prompt Input Behavior on Mobile**: Enter key prompt submission disabled on mobile devices for improved user experience.
306
+
307
+ ## [0.1.121] - 2024-04-24
308
+
309
+ ### Fixed
310
+
311
+ - **🔧 Translation Issues**: Addressed various translation discrepancies.
312
+ - **🔒 LiteLLM Security Fix**: Updated LiteLLM version to resolve a security vulnerability.
313
+ - **🖥️ HTML Tag Display**: Rectified the issue where the '< br >' tag wasn't displaying correctly.
314
+ - **🔗 WebSocket Connection**: Resolved the failure of WebSocket connection under HTTPS security for ComfyUI server.
315
+ - **📜 FileReader Optimization**: Implemented FileReader initialization per image in multi-file drag & drop to ensure reusability.
316
+ - **🏷️ Tag Display**: Corrected tag display inconsistencies.
317
+ - **📦 Archived Chat Styling**: Fixed styling issues in archived chat.
318
+ - **🔖 Safari Copy Button Bug**: Addressed the bug where the copy button failed to copy links in Safari.
319
+
320
+ ## [0.1.120] - 2024-04-20
321
+
322
+ ### Added
323
+
324
+ - **📦 Archive Chat Feature**: Easily archive chats with a new sidebar button, and access archived chats via the profile button > archived chats.
325
+ - **🔊 Configurable Text-to-Speech Endpoint**: Customize your Text-to-Speech experience with configurable OpenAI endpoints.
326
+ - **🛠️ Improved Error Handling**: Enhanced error message handling for connection failures.
327
+ - **⌨️ Enhanced Shortcut**: When editing messages, use ctrl/cmd+enter to save and submit, and esc to close.
328
+ - **🌐 Language Support**: Added support for Georgian and enhanced translations for Portuguese and Vietnamese.
329
+
330
+ ### Fixed
331
+
332
+ - **🔧 Model Selector**: Resolved issue where default model selection was not saving.
333
+ - **🔗 Share Link Copy Button**: Fixed bug where the copy button wasn't copying links in Safari.
334
+ - **🎨 Light Theme Styling**: Addressed styling issue with the light theme.
335
+
336
+ ## [0.1.119] - 2024-04-16
337
+
338
+ ### Added
339
+
340
+ - **🌟 Enhanced RAG Embedding Support**: Ollama, and OpenAI models can now be used for RAG embedding model.
341
+ - **🔄 Seamless Integration**: Copy 'ollama run <model name>' directly from Ollama page to easily select and pull models.
342
+ - **🏷️ Tagging Feature**: Add tags to chats directly via the sidebar chat menu.
343
+ - **📱 Mobile Accessibility**: Swipe left and right on mobile to effortlessly open and close the sidebar.
344
+ - **🔍 Improved Navigation**: Admin panel now supports pagination for user list.
345
+ - **🌍 Additional Language Support**: Added Polish language support.
346
+
347
+ ### Fixed
348
+
349
+ - **🌍 Language Enhancements**: Vietnamese and Spanish translations have been improved.
350
+ - **🔧 Helm Fixes**: Resolved issues with Helm trailing slash and manifest.json.
351
+
352
+ ### Changed
353
+
354
+ - **🐳 Docker Optimization**: Updated docker image build process to utilize 'uv' for significantly faster builds compared to 'pip3'.
355
+
356
+ ## [0.1.118] - 2024-04-10
357
+
358
+ ### Added
359
+
360
+ - **🦙 Ollama and CUDA Images**: Added support for ':ollama' and ':cuda' tagged images.
361
+ - **👍 Enhanced Response Rating**: Now you can annotate your ratings for better feedback.
362
+ - **👤 User Initials Profile Photo**: User initials are now the default profile photo.
363
+ - **🔍 Update RAG Embedding Model**: Customize RAG embedding model directly in document settings.
364
+ - **🌍 Additional Language Support**: Added Turkish language support.
365
+
366
+ ### Fixed
367
+
368
+ - **🔒 Share Chat Permission**: Resolved issue with chat sharing permissions.
369
+ - **🛠 Modal Close**: Modals can now be closed using the Esc key.
370
+
371
+ ### Changed
372
+
373
+ - **🎨 Admin Panel Styling**: Refreshed styling for the admin panel.
374
+ - **🐳 Docker Image Build**: Updated docker image build process for improved efficiency.
375
+
376
+ ## [0.1.117] - 2024-04-03
377
+
378
+ ### Added
379
+
380
+ - 🗨️ **Local Chat Sharing**: Share chat links seamlessly between users.
381
+ - 🔑 **API Key Generation Support**: Generate secret keys to leverage Open WebUI with OpenAI libraries.
382
+ - 📄 **Chat Download as PDF**: Easily download chats in PDF format.
383
+ - 📝 **Improved Logging**: Enhancements to logging functionality.
384
+ - 📧 **Trusted Email Authentication**: Authenticate using a trusted email header.
385
+
386
+ ### Fixed
387
+
388
+ - 🌷 **Enhanced Dutch Translation**: Improved translation for Dutch users.
389
+ - ⚪ **White Theme Styling**: Resolved styling issue with the white theme.
390
+ - 📜 **LaTeX Chat Screen Overflow**: Fixed screen overflow issue with LaTeX rendering.
391
+ - 🔒 **Security Patches**: Applied necessary security patches.
392
+
393
+ ## [0.1.116] - 2024-03-31
394
+
395
+ ### Added
396
+
397
+ - **🔄 Enhanced UI**: Model selector now conveniently located in the navbar, enabling seamless switching between multiple models during conversations.
398
+ - **🔍 Improved Model Selector**: Directly pull a model from the selector/Models now display detailed information for better understanding.
399
+ - **💬 Webhook Support**: Now compatible with Google Chat and Microsoft Teams.
400
+ - **🌐 Localization**: Korean translation (I18n) now available.
401
+ - **🌑 Dark Theme**: OLED dark theme introduced for reduced strain during prolonged usage.
402
+ - **🏷️ Tag Autocomplete**: Dropdown feature added for effortless chat tagging.
403
+
404
+ ### Fixed
405
+
406
+ - **🔽 Auto-Scrolling**: Addressed OpenAI auto-scrolling issue.
407
+ - **🏷️ Tag Validation**: Implemented tag validation to prevent empty string tags.
408
+ - **🚫 Model Whitelisting**: Resolved LiteLLM model whitelisting issue.
409
+ - **✅ Spelling**: Corrected various spelling issues for improved readability.
410
+
411
+ ## [0.1.115] - 2024-03-24
412
+
413
+ ### Added
414
+
415
+ - **🔍 Custom Model Selector**: Easily find and select custom models with the new search filter feature.
416
+ - **🛑 Cancel Model Download**: Added the ability to cancel model downloads.
417
+ - **🎨 Image Generation ComfyUI**: Image generation now supports ComfyUI.
418
+ - **🌟 Updated Light Theme**: Updated the light theme for a fresh look.
419
+ - **🌍 Additional Language Support**: Now supporting Bulgarian, Italian, Portuguese, Japanese, and Dutch.
420
+
421
+ ### Fixed
422
+
423
+ - **🔧 Fixed Broken Experimental GGUF Upload**: Resolved issues with experimental GGUF upload functionality.
424
+
425
+ ### Changed
426
+
427
+ - **🔄 Vector Storage Reset Button**: Moved the reset vector storage button to document settings.
428
+
429
+ ## [0.1.114] - 2024-03-20
430
+
431
+ ### Added
432
+
433
+ - **🔗 Webhook Integration**: Now you can subscribe to new user sign-up events via webhook. Simply navigate to the admin panel > admin settings > webhook URL.
434
+ - **🛡️ Enhanced Model Filtering**: Alongside Ollama, OpenAI proxy model whitelisting, we've added model filtering functionality for LiteLLM proxy.
435
+ - **🌍 Expanded Language Support**: Spanish, Catalan, and Vietnamese languages are now available, with improvements made to others.
436
+
437
+ ### Fixed
438
+
439
+ - **🔧 Input Field Spelling**: Resolved issue with spelling mistakes in input fields.
440
+ - **🖊️ Light Mode Styling**: Fixed styling issue with light mode in document adding.
441
+
442
+ ### Changed
443
+
444
+ - **🔄 Language Sorting**: Languages are now sorted alphabetically by their code for improved organization.
445
+
446
+ ## [0.1.113] - 2024-03-18
447
+
448
+ ### Added
449
+
450
+ - 🌍 **Localization**: You can now change the UI language in Settings > General. We support Ukrainian, German, Farsi (Persian), Traditional and Simplified Chinese and French translations. You can help us to translate the UI into your language! More info in our [CONTRIBUTION.md](https://github.com/open-webui/open-webui/blob/main/docs/CONTRIBUTING.md#-translations-and-internationalization).
451
+ - 🎨 **System-wide Theme**: Introducing a new system-wide theme for enhanced visual experience.
452
+
453
+ ### Fixed
454
+
455
+ - 🌑 **Dark Background on Select Fields**: Improved readability by adding a dark background to select fields, addressing issues on certain browsers/devices.
456
+ - **Multiple OPENAI_API_BASE_URLS Issue**: Resolved issue where multiple base URLs caused conflicts when one wasn't functioning.
457
+ - **RAG Encoding Issue**: Fixed encoding problem in RAG.
458
+ - **npm Audit Fix**: Addressed npm audit findings.
459
+ - **Reduced Scroll Threshold**: Improved auto-scroll experience by reducing the scroll threshold from 50px to 5px.
460
+
461
+ ### Changed
462
+
463
+ - 🔄 **Sidebar UI Update**: Updated sidebar UI to feature a chat menu dropdown, replacing two icons for improved navigation.
464
+
465
+ ## [0.1.112] - 2024-03-15
466
+
467
+ ### Fixed
468
+
469
+ - 🗨️ Resolved chat malfunction after image generation.
470
+ - 🎨 Fixed various RAG issues.
471
+ - 🧪 Rectified experimental broken GGUF upload logic.
472
+
473
+ ## [0.1.111] - 2024-03-10
474
+
475
+ ### Added
476
+
477
+ - 🛡️ **Model Whitelisting**: Admins now have the ability to whitelist models for users with the 'user' role.
478
+ - 🔄 **Update All Models**: Added a convenient button to update all models at once.
479
+ - 📄 **Toggle PDF OCR**: Users can now toggle PDF OCR option for improved parsing performance.
480
+ - 🎨 **DALL-E Integration**: Introduced DALL-E integration for image generation alongside automatic1111.
481
+ - 🛠️ **RAG API Refactoring**: Refactored RAG logic and exposed its API, with additional documentation to follow.
482
+
483
+ ### Fixed
484
+
485
+ - 🔒 **Max Token Settings**: Added max token settings for anthropic/claude-3-sonnet-20240229 (Issue #1094).
486
+ - 🔧 **Misalignment Issue**: Corrected misalignment of Edit and Delete Icons when Chat Title is Empty (Issue #1104).
487
+ - 🔄 **Context Loss Fix**: Resolved RAG losing context on model response regeneration with Groq models via API key (Issue #1105).
488
+ - 📁 **File Handling Bug**: Addressed File Not Found Notification when Dropping a Conversation Element (Issue #1098).
489
+ - 🖱️ **Dragged File Styling**: Fixed dragged file layover styling issue.
490
+
491
+ ## [0.1.110] - 2024-03-06
492
+
493
+ ### Added
494
+
495
+ - **🌐 Multiple OpenAI Servers Support**: Enjoy seamless integration with multiple OpenAI-compatible APIs, now supported natively.
496
+
497
+ ### Fixed
498
+
499
+ - **🔍 OCR Issue**: Resolved PDF parsing issue caused by OCR malfunction.
500
+ - **🚫 RAG Issue**: Fixed the RAG functionality, ensuring it operates smoothly.
501
+ - **📄 "Add Docs" Model Button**: Addressed the non-functional behavior of the "Add Docs" model button.
502
+
503
+ ## [0.1.109] - 2024-03-06
504
+
505
+ ### Added
506
+
507
+ - **🔄 Multiple Ollama Servers Support**: Enjoy enhanced scalability and performance with support for multiple Ollama servers in a single WebUI. Load balancing features are now available, providing improved efficiency (#788, #278).
508
+ - **🔧 Support for Claude 3 and Gemini**: Responding to user requests, we've expanded our toolset to include Claude 3 and Gemini, offering a wider range of functionalities within our platform (#1064).
509
+ - **🔍 OCR Functionality for PDF Loader**: We've augmented our PDF loader with Optical Character Recognition (OCR) capabilities. Now, extract text from scanned documents and images within PDFs, broadening the scope of content processing (#1050).
510
+
511
+ ### Fixed
512
+
513
+ - **🛠️ RAG Collection**: Implemented a dynamic mechanism to recreate RAG collections, ensuring users have up-to-date and accurate data (#1031).
514
+ - **📝 User Agent Headers**: Fixed issue of RAG web requests being sent with empty user_agent headers, reducing rejections from certain websites. Realistic headers are now utilized for these requests (#1024).
515
+ - **⏹️ Playground Cancel Functionality**: Introducing a new "Cancel" option for stopping Ollama generation in the Playground, enhancing user control and usability (#1006).
516
+ - **🔤 Typographical Error in 'ASSISTANT' Field**: Corrected a typographical error in the 'ASSISTANT' field within the GGUF model upload template for accuracy and consistency (#1061).
517
+
518
+ ### Changed
519
+
520
+ - **🔄 Refactored Message Deletion Logic**: Streamlined message deletion process for improved efficiency and user experience, simplifying interactions within the platform (#1004).
521
+ - **⚠️ Deprecation of `OLLAMA_API_BASE_URL`**: Deprecated `OLLAMA_API_BASE_URL` environment variable; recommend using `OLLAMA_BASE_URL` instead. Refer to our documentation for further details.
522
+
523
+ ## [0.1.108] - 2024-03-02
524
+
525
+ ### Added
526
+
527
+ - **🎮 Playground Feature (Beta)**: Explore the full potential of the raw API through an intuitive UI with our new playground feature, accessible to admins. Simply click on the bottom name area of the sidebar to access it. The playground feature offers two modes text completion (notebook) and chat completion. As it's in beta, please report any issues you encounter.
528
+ - **🛠️ Direct Database Download for Admins**: Admins can now download the database directly from the WebUI via the admin settings.
529
+ - **🎨 Additional RAG Settings**: Customize your RAG process with the ability to edit the TOP K value. Navigate to Documents > Settings > General to make changes.
530
+ - **🖥️ UI Improvements**: Tooltips now available in the input area and sidebar handle. More tooltips will be added across other parts of the UI.
531
+
532
+ ### Fixed
533
+
534
+ - Resolved input autofocus issue on mobile when the sidebar is open, making it easier to use.
535
+ - Corrected numbered list display issue in Safari (#963).
536
+ - Restricted user ability to delete chats without proper permissions (#993).
537
+
538
+ ### Changed
539
+
540
+ - **Simplified Ollama Settings**: Ollama settings now don't require the `/api` suffix. You can now utilize the Ollama base URL directly, e.g., `http://localhost:11434`. Also, an `OLLAMA_BASE_URL` environment variable has been added.
541
+ - **Database Renaming**: Starting from this release, `ollama.db` will be automatically renamed to `webui.db`.
542
+
543
+ ## [0.1.107] - 2024-03-01
544
+
545
+ ### Added
546
+
547
+ - **🚀 Makefile and LLM Update Script**: Included Makefile and a script for LLM updates in the repository.
548
+
549
+ ### Fixed
550
+
551
+ - Corrected issue where links in the settings modal didn't appear clickable (#960).
552
+ - Fixed problem with web UI port not taking effect due to incorrect environment variable name in run-compose.sh (#996).
553
+ - Enhanced user experience by displaying chat in browser title and enabling automatic scrolling to the bottom (#992).
554
+
555
+ ### Changed
556
+
557
+ - Upgraded toast library from `svelte-french-toast` to `svelte-sonner` for a more polished UI.
558
+ - Enhanced accessibility with the addition of dark mode on the authentication page.
559
+
560
+ ## [0.1.106] - 2024-02-27
561
+
562
+ ### Added
563
+
564
+ - **🎯 Auto-focus Feature**: The input area now automatically focuses when initiating or opening a chat conversation.
565
+
566
+ ### Fixed
567
+
568
+ - Corrected typo from "HuggingFace" to "Hugging Face" (Issue #924).
569
+ - Resolved bug causing errors in chat completion API calls to OpenAI due to missing "num_ctx" parameter (Issue #927).
570
+ - Fixed issues preventing text editing, selection, and cursor retention in the input field (Issue #940).
571
+ - Fixed a bug where defining an OpenAI-compatible API server using 'OPENAI_API_BASE_URL' containing 'openai' string resulted in hiding models not containing 'gpt' string from the model menu. (Issue #930)
572
+
573
+ ## [0.1.105] - 2024-02-25
574
+
575
+ ### Added
576
+
577
+ - **📄 Document Selection**: Now you can select and delete multiple documents at once for easier management.
578
+
579
+ ### Changed
580
+
581
+ - **🏷️ Document Pre-tagging**: Simply click the "+" button at the top, enter tag names in the popup window, or select from a list of existing tags. Then, upload files with the added tags for streamlined organization.
582
+
583
+ ## [0.1.104] - 2024-02-25
584
+
585
+ ### Added
586
+
587
+ - **🔄 Check for Updates**: Keep your system current by checking for updates conveniently located in Settings > About.
588
+ - **🗑️ Automatic Tag Deletion**: Unused tags on the sidebar will now be deleted automatically with just a click.
589
+
590
+ ### Changed
591
+
592
+ - **🎨 Modernized Styling**: Enjoy a refreshed look with updated styling for a more contemporary experience.
593
+
594
+ ## [0.1.103] - 2024-02-25
595
+
596
+ ### Added
597
+
598
+ - **🔗 Built-in LiteLLM Proxy**: Now includes LiteLLM proxy within Open WebUI for enhanced functionality.
599
+
600
+ - Easily integrate existing LiteLLM configurations using `-v /path/to/config.yaml:/app/backend/data/litellm/config.yaml` flag.
601
+ - When utilizing Docker container to run Open WebUI, ensure connections to localhost use `host.docker.internal`.
602
+
603
+ - **🖼️ Image Generation Enhancements**: Introducing Advanced Settings with Image Preview Feature.
604
+ - Customize image generation by setting the number of steps; defaults to A1111 value.
605
+
606
+ ### Fixed
607
+
608
+ - Resolved issue with RAG scan halting document loading upon encountering unsupported MIME types or exceptions (Issue #866).
609
+
610
+ ### Changed
611
+
612
+ - Ollama is no longer required to run Open WebUI.
613
+ - Access our comprehensive documentation at [Open WebUI Documentation](https://docs.openwebui.com/).
614
+
615
+ ## [0.1.102] - 2024-02-22
616
+
617
+ ### Added
618
+
619
+ - **🖼️ Image Generation**: Generate Images using the AUTOMATIC1111/stable-diffusion-webui API. You can set this up in Settings > Images.
620
+ - **📝 Change title generation prompt**: Change the prompt used to generate titles for your chats. You can set this up in the Settings > Interface.
621
+ - **🤖 Change embedding model**: Change the embedding model used to generate embeddings for your chats in the Dockerfile. Use any sentence transformer model from huggingface.co.
622
+ - **📢 CHANGELOG.md/Popup**: This popup will show you the latest changes.
623
+
624
+ ## [0.1.101] - 2024-02-22
625
+
626
+ ### Fixed
627
+
628
+ - LaTex output formatting issue (#828)
629
+
630
+ ### Changed
631
+
632
+ - Instead of having the previous 1.0.0-alpha.101, we switched to semantic versioning as a way to respect global conventions.
CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
13
+
14
+ ## Our Standards
15
+
16
+ Examples of behavior that contribute to a positive environment for our community include:
17
+
18
+ - Demonstrating empathy and kindness toward other people
19
+ - Being respectful of differing opinions, viewpoints, and experiences
20
+ - Giving and gracefully accepting constructive feedback
21
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
22
+ - Focusing on what is best not just for us as individuals, but for the overall community
23
+
24
+ Examples of unacceptable behavior include:
25
+
26
+ - The use of sexualized language or imagery, and sexual attention or advances of any kind
27
+ - Trolling, insulting or derogatory comments, and personal or political attacks
28
+ - Public or private harassment
29
+ - Publishing others' private information, such as a physical or email address, without their explicit permission
30
+ - **Spamming of any kind**
31
+ - Aggressive sales tactics targeting our community members are strictly prohibited. You can mention your product if it's relevant to the discussion, but under no circumstances should you push it forcefully
32
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
33
+
34
+ ## Enforcement Responsibilities
35
+
36
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
37
+
38
+ ## Scope
39
+
40
+ This Code of Conduct applies within all community spaces and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
41
+
42
+ ## Enforcement
43
+
44
+ Instances of abusive, harassing, spamming, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hello@openwebui.com. All complaints will be reviewed and investigated promptly and fairly.
45
+
46
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
47
+
48
+ ## Enforcement Guidelines
49
+
50
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
51
+
52
+ ### 1. Temporary Ban
53
+
54
+ **Community Impact**: Any violation of community standards, including but not limited to inappropriate language, unprofessional behavior, harassment, or spamming.
55
+
56
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
57
+
58
+ ### 2. Permanent Ban
59
+
60
+ **Community Impact**: Repeated or severe violations of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
61
+
62
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
63
+
64
+ ## Attribution
65
+
66
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
67
+ version 2.0, available at
68
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
69
+
70
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
71
+ enforcement ladder](https://github.com/mozilla/diversity).
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see the FAQ at
76
+ https://www.contributor-covenant.org/faq. Translations are available at
77
+ https://www.contributor-covenant.org/translations.
Caddyfile.localhost ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Run with
2
+ # caddy run --envfile ./example.env --config ./Caddyfile.localhost
3
+ #
4
+ # This is configured for
5
+ # - Automatic HTTPS (even for localhost)
6
+ # - Reverse Proxying to Ollama API Base URL (http://localhost:11434/api)
7
+ # - CORS
8
+ # - HTTP Basic Auth API Tokens (uncomment basicauth section)
9
+
10
+
11
+ # CORS Preflight (OPTIONS) + Request (GET, POST, PATCH, PUT, DELETE)
12
+ (cors-api) {
13
+ @match-cors-api-preflight method OPTIONS
14
+ handle @match-cors-api-preflight {
15
+ header {
16
+ Access-Control-Allow-Origin "{http.request.header.origin}"
17
+ Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
18
+ Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With"
19
+ Access-Control-Allow-Credentials "true"
20
+ Access-Control-Max-Age "3600"
21
+ defer
22
+ }
23
+ respond "" 204
24
+ }
25
+
26
+ @match-cors-api-request {
27
+ not {
28
+ header Origin "{http.request.scheme}://{http.request.host}"
29
+ }
30
+ header Origin "{http.request.header.origin}"
31
+ }
32
+ handle @match-cors-api-request {
33
+ header {
34
+ Access-Control-Allow-Origin "{http.request.header.origin}"
35
+ Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
36
+ Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With"
37
+ Access-Control-Allow-Credentials "true"
38
+ Access-Control-Max-Age "3600"
39
+ defer
40
+ }
41
+ }
42
+ }
43
+
44
+ # replace localhost with example.com or whatever
45
+ localhost {
46
+ ## HTTP Basic Auth
47
+ ## (uncomment to enable)
48
+ # basicauth {
49
+ # # see .example.env for how to generate tokens
50
+ # {env.OLLAMA_API_ID} {env.OLLAMA_API_TOKEN_DIGEST}
51
+ # }
52
+
53
+ handle /api/* {
54
+ # Comment to disable CORS
55
+ import cors-api
56
+
57
+ reverse_proxy localhost:11434
58
+ }
59
+
60
+ # Same-Origin Static Web Server
61
+ file_server {
62
+ root ./build/
63
+ }
64
+ }
Dockerfile ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1
2
+ # Initialize device type args
3
+ # use build args in the docker build commmand with --build-arg="BUILDARG=true"
4
+ ARG USE_CUDA=false
5
+ ARG USE_OLLAMA=false
6
+ # Tested with cu117 for CUDA 11 and cu121 for CUDA 12 (default)
7
+ ARG USE_CUDA_VER=cu121
8
+ # any sentence transformer model; models to use can be found at https://huggingface.co/models?library=sentence-transformers
9
+ # Leaderboard: https://huggingface.co/spaces/mteb/leaderboard
10
+ # for better performance and multilangauge support use "intfloat/multilingual-e5-large" (~2.5GB) or "intfloat/multilingual-e5-base" (~1.5GB)
11
+ # 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.
12
+ ARG USE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
13
+ ARG USE_RERANKING_MODEL=""
14
+ ARG BUILD_HASH=dev-build
15
+ # Override at your own risk - non-root configurations are untested
16
+ ARG UID=0
17
+ ARG GID=0
18
+
19
+ ######## WebUI frontend ########
20
+ FROM --platform=$BUILDPLATFORM node:21-alpine3.19 as build
21
+ ARG BUILD_HASH
22
+
23
+ WORKDIR /app
24
+
25
+ COPY package.json package-lock.json ./
26
+ RUN npm ci
27
+
28
+ COPY . .
29
+ ENV APP_BUILD_HASH=${BUILD_HASH}
30
+ RUN npm run build
31
+
32
+ ######## WebUI backend ########
33
+ FROM python:3.11-slim-bookworm as base
34
+
35
+ # Use args
36
+ ARG USE_CUDA
37
+ ARG USE_OLLAMA
38
+ ARG USE_CUDA_VER
39
+ ARG USE_EMBEDDING_MODEL
40
+ ARG USE_RERANKING_MODEL
41
+ ARG UID
42
+ ARG GID
43
+
44
+ ## Basis ##
45
+ ENV ENV=prod \
46
+ PORT=8080 \
47
+ # pass build args to the build
48
+ USE_OLLAMA_DOCKER=${USE_OLLAMA} \
49
+ USE_CUDA_DOCKER=${USE_CUDA} \
50
+ USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \
51
+ USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL} \
52
+ USE_RERANKING_MODEL_DOCKER=${USE_RERANKING_MODEL}
53
+
54
+ ## Basis URL Config ##
55
+ ENV OLLAMA_BASE_URL="/ollama" \
56
+ OPENAI_API_BASE_URL=""
57
+
58
+ ## API Key and Security Config ##
59
+ ENV OPENAI_API_KEY="" \
60
+ WEBUI_SECRET_KEY="" \
61
+ SCARF_NO_ANALYTICS=true \
62
+ DO_NOT_TRACK=true \
63
+ ANONYMIZED_TELEMETRY=false
64
+
65
+ #### Other models #########################################################
66
+ ## whisper TTS model settings ##
67
+ ENV WHISPER_MODEL="base" \
68
+ WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
69
+
70
+ ## RAG Embedding model settings ##
71
+ ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
72
+ RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \
73
+ SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
74
+
75
+ ## Hugging Face download cache ##
76
+ ENV HF_HOME="/app/backend/data/cache/embedding/models"
77
+ #### Other models ##########################################################
78
+
79
+ WORKDIR /app/backend
80
+
81
+ ENV HOME /root
82
+ # Create user and group if not root
83
+ RUN if [ $UID -ne 0 ]; then \
84
+ if [ $GID -ne 0 ]; then \
85
+ addgroup --gid $GID app; \
86
+ fi; \
87
+ adduser --uid $UID --gid $GID --home $HOME --disabled-password --no-create-home app; \
88
+ fi
89
+
90
+ RUN mkdir -p $HOME/.cache/chroma
91
+ RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
92
+
93
+ # Make sure the user has access to the app and root directory
94
+ RUN chown -R $UID:$GID /app $HOME
95
+
96
+ RUN if [ "$USE_OLLAMA" = "true" ]; then \
97
+ apt-get update && \
98
+ # Install pandoc and netcat
99
+ apt-get install -y --no-install-recommends pandoc netcat-openbsd curl && \
100
+ # for RAG OCR
101
+ apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
102
+ # install helper tools
103
+ apt-get install -y --no-install-recommends curl jq && \
104
+ # install ollama
105
+ curl -fsSL https://ollama.com/install.sh | sh && \
106
+ # cleanup
107
+ rm -rf /var/lib/apt/lists/*; \
108
+ else \
109
+ apt-get update && \
110
+ # Install pandoc and netcat
111
+ apt-get install -y --no-install-recommends pandoc netcat-openbsd curl jq && \
112
+ # for RAG OCR
113
+ apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
114
+ # cleanup
115
+ rm -rf /var/lib/apt/lists/*; \
116
+ fi
117
+
118
+ # install python dependencies
119
+ COPY --chown=$UID:$GID ./backend/requirements.txt ./requirements.txt
120
+
121
+ RUN pip3 install uv && \
122
+ if [ "$USE_CUDA" = "true" ]; then \
123
+ # If you use CUDA the whisper and embedding model will be downloaded on first use
124
+ pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
125
+ uv pip install --system -r requirements.txt --no-cache-dir && \
126
+ python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
127
+ 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'])"; \
128
+ else \
129
+ pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
130
+ uv pip install --system -r requirements.txt --no-cache-dir && \
131
+ python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
132
+ 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'])"; \
133
+ fi; \
134
+ chown -R $UID:$GID /app/backend/data/
135
+
136
+
137
+
138
+ # copy embedding weight from build
139
+ # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
140
+ # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
141
+
142
+ # copy built frontend files
143
+ COPY --chown=$UID:$GID --from=build /app/build /app/build
144
+ COPY --chown=$UID:$GID --from=build /app/CHANGELOG.md /app/CHANGELOG.md
145
+ COPY --chown=$UID:$GID --from=build /app/package.json /app/package.json
146
+
147
+ # copy backend files
148
+ COPY --chown=$UID:$GID ./backend .
149
+
150
+ EXPOSE 8080
151
+
152
+ HEALTHCHECK CMD curl --silent --fail http://localhost:8080/health | jq -e '.status == true' || exit 1
153
+
154
+ USER $UID:$GID
155
+
156
+ ARG BUILD_HASH
157
+ ENV WEBUI_BUILD_VERSION=${BUILD_HASH}
158
+
159
+ CMD [ "bash", "start.sh"]
INSTALLATION.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Installing Both Ollama and Open WebUI Using Kustomize
2
+
3
+ For cpu-only pod
4
+
5
+ ```bash
6
+ kubectl apply -f ./kubernetes/manifest/base
7
+ ```
8
+
9
+ For gpu-enabled pod
10
+
11
+ ```bash
12
+ kubectl apply -k ./kubernetes/manifest
13
+ ```
14
+
15
+ ### Installing Both Ollama and Open WebUI Using Helm
16
+
17
+ Package Helm file first
18
+
19
+ ```bash
20
+ helm package ./kubernetes/helm/
21
+ ```
22
+
23
+ For cpu-only pod
24
+
25
+ ```bash
26
+ helm install ollama-webui ./ollama-webui-*.tgz
27
+ ```
28
+
29
+ For gpu-enabled pod
30
+
31
+ ```bash
32
+ helm install ollama-webui ./ollama-webui-*.tgz --set ollama.resources.limits.nvidia.com/gpu="1"
33
+ ```
34
+
35
+ Check the `kubernetes/helm/values.yaml` file to know which parameters are available for customization
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Timothy Jaeryang Baek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Makefile ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ifneq ($(shell which docker-compose 2>/dev/null),)
3
+ DOCKER_COMPOSE := docker-compose
4
+ else
5
+ DOCKER_COMPOSE := docker compose
6
+ endif
7
+
8
+ install:
9
+ $(DOCKER_COMPOSE) up -d
10
+
11
+ remove:
12
+ @chmod +x confirm_remove.sh
13
+ @./confirm_remove.sh
14
+
15
+ start:
16
+ $(DOCKER_COMPOSE) start
17
+ startAndBuild:
18
+ $(DOCKER_COMPOSE) up -d --build
19
+
20
+ stop:
21
+ $(DOCKER_COMPOSE) stop
22
+
23
+ update:
24
+ # Calls the LLM update script
25
+ chmod +x update_ollama_models.sh
26
+ @./update_ollama_models.sh
27
+ @git pull
28
+ $(DOCKER_COMPOSE) down
29
+ # Make sure the ollama-webui container is stopped before rebuilding
30
+ @docker stop open-webui || true
31
+ $(DOCKER_COMPOSE) up --build -d
32
+ $(DOCKER_COMPOSE) start
33
+
README.md ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Open WebUI
3
+ emoji: 🐳
4
+ colorFrom: purple
5
+ colorTo: gray
6
+ sdk: docker
7
+ app_port: 8080
8
+ ---
9
+ # Open WebUI (Formerly Ollama WebUI) 👋
10
+
11
+ ![GitHub stars](https://img.shields.io/github/stars/open-webui/open-webui?style=social)
12
+ ![GitHub forks](https://img.shields.io/github/forks/open-webui/open-webui?style=social)
13
+ ![GitHub watchers](https://img.shields.io/github/watchers/open-webui/open-webui?style=social)
14
+ ![GitHub repo size](https://img.shields.io/github/repo-size/open-webui/open-webui)
15
+ ![GitHub language count](https://img.shields.io/github/languages/count/open-webui/open-webui)
16
+ ![GitHub top language](https://img.shields.io/github/languages/top/open-webui/open-webui)
17
+ ![GitHub last commit](https://img.shields.io/github/last-commit/open-webui/open-webui?color=red)
18
+ ![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Follama-webui%2Follama-wbui&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)
19
+ [![Discord](https://img.shields.io/badge/Discord-Open_WebUI-blue?logo=discord&logoColor=white)](https://discord.gg/5rJgQTnV4s)
20
+ [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/tjbck)
21
+
22
+ Open WebUI is an [extensible](https://github.com/open-webui/pipelines), feature-rich, and user-friendly self-hosted WebUI designed to operate entirely offline. It supports various LLM runners, including Ollama and OpenAI-compatible APIs. For more information, be sure to check out our [Open WebUI Documentation](https://docs.openwebui.com/).
23
+
24
+ ![Open WebUI Demo](./demo.gif)
25
+
26
+ ## Key Features of Open WebUI ⭐
27
+
28
+ - 🚀 **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.
29
+
30
+ - 🤝 **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**.
31
+
32
+ - 🧩 **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.
33
+
34
+ - 📱 **Responsive Design**: Enjoy a seamless experience across Desktop PC, Laptop, and Mobile devices.
35
+
36
+ - 📱 **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.
37
+
38
+ - ✒️🔢 **Full Markdown and LaTeX Support**: Elevate your LLM experience with comprehensive Markdown and LaTeX capabilities for enriched interaction.
39
+
40
+ - 🎤📹 **Hands-Free Voice/Video Call**: Experience seamless communication with integrated hands-free voice and video call features, allowing for a more dynamic and interactive chat environment.
41
+
42
+ - 🛠️ **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.
43
+
44
+ - 🐍 **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.
45
+
46
+ - 📚 **Local RAG Integration**: Dive into the future of chat interactions with groundbreaking Retrieval Augmented Generation (RAG) support. This feature seamlessly integrates document interactions into your chat experience. You can load documents directly into the chat or add files to your document library, effortlessly accessing them using the `#` command before a query.
47
+
48
+ - 🔍 **Web Search for RAG**: Perform web searches using providers like `SearXNG`, `Google PSE`, `Brave Search`, `serpstack`, `serper`, `Serply`, `DuckDuckGo` and `TavilySearch` and inject the results directly into your chat experience.
49
+
50
+ - 🌐 **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.
51
+
52
+ - 🎨 **Image Generation Integration**: Seamlessly incorporate image generation capabilities using options such as AUTOMATIC1111 API or ComfyUI (local), and OpenAI's DALL-E (external), enriching your chat experience with dynamic visual content.
53
+
54
+ - ⚙️ **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.
55
+
56
+ - 🔐 **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.
57
+
58
+ - 🌐🌍 **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!
59
+
60
+ - 🌟 **Continuous Updates**: We are committed to improving Open WebUI with regular updates, fixes, and new features.
61
+
62
+ Want to learn more about Open WebUI's features? Check out our [Open WebUI documentation](https://docs.openwebui.com/features) for a comprehensive overview!
63
+
64
+ ## 🔗 Also Check Out Open WebUI Community!
65
+
66
+ Don't forget to explore our sibling project, [Open WebUI Community](https://openwebui.com/), where you can discover, download, and explore customized Modelfiles. Open WebUI Community offers a wide range of exciting possibilities for enhancing your chat interactions with Open WebUI! 🚀
67
+
68
+ ## How to Install 🚀
69
+
70
+ > [!NOTE]
71
+ > 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.
72
+
73
+ ### Quick Start with Docker 🐳
74
+
75
+ > [!WARNING]
76
+ > 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.
77
+
78
+ > [!TIP]
79
+ > 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.
80
+
81
+ ### Installation with Default Configuration
82
+
83
+ - **If Ollama is on your computer**, use this command:
84
+
85
+ ```bash
86
+ 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
87
+ ```
88
+
89
+ - **If Ollama is on a Different Server**, use this command:
90
+
91
+ To connect to Ollama on another server, change the `OLLAMA_BASE_URL` to the server's URL:
92
+
93
+ ```bash
94
+ 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
95
+ ```
96
+
97
+ - **To run Open WebUI with Nvidia GPU support**, use this command:
98
+
99
+ ```bash
100
+ 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
101
+ ```
102
+
103
+ ### Installation for OpenAI API Usage Only
104
+
105
+ - **If you're only using OpenAI API**, use this command:
106
+
107
+ ```bash
108
+ 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
109
+ ```
110
+
111
+ ### Installing Open WebUI with Bundled Ollama Support
112
+
113
+ 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:
114
+
115
+ - **With GPU Support**:
116
+ Utilize GPU resources by running the following command:
117
+
118
+ ```bash
119
+ 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
120
+ ```
121
+
122
+ - **For CPU Only**:
123
+ If you're not using a GPU, use this command instead:
124
+
125
+ ```bash
126
+ 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
127
+ ```
128
+
129
+ 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.
130
+
131
+ After installation, you can access Open WebUI at [http://localhost:3000](http://localhost:3000). Enjoy! 😄
132
+
133
+ ### Other Installation Methods
134
+
135
+ 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.
136
+
137
+ ### Troubleshooting
138
+
139
+ 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).
140
+
141
+ #### Open WebUI: Server Connection Error
142
+
143
+ 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`.
144
+
145
+ **Example Docker Command**:
146
+
147
+ ```bash
148
+ docker 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
149
+ ```
150
+
151
+ ### Keeping Your Docker Installation Up-to-Date
152
+
153
+ In case you want to update your local Docker installation to the latest version, you can do it with [Watchtower](https://containrrr.dev/watchtower/):
154
+
155
+ ```bash
156
+ docker run --rm --volume /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --run-once open-webui
157
+ ```
158
+
159
+ In the last part of the command, replace `open-webui` with your container name if it is different.
160
+
161
+ Check our Migration Guide available in our [Open WebUI Documentation](https://docs.openwebui.com/migration/).
162
+
163
+ ### Using the Dev Branch 🌙
164
+
165
+ > [!WARNING]
166
+ > The `:dev` branch contains the latest unstable features and changes. Use it at your own risk as it may have bugs or incomplete features.
167
+
168
+ 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:
169
+
170
+ ```bash
171
+ docker 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
172
+ ```
173
+
174
+ ## What's Next? 🌟
175
+
176
+ Discover upcoming features on our roadmap in the [Open WebUI Documentation](https://docs.openwebui.com/roadmap/).
177
+
178
+ ## Supporters ✨
179
+
180
+ A big shoutout to our amazing supporters who's helping to make this project possible! 🙏
181
+
182
+ ### Platinum Sponsors 🤍
183
+
184
+ - We're looking for Sponsors!
185
+
186
+ ### Acknowledgments
187
+
188
+ Special thanks to [Prof. Lawrence Kim](https://www.lhkim.com/) and [Prof. Nick Vincent](https://www.nickmvincent.com/) for their invaluable support and guidance in shaping this project into a research endeavor. Grateful for your mentorship throughout the journey! 🙌
189
+
190
+ ## License 📜
191
+
192
+ This project is licensed under the [MIT License](LICENSE) - see the [LICENSE](LICENSE) file for details. 📄
193
+
194
+ ## Support 💬
195
+
196
+ If you have any questions, suggestions, or need assistance, please open an issue or join our
197
+ [Open WebUI Discord community](https://discord.gg/5rJgQTnV4s) to connect with us! 🤝
198
+
199
+ ## Star History
200
+
201
+ <a href="https://star-history.com/#open-webui/open-webui&Date">
202
+ <picture>
203
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=open-webui/open-webui&type=Date&theme=dark" />
204
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=open-webui/open-webui&type=Date" />
205
+ <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=open-webui/open-webui&type=Date" />
206
+ </picture>
207
+ </a>
208
+
209
+ ---
210
+
211
+ Created by [Timothy J. Baek](https://github.com/tjbck) - Let's make Open WebUI even more amazing together! 💪
TROUBLESHOOTING.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Open WebUI Troubleshooting Guide
2
+
3
+ ## Understanding the Open WebUI Architecture
4
+
5
+ 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.
6
+
7
+ - **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.
8
+
9
+ - **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.
10
+
11
+ ## Open WebUI: Server Connection Error
12
+
13
+ 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`.
14
+
15
+ **Example Docker Command**:
16
+
17
+ ```bash
18
+ docker 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
19
+ ```
20
+
21
+ ### Error on Slow Reponses for Ollama
22
+
23
+ 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.
24
+
25
+ ### General Connection Errors
26
+
27
+ **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.
28
+
29
+ **Troubleshooting Steps**:
30
+
31
+ 1. **Verify Ollama URL Format**:
32
+ - 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).
33
+ - In the Open WebUI, navigate to "Settings" > "General".
34
+ - Confirm that the Ollama Server URL is correctly set to `[OLLAMA URL]` (e.g., `http://localhost:11434`).
35
+
36
+ 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.
backend/.dockerignore ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__
2
+ .env
3
+ _old
4
+ uploads
5
+ .ipynb_checkpoints
6
+ *.db
7
+ _test
8
+ !/data
9
+ /data/*
10
+ !/data/litellm
11
+ /data/litellm/*
12
+ !data/litellm/config.yaml
13
+
14
+ !data/config.json
backend/.gitignore ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__
2
+ .env
3
+ _old
4
+ uploads
5
+ .ipynb_checkpoints
6
+ *.db
7
+ _test
8
+ Pipfile
9
+ !/data
10
+ /data/*
11
+ !/data/litellm
12
+ /data/litellm/*
13
+ !data/litellm/config.yaml
14
+
15
+ !data/config.json
16
+ .webui_secret_key
backend/apps/audio/main.py ADDED
@@ -0,0 +1,374 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import logging
3
+ from fastapi import (
4
+ FastAPI,
5
+ Request,
6
+ Depends,
7
+ HTTPException,
8
+ status,
9
+ UploadFile,
10
+ File,
11
+ Form,
12
+ )
13
+
14
+ from fastapi.responses import StreamingResponse, JSONResponse, FileResponse
15
+
16
+ from fastapi.middleware.cors import CORSMiddleware
17
+ from faster_whisper import WhisperModel
18
+ from pydantic import BaseModel
19
+
20
+ import uuid
21
+ import requests
22
+ import hashlib
23
+ from pathlib import Path
24
+ import json
25
+
26
+ from constants import ERROR_MESSAGES
27
+ from utils.utils import (
28
+ decode_token,
29
+ get_current_user,
30
+ get_verified_user,
31
+ get_admin_user,
32
+ )
33
+ from utils.misc import calculate_sha256
34
+
35
+ from config import (
36
+ SRC_LOG_LEVELS,
37
+ CACHE_DIR,
38
+ UPLOAD_DIR,
39
+ WHISPER_MODEL,
40
+ WHISPER_MODEL_DIR,
41
+ WHISPER_MODEL_AUTO_UPDATE,
42
+ DEVICE_TYPE,
43
+ AUDIO_STT_OPENAI_API_BASE_URL,
44
+ AUDIO_STT_OPENAI_API_KEY,
45
+ AUDIO_TTS_OPENAI_API_BASE_URL,
46
+ AUDIO_TTS_OPENAI_API_KEY,
47
+ AUDIO_STT_ENGINE,
48
+ AUDIO_STT_MODEL,
49
+ AUDIO_TTS_ENGINE,
50
+ AUDIO_TTS_MODEL,
51
+ AUDIO_TTS_VOICE,
52
+ AppConfig,
53
+ )
54
+
55
+ log = logging.getLogger(__name__)
56
+ log.setLevel(SRC_LOG_LEVELS["AUDIO"])
57
+
58
+ app = FastAPI()
59
+ app.add_middleware(
60
+ CORSMiddleware,
61
+ allow_origins=["*"],
62
+ allow_credentials=True,
63
+ allow_methods=["*"],
64
+ allow_headers=["*"],
65
+ )
66
+
67
+ app.state.config = AppConfig()
68
+
69
+ app.state.config.STT_OPENAI_API_BASE_URL = AUDIO_STT_OPENAI_API_BASE_URL
70
+ app.state.config.STT_OPENAI_API_KEY = AUDIO_STT_OPENAI_API_KEY
71
+ app.state.config.STT_ENGINE = AUDIO_STT_ENGINE
72
+ app.state.config.STT_MODEL = AUDIO_STT_MODEL
73
+
74
+ app.state.config.TTS_OPENAI_API_BASE_URL = AUDIO_TTS_OPENAI_API_BASE_URL
75
+ app.state.config.TTS_OPENAI_API_KEY = AUDIO_TTS_OPENAI_API_KEY
76
+ app.state.config.TTS_ENGINE = AUDIO_TTS_ENGINE
77
+ app.state.config.TTS_MODEL = AUDIO_TTS_MODEL
78
+ app.state.config.TTS_VOICE = AUDIO_TTS_VOICE
79
+
80
+ # setting device type for whisper model
81
+ whisper_device_type = DEVICE_TYPE if DEVICE_TYPE and DEVICE_TYPE == "cuda" else "cpu"
82
+ log.info(f"whisper_device_type: {whisper_device_type}")
83
+
84
+ SPEECH_CACHE_DIR = Path(CACHE_DIR).joinpath("./audio/speech/")
85
+ SPEECH_CACHE_DIR.mkdir(parents=True, exist_ok=True)
86
+
87
+
88
+ class TTSConfigForm(BaseModel):
89
+ OPENAI_API_BASE_URL: str
90
+ OPENAI_API_KEY: str
91
+ ENGINE: str
92
+ MODEL: str
93
+ VOICE: str
94
+
95
+
96
+ class STTConfigForm(BaseModel):
97
+ OPENAI_API_BASE_URL: str
98
+ OPENAI_API_KEY: str
99
+ ENGINE: str
100
+ MODEL: str
101
+
102
+
103
+ class AudioConfigUpdateForm(BaseModel):
104
+ tts: TTSConfigForm
105
+ stt: STTConfigForm
106
+
107
+
108
+ from pydub import AudioSegment
109
+ from pydub.utils import mediainfo
110
+
111
+
112
+ def is_mp4_audio(file_path):
113
+ """Check if the given file is an MP4 audio file."""
114
+ if not os.path.isfile(file_path):
115
+ print(f"File not found: {file_path}")
116
+ return False
117
+
118
+ info = mediainfo(file_path)
119
+ if (
120
+ info.get("codec_name") == "aac"
121
+ and info.get("codec_type") == "audio"
122
+ and info.get("codec_tag_string") == "mp4a"
123
+ ):
124
+ return True
125
+ return False
126
+
127
+
128
+ def convert_mp4_to_wav(file_path, output_path):
129
+ """Convert MP4 audio file to WAV format."""
130
+ audio = AudioSegment.from_file(file_path, format="mp4")
131
+ audio.export(output_path, format="wav")
132
+ print(f"Converted {file_path} to {output_path}")
133
+
134
+
135
+ @app.get("/config")
136
+ async def get_audio_config(user=Depends(get_admin_user)):
137
+ return {
138
+ "tts": {
139
+ "OPENAI_API_BASE_URL": app.state.config.TTS_OPENAI_API_BASE_URL,
140
+ "OPENAI_API_KEY": app.state.config.TTS_OPENAI_API_KEY,
141
+ "ENGINE": app.state.config.TTS_ENGINE,
142
+ "MODEL": app.state.config.TTS_MODEL,
143
+ "VOICE": app.state.config.TTS_VOICE,
144
+ },
145
+ "stt": {
146
+ "OPENAI_API_BASE_URL": app.state.config.STT_OPENAI_API_BASE_URL,
147
+ "OPENAI_API_KEY": app.state.config.STT_OPENAI_API_KEY,
148
+ "ENGINE": app.state.config.STT_ENGINE,
149
+ "MODEL": app.state.config.STT_MODEL,
150
+ },
151
+ }
152
+
153
+
154
+ @app.post("/config/update")
155
+ async def update_audio_config(
156
+ form_data: AudioConfigUpdateForm, user=Depends(get_admin_user)
157
+ ):
158
+ app.state.config.TTS_OPENAI_API_BASE_URL = form_data.tts.OPENAI_API_BASE_URL
159
+ app.state.config.TTS_OPENAI_API_KEY = form_data.tts.OPENAI_API_KEY
160
+ app.state.config.TTS_ENGINE = form_data.tts.ENGINE
161
+ app.state.config.TTS_MODEL = form_data.tts.MODEL
162
+ app.state.config.TTS_VOICE = form_data.tts.VOICE
163
+
164
+ app.state.config.STT_OPENAI_API_BASE_URL = form_data.stt.OPENAI_API_BASE_URL
165
+ app.state.config.STT_OPENAI_API_KEY = form_data.stt.OPENAI_API_KEY
166
+ app.state.config.STT_ENGINE = form_data.stt.ENGINE
167
+ app.state.config.STT_MODEL = form_data.stt.MODEL
168
+
169
+ return {
170
+ "tts": {
171
+ "OPENAI_API_BASE_URL": app.state.config.TTS_OPENAI_API_BASE_URL,
172
+ "OPENAI_API_KEY": app.state.config.TTS_OPENAI_API_KEY,
173
+ "ENGINE": app.state.config.TTS_ENGINE,
174
+ "MODEL": app.state.config.TTS_MODEL,
175
+ "VOICE": app.state.config.TTS_VOICE,
176
+ },
177
+ "stt": {
178
+ "OPENAI_API_BASE_URL": app.state.config.STT_OPENAI_API_BASE_URL,
179
+ "OPENAI_API_KEY": app.state.config.STT_OPENAI_API_KEY,
180
+ "ENGINE": app.state.config.STT_ENGINE,
181
+ "MODEL": app.state.config.STT_MODEL,
182
+ },
183
+ }
184
+
185
+
186
+ @app.post("/speech")
187
+ async def speech(request: Request, user=Depends(get_verified_user)):
188
+ body = await request.body()
189
+ name = hashlib.sha256(body).hexdigest()
190
+
191
+ file_path = SPEECH_CACHE_DIR.joinpath(f"{name}.mp3")
192
+ file_body_path = SPEECH_CACHE_DIR.joinpath(f"{name}.json")
193
+
194
+ # Check if the file already exists in the cache
195
+ if file_path.is_file():
196
+ return FileResponse(file_path)
197
+
198
+ headers = {}
199
+ headers["Authorization"] = f"Bearer {app.state.config.TTS_OPENAI_API_KEY}"
200
+ headers["Content-Type"] = "application/json"
201
+
202
+ try:
203
+ body = body.decode("utf-8")
204
+ body = json.loads(body)
205
+ body["model"] = app.state.config.TTS_MODEL
206
+ body = json.dumps(body).encode("utf-8")
207
+ except Exception as e:
208
+ pass
209
+
210
+ r = None
211
+ try:
212
+ r = requests.post(
213
+ url=f"{app.state.config.TTS_OPENAI_API_BASE_URL}/audio/speech",
214
+ data=body,
215
+ headers=headers,
216
+ stream=True,
217
+ )
218
+
219
+ r.raise_for_status()
220
+
221
+ # Save the streaming content to a file
222
+ with open(file_path, "wb") as f:
223
+ for chunk in r.iter_content(chunk_size=8192):
224
+ f.write(chunk)
225
+
226
+ with open(file_body_path, "w") as f:
227
+ json.dump(json.loads(body.decode("utf-8")), f)
228
+
229
+ # Return the saved file
230
+ return FileResponse(file_path)
231
+
232
+ except Exception as e:
233
+ log.exception(e)
234
+ error_detail = "Open WebUI: Server Connection Error"
235
+ if r is not None:
236
+ try:
237
+ res = r.json()
238
+ if "error" in res:
239
+ error_detail = f"External: {res['error']['message']}"
240
+ except:
241
+ error_detail = f"External: {e}"
242
+
243
+ raise HTTPException(
244
+ status_code=r.status_code if r != None else 500,
245
+ detail=error_detail,
246
+ )
247
+
248
+
249
+ @app.post("/transcriptions")
250
+ def transcribe(
251
+ file: UploadFile = File(...),
252
+ user=Depends(get_current_user),
253
+ ):
254
+ log.info(f"file.content_type: {file.content_type}")
255
+
256
+ if file.content_type not in ["audio/mpeg", "audio/wav"]:
257
+ raise HTTPException(
258
+ status_code=status.HTTP_400_BAD_REQUEST,
259
+ detail=ERROR_MESSAGES.FILE_NOT_SUPPORTED,
260
+ )
261
+
262
+ try:
263
+ ext = file.filename.split(".")[-1]
264
+
265
+ id = uuid.uuid4()
266
+ filename = f"{id}.{ext}"
267
+
268
+ file_dir = f"{CACHE_DIR}/audio/transcriptions"
269
+ os.makedirs(file_dir, exist_ok=True)
270
+ file_path = f"{file_dir}/{filename}"
271
+
272
+ print(filename)
273
+
274
+ contents = file.file.read()
275
+ with open(file_path, "wb") as f:
276
+ f.write(contents)
277
+ f.close()
278
+
279
+ if app.state.config.STT_ENGINE == "":
280
+ whisper_kwargs = {
281
+ "model_size_or_path": WHISPER_MODEL,
282
+ "device": whisper_device_type,
283
+ "compute_type": "int8",
284
+ "download_root": WHISPER_MODEL_DIR,
285
+ "local_files_only": not WHISPER_MODEL_AUTO_UPDATE,
286
+ }
287
+
288
+ log.debug(f"whisper_kwargs: {whisper_kwargs}")
289
+
290
+ try:
291
+ model = WhisperModel(**whisper_kwargs)
292
+ except:
293
+ log.warning(
294
+ "WhisperModel initialization failed, attempting download with local_files_only=False"
295
+ )
296
+ whisper_kwargs["local_files_only"] = False
297
+ model = WhisperModel(**whisper_kwargs)
298
+
299
+ segments, info = model.transcribe(file_path, beam_size=5)
300
+ log.info(
301
+ "Detected language '%s' with probability %f"
302
+ % (info.language, info.language_probability)
303
+ )
304
+
305
+ transcript = "".join([segment.text for segment in list(segments)])
306
+
307
+ data = {"text": transcript.strip()}
308
+
309
+ # save the transcript to a json file
310
+ transcript_file = f"{file_dir}/{id}.json"
311
+ with open(transcript_file, "w") as f:
312
+ json.dump(data, f)
313
+
314
+ print(data)
315
+
316
+ return data
317
+
318
+ elif app.state.config.STT_ENGINE == "openai":
319
+ if is_mp4_audio(file_path):
320
+ print("is_mp4_audio")
321
+ os.rename(file_path, file_path.replace(".wav", ".mp4"))
322
+ # Convert MP4 audio file to WAV format
323
+ convert_mp4_to_wav(file_path.replace(".wav", ".mp4"), file_path)
324
+
325
+ headers = {"Authorization": f"Bearer {app.state.config.STT_OPENAI_API_KEY}"}
326
+
327
+ files = {"file": (filename, open(file_path, "rb"))}
328
+ data = {"model": "whisper-1"}
329
+
330
+ print(files, data)
331
+
332
+ r = None
333
+ try:
334
+ r = requests.post(
335
+ url=f"{app.state.config.STT_OPENAI_API_BASE_URL}/audio/transcriptions",
336
+ headers=headers,
337
+ files=files,
338
+ data=data,
339
+ )
340
+
341
+ r.raise_for_status()
342
+
343
+ data = r.json()
344
+
345
+ # save the transcript to a json file
346
+ transcript_file = f"{file_dir}/{id}.json"
347
+ with open(transcript_file, "w") as f:
348
+ json.dump(data, f)
349
+
350
+ print(data)
351
+ return data
352
+ except Exception as e:
353
+ log.exception(e)
354
+ error_detail = "Open WebUI: Server Connection Error"
355
+ if r is not None:
356
+ try:
357
+ res = r.json()
358
+ if "error" in res:
359
+ error_detail = f"External: {res['error']['message']}"
360
+ except:
361
+ error_detail = f"External: {e}"
362
+
363
+ raise HTTPException(
364
+ status_code=r.status_code if r != None else 500,
365
+ detail=error_detail,
366
+ )
367
+
368
+ except Exception as e:
369
+ log.exception(e)
370
+
371
+ raise HTTPException(
372
+ status_code=status.HTTP_400_BAD_REQUEST,
373
+ detail=ERROR_MESSAGES.DEFAULT(e),
374
+ )
backend/apps/images/main.py ADDED
@@ -0,0 +1,547 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import requests
3
+ from fastapi import (
4
+ FastAPI,
5
+ Request,
6
+ Depends,
7
+ HTTPException,
8
+ status,
9
+ UploadFile,
10
+ File,
11
+ Form,
12
+ )
13
+ from fastapi.middleware.cors import CORSMiddleware
14
+ from faster_whisper import WhisperModel
15
+
16
+ from constants import ERROR_MESSAGES
17
+ from utils.utils import (
18
+ get_current_user,
19
+ get_admin_user,
20
+ )
21
+
22
+ from apps.images.utils.comfyui import ImageGenerationPayload, comfyui_generate_image
23
+ from utils.misc import calculate_sha256
24
+ from typing import Optional
25
+ from pydantic import BaseModel
26
+ from pathlib import Path
27
+ import mimetypes
28
+ import uuid
29
+ import base64
30
+ import json
31
+ import logging
32
+
33
+ from config import (
34
+ SRC_LOG_LEVELS,
35
+ CACHE_DIR,
36
+ IMAGE_GENERATION_ENGINE,
37
+ ENABLE_IMAGE_GENERATION,
38
+ AUTOMATIC1111_BASE_URL,
39
+ COMFYUI_BASE_URL,
40
+ COMFYUI_CFG_SCALE,
41
+ COMFYUI_SAMPLER,
42
+ COMFYUI_SCHEDULER,
43
+ COMFYUI_SD3,
44
+ IMAGES_OPENAI_API_BASE_URL,
45
+ IMAGES_OPENAI_API_KEY,
46
+ IMAGE_GENERATION_MODEL,
47
+ IMAGE_SIZE,
48
+ IMAGE_STEPS,
49
+ AppConfig,
50
+ )
51
+
52
+
53
+ log = logging.getLogger(__name__)
54
+ log.setLevel(SRC_LOG_LEVELS["IMAGES"])
55
+
56
+ IMAGE_CACHE_DIR = Path(CACHE_DIR).joinpath("./image/generations/")
57
+ IMAGE_CACHE_DIR.mkdir(parents=True, exist_ok=True)
58
+
59
+ app = FastAPI()
60
+ app.add_middleware(
61
+ CORSMiddleware,
62
+ allow_origins=["*"],
63
+ allow_credentials=True,
64
+ allow_methods=["*"],
65
+ allow_headers=["*"],
66
+ )
67
+
68
+ app.state.config = AppConfig()
69
+
70
+ app.state.config.ENGINE = IMAGE_GENERATION_ENGINE
71
+ app.state.config.ENABLED = ENABLE_IMAGE_GENERATION
72
+
73
+ app.state.config.OPENAI_API_BASE_URL = IMAGES_OPENAI_API_BASE_URL
74
+ app.state.config.OPENAI_API_KEY = IMAGES_OPENAI_API_KEY
75
+
76
+ app.state.config.MODEL = IMAGE_GENERATION_MODEL
77
+
78
+
79
+ app.state.config.AUTOMATIC1111_BASE_URL = AUTOMATIC1111_BASE_URL
80
+ app.state.config.COMFYUI_BASE_URL = COMFYUI_BASE_URL
81
+
82
+
83
+ app.state.config.IMAGE_SIZE = IMAGE_SIZE
84
+ app.state.config.IMAGE_STEPS = IMAGE_STEPS
85
+ app.state.config.COMFYUI_CFG_SCALE = COMFYUI_CFG_SCALE
86
+ app.state.config.COMFYUI_SAMPLER = COMFYUI_SAMPLER
87
+ app.state.config.COMFYUI_SCHEDULER = COMFYUI_SCHEDULER
88
+ app.state.config.COMFYUI_SD3 = COMFYUI_SD3
89
+
90
+
91
+ @app.get("/config")
92
+ async def get_config(request: Request, user=Depends(get_admin_user)):
93
+ return {
94
+ "engine": app.state.config.ENGINE,
95
+ "enabled": app.state.config.ENABLED,
96
+ }
97
+
98
+
99
+ class ConfigUpdateForm(BaseModel):
100
+ engine: str
101
+ enabled: bool
102
+
103
+
104
+ @app.post("/config/update")
105
+ async def update_config(form_data: ConfigUpdateForm, user=Depends(get_admin_user)):
106
+ app.state.config.ENGINE = form_data.engine
107
+ app.state.config.ENABLED = form_data.enabled
108
+ return {
109
+ "engine": app.state.config.ENGINE,
110
+ "enabled": app.state.config.ENABLED,
111
+ }
112
+
113
+
114
+ class EngineUrlUpdateForm(BaseModel):
115
+ AUTOMATIC1111_BASE_URL: Optional[str] = None
116
+ COMFYUI_BASE_URL: Optional[str] = None
117
+
118
+
119
+ @app.get("/url")
120
+ async def get_engine_url(user=Depends(get_admin_user)):
121
+ return {
122
+ "AUTOMATIC1111_BASE_URL": app.state.config.AUTOMATIC1111_BASE_URL,
123
+ "COMFYUI_BASE_URL": app.state.config.COMFYUI_BASE_URL,
124
+ }
125
+
126
+
127
+ @app.post("/url/update")
128
+ async def update_engine_url(
129
+ form_data: EngineUrlUpdateForm, user=Depends(get_admin_user)
130
+ ):
131
+
132
+ if form_data.AUTOMATIC1111_BASE_URL == None:
133
+ app.state.config.AUTOMATIC1111_BASE_URL = AUTOMATIC1111_BASE_URL
134
+ else:
135
+ url = form_data.AUTOMATIC1111_BASE_URL.strip("/")
136
+ try:
137
+ r = requests.head(url)
138
+ app.state.config.AUTOMATIC1111_BASE_URL = url
139
+ except Exception as e:
140
+ raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e))
141
+
142
+ if form_data.COMFYUI_BASE_URL == None:
143
+ app.state.config.COMFYUI_BASE_URL = COMFYUI_BASE_URL
144
+ else:
145
+ url = form_data.COMFYUI_BASE_URL.strip("/")
146
+
147
+ try:
148
+ r = requests.head(url)
149
+ app.state.config.COMFYUI_BASE_URL = url
150
+ except Exception as e:
151
+ raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e))
152
+
153
+ return {
154
+ "AUTOMATIC1111_BASE_URL": app.state.config.AUTOMATIC1111_BASE_URL,
155
+ "COMFYUI_BASE_URL": app.state.config.COMFYUI_BASE_URL,
156
+ "status": True,
157
+ }
158
+
159
+
160
+ class OpenAIConfigUpdateForm(BaseModel):
161
+ url: str
162
+ key: str
163
+
164
+
165
+ @app.get("/openai/config")
166
+ async def get_openai_config(user=Depends(get_admin_user)):
167
+ return {
168
+ "OPENAI_API_BASE_URL": app.state.config.OPENAI_API_BASE_URL,
169
+ "OPENAI_API_KEY": app.state.config.OPENAI_API_KEY,
170
+ }
171
+
172
+
173
+ @app.post("/openai/config/update")
174
+ async def update_openai_config(
175
+ form_data: OpenAIConfigUpdateForm, user=Depends(get_admin_user)
176
+ ):
177
+ if form_data.key == "":
178
+ raise HTTPException(status_code=400, detail=ERROR_MESSAGES.API_KEY_NOT_FOUND)
179
+
180
+ app.state.config.OPENAI_API_BASE_URL = form_data.url
181
+ app.state.config.OPENAI_API_KEY = form_data.key
182
+
183
+ return {
184
+ "status": True,
185
+ "OPENAI_API_BASE_URL": app.state.config.OPENAI_API_BASE_URL,
186
+ "OPENAI_API_KEY": app.state.config.OPENAI_API_KEY,
187
+ }
188
+
189
+
190
+ class ImageSizeUpdateForm(BaseModel):
191
+ size: str
192
+
193
+
194
+ @app.get("/size")
195
+ async def get_image_size(user=Depends(get_admin_user)):
196
+ return {"IMAGE_SIZE": app.state.config.IMAGE_SIZE}
197
+
198
+
199
+ @app.post("/size/update")
200
+ async def update_image_size(
201
+ form_data: ImageSizeUpdateForm, user=Depends(get_admin_user)
202
+ ):
203
+ pattern = r"^\d+x\d+$" # Regular expression pattern
204
+ if re.match(pattern, form_data.size):
205
+ app.state.config.IMAGE_SIZE = form_data.size
206
+ return {
207
+ "IMAGE_SIZE": app.state.config.IMAGE_SIZE,
208
+ "status": True,
209
+ }
210
+ else:
211
+ raise HTTPException(
212
+ status_code=400,
213
+ detail=ERROR_MESSAGES.INCORRECT_FORMAT(" (e.g., 512x512)."),
214
+ )
215
+
216
+
217
+ class ImageStepsUpdateForm(BaseModel):
218
+ steps: int
219
+
220
+
221
+ @app.get("/steps")
222
+ async def get_image_size(user=Depends(get_admin_user)):
223
+ return {"IMAGE_STEPS": app.state.config.IMAGE_STEPS}
224
+
225
+
226
+ @app.post("/steps/update")
227
+ async def update_image_size(
228
+ form_data: ImageStepsUpdateForm, user=Depends(get_admin_user)
229
+ ):
230
+ if form_data.steps >= 0:
231
+ app.state.config.IMAGE_STEPS = form_data.steps
232
+ return {
233
+ "IMAGE_STEPS": app.state.config.IMAGE_STEPS,
234
+ "status": True,
235
+ }
236
+ else:
237
+ raise HTTPException(
238
+ status_code=400,
239
+ detail=ERROR_MESSAGES.INCORRECT_FORMAT(" (e.g., 50)."),
240
+ )
241
+
242
+
243
+ @app.get("/models")
244
+ def get_models(user=Depends(get_current_user)):
245
+ try:
246
+ if app.state.config.ENGINE == "openai":
247
+ return [
248
+ {"id": "dall-e-2", "name": "DALL·E 2"},
249
+ {"id": "dall-e-3", "name": "DALL·E 3"},
250
+ ]
251
+ elif app.state.config.ENGINE == "comfyui":
252
+
253
+ r = requests.get(url=f"{app.state.config.COMFYUI_BASE_URL}/object_info")
254
+ info = r.json()
255
+
256
+ return list(
257
+ map(
258
+ lambda model: {"id": model, "name": model},
259
+ info["CheckpointLoaderSimple"]["input"]["required"]["ckpt_name"][0],
260
+ )
261
+ )
262
+
263
+ else:
264
+ r = requests.get(
265
+ url=f"{app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/sd-models"
266
+ )
267
+ models = r.json()
268
+ return list(
269
+ map(
270
+ lambda model: {"id": model["title"], "name": model["model_name"]},
271
+ models,
272
+ )
273
+ )
274
+ except Exception as e:
275
+ app.state.config.ENABLED = False
276
+ raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e))
277
+
278
+
279
+ @app.get("/models/default")
280
+ async def get_default_model(user=Depends(get_admin_user)):
281
+ try:
282
+ if app.state.config.ENGINE == "openai":
283
+ return {
284
+ "model": (
285
+ app.state.config.MODEL if app.state.config.MODEL else "dall-e-2"
286
+ )
287
+ }
288
+ elif app.state.config.ENGINE == "comfyui":
289
+ return {"model": (app.state.config.MODEL if app.state.config.MODEL else "")}
290
+ else:
291
+ r = requests.get(
292
+ url=f"{app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options"
293
+ )
294
+ options = r.json()
295
+ return {"model": options["sd_model_checkpoint"]}
296
+ except Exception as e:
297
+ app.state.config.ENABLED = False
298
+ raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e))
299
+
300
+
301
+ class UpdateModelForm(BaseModel):
302
+ model: str
303
+
304
+
305
+ def set_model_handler(model: str):
306
+ if app.state.config.ENGINE in ["openai", "comfyui"]:
307
+ app.state.config.MODEL = model
308
+ return app.state.config.MODEL
309
+ else:
310
+ r = requests.get(
311
+ url=f"{app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options"
312
+ )
313
+ options = r.json()
314
+
315
+ if model != options["sd_model_checkpoint"]:
316
+ options["sd_model_checkpoint"] = model
317
+ r = requests.post(
318
+ url=f"{app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options",
319
+ json=options,
320
+ )
321
+
322
+ return options
323
+
324
+
325
+ @app.post("/models/default/update")
326
+ def update_default_model(
327
+ form_data: UpdateModelForm,
328
+ user=Depends(get_current_user),
329
+ ):
330
+ return set_model_handler(form_data.model)
331
+
332
+
333
+ class GenerateImageForm(BaseModel):
334
+ model: Optional[str] = None
335
+ prompt: str
336
+ n: int = 1
337
+ size: Optional[str] = None
338
+ negative_prompt: Optional[str] = None
339
+
340
+
341
+ def save_b64_image(b64_str):
342
+ try:
343
+ image_id = str(uuid.uuid4())
344
+
345
+ if "," in b64_str:
346
+ header, encoded = b64_str.split(",", 1)
347
+ mime_type = header.split(";")[0]
348
+
349
+ img_data = base64.b64decode(encoded)
350
+ image_format = mimetypes.guess_extension(mime_type)
351
+
352
+ image_filename = f"{image_id}{image_format}"
353
+ file_path = IMAGE_CACHE_DIR / f"{image_filename}"
354
+ with open(file_path, "wb") as f:
355
+ f.write(img_data)
356
+ return image_filename
357
+ else:
358
+ image_filename = f"{image_id}.png"
359
+ file_path = IMAGE_CACHE_DIR.joinpath(image_filename)
360
+
361
+ img_data = base64.b64decode(b64_str)
362
+
363
+ # Write the image data to a file
364
+ with open(file_path, "wb") as f:
365
+ f.write(img_data)
366
+ return image_filename
367
+
368
+ except Exception as e:
369
+ log.exception(f"Error saving image: {e}")
370
+ return None
371
+
372
+
373
+ def save_url_image(url):
374
+ image_id = str(uuid.uuid4())
375
+ try:
376
+ r = requests.get(url)
377
+ r.raise_for_status()
378
+ if r.headers["content-type"].split("/")[0] == "image":
379
+
380
+ mime_type = r.headers["content-type"]
381
+ image_format = mimetypes.guess_extension(mime_type)
382
+
383
+ if not image_format:
384
+ raise ValueError("Could not determine image type from MIME type")
385
+
386
+ image_filename = f"{image_id}{image_format}"
387
+
388
+ file_path = IMAGE_CACHE_DIR.joinpath(f"{image_filename}")
389
+ with open(file_path, "wb") as image_file:
390
+ for chunk in r.iter_content(chunk_size=8192):
391
+ image_file.write(chunk)
392
+ return image_filename
393
+ else:
394
+ log.error(f"Url does not point to an image.")
395
+ return None
396
+
397
+ except Exception as e:
398
+ log.exception(f"Error saving image: {e}")
399
+ return None
400
+
401
+
402
+ @app.post("/generations")
403
+ def generate_image(
404
+ form_data: GenerateImageForm,
405
+ user=Depends(get_current_user),
406
+ ):
407
+
408
+ width, height = tuple(map(int, app.state.config.IMAGE_SIZE.split("x")))
409
+
410
+ r = None
411
+ try:
412
+ if app.state.config.ENGINE == "openai":
413
+
414
+ headers = {}
415
+ headers["Authorization"] = f"Bearer {app.state.config.OPENAI_API_KEY}"
416
+ headers["Content-Type"] = "application/json"
417
+
418
+ data = {
419
+ "model": (
420
+ app.state.config.MODEL
421
+ if app.state.config.MODEL != ""
422
+ else "dall-e-2"
423
+ ),
424
+ "prompt": form_data.prompt,
425
+ "n": form_data.n,
426
+ "size": (
427
+ form_data.size if form_data.size else app.state.config.IMAGE_SIZE
428
+ ),
429
+ "response_format": "b64_json",
430
+ }
431
+
432
+ r = requests.post(
433
+ url=f"{app.state.config.OPENAI_API_BASE_URL}/images/generations",
434
+ json=data,
435
+ headers=headers,
436
+ )
437
+
438
+ r.raise_for_status()
439
+ res = r.json()
440
+
441
+ images = []
442
+
443
+ for image in res["data"]:
444
+ image_filename = save_b64_image(image["b64_json"])
445
+ images.append({"url": f"/cache/image/generations/{image_filename}"})
446
+ file_body_path = IMAGE_CACHE_DIR.joinpath(f"{image_filename}.json")
447
+
448
+ with open(file_body_path, "w") as f:
449
+ json.dump(data, f)
450
+
451
+ return images
452
+
453
+ elif app.state.config.ENGINE == "comfyui":
454
+
455
+ data = {
456
+ "prompt": form_data.prompt,
457
+ "width": width,
458
+ "height": height,
459
+ "n": form_data.n,
460
+ }
461
+
462
+ if app.state.config.IMAGE_STEPS is not None:
463
+ data["steps"] = app.state.config.IMAGE_STEPS
464
+
465
+ if form_data.negative_prompt is not None:
466
+ data["negative_prompt"] = form_data.negative_prompt
467
+
468
+ if app.state.config.COMFYUI_CFG_SCALE:
469
+ data["cfg_scale"] = app.state.config.COMFYUI_CFG_SCALE
470
+
471
+ if app.state.config.COMFYUI_SAMPLER is not None:
472
+ data["sampler"] = app.state.config.COMFYUI_SAMPLER
473
+
474
+ if app.state.config.COMFYUI_SCHEDULER is not None:
475
+ data["scheduler"] = app.state.config.COMFYUI_SCHEDULER
476
+
477
+ if app.state.config.COMFYUI_SD3 is not None:
478
+ data["sd3"] = app.state.config.COMFYUI_SD3
479
+
480
+ data = ImageGenerationPayload(**data)
481
+
482
+ res = comfyui_generate_image(
483
+ app.state.config.MODEL,
484
+ data,
485
+ user.id,
486
+ app.state.config.COMFYUI_BASE_URL,
487
+ )
488
+ log.debug(f"res: {res}")
489
+
490
+ images = []
491
+
492
+ for image in res["data"]:
493
+ image_filename = save_url_image(image["url"])
494
+ images.append({"url": f"/cache/image/generations/{image_filename}"})
495
+ file_body_path = IMAGE_CACHE_DIR.joinpath(f"{image_filename}.json")
496
+
497
+ with open(file_body_path, "w") as f:
498
+ json.dump(data.model_dump(exclude_none=True), f)
499
+
500
+ log.debug(f"images: {images}")
501
+ return images
502
+ else:
503
+ if form_data.model:
504
+ set_model_handler(form_data.model)
505
+
506
+ data = {
507
+ "prompt": form_data.prompt,
508
+ "batch_size": form_data.n,
509
+ "width": width,
510
+ "height": height,
511
+ }
512
+
513
+ if app.state.config.IMAGE_STEPS is not None:
514
+ data["steps"] = app.state.config.IMAGE_STEPS
515
+
516
+ if form_data.negative_prompt is not None:
517
+ data["negative_prompt"] = form_data.negative_prompt
518
+
519
+ r = requests.post(
520
+ url=f"{app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/txt2img",
521
+ json=data,
522
+ )
523
+
524
+ res = r.json()
525
+
526
+ log.debug(f"res: {res}")
527
+
528
+ images = []
529
+
530
+ for image in res["images"]:
531
+ image_filename = save_b64_image(image)
532
+ images.append({"url": f"/cache/image/generations/{image_filename}"})
533
+ file_body_path = IMAGE_CACHE_DIR.joinpath(f"{image_filename}.json")
534
+
535
+ with open(file_body_path, "w") as f:
536
+ json.dump({**data, "info": res["info"]}, f)
537
+
538
+ return images
539
+
540
+ except Exception as e:
541
+ error = e
542
+
543
+ if r != None:
544
+ data = r.json()
545
+ if "error" in data:
546
+ error = data["error"]["message"]
547
+ raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(error))
backend/apps/images/utils/comfyui.py ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import websocket # NOTE: websocket-client (https://github.com/websocket-client/websocket-client)
2
+ import uuid
3
+ import json
4
+ import urllib.request
5
+ import urllib.parse
6
+ import random
7
+ import logging
8
+
9
+ from config import SRC_LOG_LEVELS
10
+
11
+ log = logging.getLogger(__name__)
12
+ log.setLevel(SRC_LOG_LEVELS["COMFYUI"])
13
+
14
+ from pydantic import BaseModel
15
+
16
+ from typing import Optional
17
+
18
+ COMFYUI_DEFAULT_PROMPT = """
19
+ {
20
+ "3": {
21
+ "inputs": {
22
+ "seed": 0,
23
+ "steps": 20,
24
+ "cfg": 8,
25
+ "sampler_name": "euler",
26
+ "scheduler": "normal",
27
+ "denoise": 1,
28
+ "model": [
29
+ "4",
30
+ 0
31
+ ],
32
+ "positive": [
33
+ "6",
34
+ 0
35
+ ],
36
+ "negative": [
37
+ "7",
38
+ 0
39
+ ],
40
+ "latent_image": [
41
+ "5",
42
+ 0
43
+ ]
44
+ },
45
+ "class_type": "KSampler",
46
+ "_meta": {
47
+ "title": "KSampler"
48
+ }
49
+ },
50
+ "4": {
51
+ "inputs": {
52
+ "ckpt_name": "model.safetensors"
53
+ },
54
+ "class_type": "CheckpointLoaderSimple",
55
+ "_meta": {
56
+ "title": "Load Checkpoint"
57
+ }
58
+ },
59
+ "5": {
60
+ "inputs": {
61
+ "width": 512,
62
+ "height": 512,
63
+ "batch_size": 1
64
+ },
65
+ "class_type": "EmptyLatentImage",
66
+ "_meta": {
67
+ "title": "Empty Latent Image"
68
+ }
69
+ },
70
+ "6": {
71
+ "inputs": {
72
+ "text": "Prompt",
73
+ "clip": [
74
+ "4",
75
+ 1
76
+ ]
77
+ },
78
+ "class_type": "CLIPTextEncode",
79
+ "_meta": {
80
+ "title": "CLIP Text Encode (Prompt)"
81
+ }
82
+ },
83
+ "7": {
84
+ "inputs": {
85
+ "text": "Negative Prompt",
86
+ "clip": [
87
+ "4",
88
+ 1
89
+ ]
90
+ },
91
+ "class_type": "CLIPTextEncode",
92
+ "_meta": {
93
+ "title": "CLIP Text Encode (Prompt)"
94
+ }
95
+ },
96
+ "8": {
97
+ "inputs": {
98
+ "samples": [
99
+ "3",
100
+ 0
101
+ ],
102
+ "vae": [
103
+ "4",
104
+ 2
105
+ ]
106
+ },
107
+ "class_type": "VAEDecode",
108
+ "_meta": {
109
+ "title": "VAE Decode"
110
+ }
111
+ },
112
+ "9": {
113
+ "inputs": {
114
+ "filename_prefix": "ComfyUI",
115
+ "images": [
116
+ "8",
117
+ 0
118
+ ]
119
+ },
120
+ "class_type": "SaveImage",
121
+ "_meta": {
122
+ "title": "Save Image"
123
+ }
124
+ }
125
+ }
126
+ """
127
+
128
+
129
+ def queue_prompt(prompt, client_id, base_url):
130
+ log.info("queue_prompt")
131
+ p = {"prompt": prompt, "client_id": client_id}
132
+ data = json.dumps(p).encode("utf-8")
133
+ req = urllib.request.Request(f"{base_url}/prompt", data=data)
134
+ return json.loads(urllib.request.urlopen(req).read())
135
+
136
+
137
+ def get_image(filename, subfolder, folder_type, base_url):
138
+ log.info("get_image")
139
+ data = {"filename": filename, "subfolder": subfolder, "type": folder_type}
140
+ url_values = urllib.parse.urlencode(data)
141
+ with urllib.request.urlopen(f"{base_url}/view?{url_values}") as response:
142
+ return response.read()
143
+
144
+
145
+ def get_image_url(filename, subfolder, folder_type, base_url):
146
+ log.info("get_image")
147
+ data = {"filename": filename, "subfolder": subfolder, "type": folder_type}
148
+ url_values = urllib.parse.urlencode(data)
149
+ return f"{base_url}/view?{url_values}"
150
+
151
+
152
+ def get_history(prompt_id, base_url):
153
+ log.info("get_history")
154
+ with urllib.request.urlopen(f"{base_url}/history/{prompt_id}") as response:
155
+ return json.loads(response.read())
156
+
157
+
158
+ def get_images(ws, prompt, client_id, base_url):
159
+ prompt_id = queue_prompt(prompt, client_id, base_url)["prompt_id"]
160
+ output_images = []
161
+ while True:
162
+ out = ws.recv()
163
+ if isinstance(out, str):
164
+ message = json.loads(out)
165
+ if message["type"] == "executing":
166
+ data = message["data"]
167
+ if data["node"] is None and data["prompt_id"] == prompt_id:
168
+ break # Execution is done
169
+ else:
170
+ continue # previews are binary data
171
+
172
+ history = get_history(prompt_id, base_url)[prompt_id]
173
+ for o in history["outputs"]:
174
+ for node_id in history["outputs"]:
175
+ node_output = history["outputs"][node_id]
176
+ if "images" in node_output:
177
+ for image in node_output["images"]:
178
+ url = get_image_url(
179
+ image["filename"], image["subfolder"], image["type"], base_url
180
+ )
181
+ output_images.append({"url": url})
182
+ return {"data": output_images}
183
+
184
+
185
+ class ImageGenerationPayload(BaseModel):
186
+ prompt: str
187
+ negative_prompt: Optional[str] = ""
188
+ steps: Optional[int] = None
189
+ seed: Optional[int] = None
190
+ width: int
191
+ height: int
192
+ n: int = 1
193
+ cfg_scale: Optional[float] = None
194
+ sampler: Optional[str] = None
195
+ scheduler: Optional[str] = None
196
+ sd3: Optional[bool] = None
197
+
198
+
199
+ def comfyui_generate_image(
200
+ model: str, payload: ImageGenerationPayload, client_id, base_url
201
+ ):
202
+ ws_url = base_url.replace("http://", "ws://").replace("https://", "wss://")
203
+
204
+ comfyui_prompt = json.loads(COMFYUI_DEFAULT_PROMPT)
205
+
206
+ if payload.cfg_scale:
207
+ comfyui_prompt["3"]["inputs"]["cfg"] = payload.cfg_scale
208
+
209
+ if payload.sampler:
210
+ comfyui_prompt["3"]["inputs"]["sampler"] = payload.sampler
211
+
212
+ if payload.scheduler:
213
+ comfyui_prompt["3"]["inputs"]["scheduler"] = payload.scheduler
214
+
215
+ if payload.sd3:
216
+ comfyui_prompt["5"]["class_type"] = "EmptySD3LatentImage"
217
+
218
+ comfyui_prompt["4"]["inputs"]["ckpt_name"] = model
219
+ comfyui_prompt["5"]["inputs"]["batch_size"] = payload.n
220
+ comfyui_prompt["5"]["inputs"]["width"] = payload.width
221
+ comfyui_prompt["5"]["inputs"]["height"] = payload.height
222
+
223
+ # set the text prompt for our positive CLIPTextEncode
224
+ comfyui_prompt["6"]["inputs"]["text"] = payload.prompt
225
+ comfyui_prompt["7"]["inputs"]["text"] = payload.negative_prompt
226
+
227
+ if payload.steps:
228
+ comfyui_prompt["3"]["inputs"]["steps"] = payload.steps
229
+
230
+ comfyui_prompt["3"]["inputs"]["seed"] = (
231
+ payload.seed if payload.seed else random.randint(0, 18446744073709551614)
232
+ )
233
+
234
+ try:
235
+ ws = websocket.WebSocket()
236
+ ws.connect(f"{ws_url}/ws?clientId={client_id}")
237
+ log.info("WebSocket connection established.")
238
+ except Exception as e:
239
+ log.exception(f"Failed to connect to WebSocket server: {e}")
240
+ return None
241
+
242
+ try:
243
+ images = get_images(ws, comfyui_prompt, client_id, base_url)
244
+ except Exception as e:
245
+ log.exception(f"Error while receiving images: {e}")
246
+ images = None
247
+
248
+ ws.close()
249
+
250
+ return images
backend/apps/ollama/main.py ADDED
@@ -0,0 +1,1214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import (
2
+ FastAPI,
3
+ Request,
4
+ Response,
5
+ HTTPException,
6
+ Depends,
7
+ status,
8
+ UploadFile,
9
+ File,
10
+ BackgroundTasks,
11
+ )
12
+ from fastapi.middleware.cors import CORSMiddleware
13
+ from fastapi.responses import StreamingResponse
14
+ from fastapi.concurrency import run_in_threadpool
15
+
16
+ from pydantic import BaseModel, ConfigDict
17
+
18
+ import os
19
+ import re
20
+ import copy
21
+ import random
22
+ import requests
23
+ import json
24
+ import uuid
25
+ import aiohttp
26
+ import asyncio
27
+ import logging
28
+ import time
29
+ from urllib.parse import urlparse
30
+ from typing import Optional, List, Union
31
+
32
+ from starlette.background import BackgroundTask
33
+
34
+ from apps.webui.models.models import Models
35
+ from apps.webui.models.users import Users
36
+ from constants import ERROR_MESSAGES
37
+ from utils.utils import (
38
+ decode_token,
39
+ get_current_user,
40
+ get_verified_user,
41
+ get_admin_user,
42
+ )
43
+ from utils.task import prompt_template
44
+
45
+
46
+ from config import (
47
+ SRC_LOG_LEVELS,
48
+ OLLAMA_BASE_URLS,
49
+ ENABLE_OLLAMA_API,
50
+ AIOHTTP_CLIENT_TIMEOUT,
51
+ ENABLE_MODEL_FILTER,
52
+ MODEL_FILTER_LIST,
53
+ UPLOAD_DIR,
54
+ AppConfig,
55
+ )
56
+ from utils.misc import calculate_sha256, add_or_update_system_message
57
+
58
+ log = logging.getLogger(__name__)
59
+ log.setLevel(SRC_LOG_LEVELS["OLLAMA"])
60
+
61
+ app = FastAPI()
62
+ app.add_middleware(
63
+ CORSMiddleware,
64
+ allow_origins=["*"],
65
+ allow_credentials=True,
66
+ allow_methods=["*"],
67
+ allow_headers=["*"],
68
+ )
69
+
70
+ app.state.config = AppConfig()
71
+
72
+ app.state.config.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER
73
+ app.state.config.MODEL_FILTER_LIST = MODEL_FILTER_LIST
74
+
75
+ app.state.config.ENABLE_OLLAMA_API = ENABLE_OLLAMA_API
76
+ app.state.config.OLLAMA_BASE_URLS = OLLAMA_BASE_URLS
77
+ app.state.MODELS = {}
78
+
79
+
80
+ # TODO: Implement a more intelligent load balancing mechanism for distributing requests among multiple backend instances.
81
+ # Current implementation uses a simple round-robin approach (random.choice). Consider incorporating algorithms like weighted round-robin,
82
+ # least connections, or least response time for better resource utilization and performance optimization.
83
+
84
+
85
+ @app.middleware("http")
86
+ async def check_url(request: Request, call_next):
87
+ if len(app.state.MODELS) == 0:
88
+ await get_all_models()
89
+ else:
90
+ pass
91
+
92
+ response = await call_next(request)
93
+ return response
94
+
95
+
96
+ @app.head("/")
97
+ @app.get("/")
98
+ async def get_status():
99
+ return {"status": True}
100
+
101
+
102
+ @app.get("/config")
103
+ async def get_config(user=Depends(get_admin_user)):
104
+ return {"ENABLE_OLLAMA_API": app.state.config.ENABLE_OLLAMA_API}
105
+
106
+
107
+ class OllamaConfigForm(BaseModel):
108
+ enable_ollama_api: Optional[bool] = None
109
+
110
+
111
+ @app.post("/config/update")
112
+ async def update_config(form_data: OllamaConfigForm, user=Depends(get_admin_user)):
113
+ app.state.config.ENABLE_OLLAMA_API = form_data.enable_ollama_api
114
+ return {"ENABLE_OLLAMA_API": app.state.config.ENABLE_OLLAMA_API}
115
+
116
+
117
+ @app.get("/urls")
118
+ async def get_ollama_api_urls(user=Depends(get_admin_user)):
119
+ return {"OLLAMA_BASE_URLS": app.state.config.OLLAMA_BASE_URLS}
120
+
121
+
122
+ class UrlUpdateForm(BaseModel):
123
+ urls: List[str]
124
+
125
+
126
+ @app.post("/urls/update")
127
+ async def update_ollama_api_url(form_data: UrlUpdateForm, user=Depends(get_admin_user)):
128
+ app.state.config.OLLAMA_BASE_URLS = form_data.urls
129
+
130
+ log.info(f"app.state.config.OLLAMA_BASE_URLS: {app.state.config.OLLAMA_BASE_URLS}")
131
+ return {"OLLAMA_BASE_URLS": app.state.config.OLLAMA_BASE_URLS}
132
+
133
+
134
+ async def fetch_url(url):
135
+ timeout = aiohttp.ClientTimeout(total=5)
136
+ try:
137
+ async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session:
138
+ async with session.get(url) as response:
139
+ return await response.json()
140
+ except Exception as e:
141
+ # Handle connection error here
142
+ log.error(f"Connection error: {e}")
143
+ return None
144
+
145
+
146
+ async def cleanup_response(
147
+ response: Optional[aiohttp.ClientResponse],
148
+ session: Optional[aiohttp.ClientSession],
149
+ ):
150
+ if response:
151
+ response.close()
152
+ if session:
153
+ await session.close()
154
+
155
+
156
+ async def post_streaming_url(url: str, payload: str):
157
+ r = None
158
+ try:
159
+ session = aiohttp.ClientSession(
160
+ trust_env=True, timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT)
161
+ )
162
+ r = await session.post(url, data=payload)
163
+ r.raise_for_status()
164
+
165
+ return StreamingResponse(
166
+ r.content,
167
+ status_code=r.status,
168
+ headers=dict(r.headers),
169
+ background=BackgroundTask(cleanup_response, response=r, session=session),
170
+ )
171
+ except Exception as e:
172
+ error_detail = "Open WebUI: Server Connection Error"
173
+ if r is not None:
174
+ try:
175
+ res = await r.json()
176
+ if "error" in res:
177
+ error_detail = f"Ollama: {res['error']}"
178
+ except:
179
+ error_detail = f"Ollama: {e}"
180
+
181
+ raise HTTPException(
182
+ status_code=r.status if r else 500,
183
+ detail=error_detail,
184
+ )
185
+
186
+
187
+ def merge_models_lists(model_lists):
188
+ merged_models = {}
189
+
190
+ for idx, model_list in enumerate(model_lists):
191
+ if model_list is not None:
192
+ for model in model_list:
193
+ digest = model["digest"]
194
+ if digest not in merged_models:
195
+ model["urls"] = [idx]
196
+ merged_models[digest] = model
197
+ else:
198
+ merged_models[digest]["urls"].append(idx)
199
+
200
+ return list(merged_models.values())
201
+
202
+
203
+ async def get_all_models():
204
+ log.info("get_all_models()")
205
+
206
+ if app.state.config.ENABLE_OLLAMA_API:
207
+ tasks = [
208
+ fetch_url(f"{url}/api/tags") for url in app.state.config.OLLAMA_BASE_URLS
209
+ ]
210
+ responses = await asyncio.gather(*tasks)
211
+
212
+ models = {
213
+ "models": merge_models_lists(
214
+ map(
215
+ lambda response: response["models"] if response else None, responses
216
+ )
217
+ )
218
+ }
219
+
220
+ else:
221
+ models = {"models": []}
222
+
223
+ app.state.MODELS = {model["model"]: model for model in models["models"]}
224
+
225
+ return models
226
+
227
+
228
+ @app.get("/api/tags")
229
+ @app.get("/api/tags/{url_idx}")
230
+ async def get_ollama_tags(
231
+ url_idx: Optional[int] = None, user=Depends(get_verified_user)
232
+ ):
233
+ if url_idx == None:
234
+ models = await get_all_models()
235
+
236
+ if app.state.config.ENABLE_MODEL_FILTER:
237
+ if user.role == "user":
238
+ models["models"] = list(
239
+ filter(
240
+ lambda model: model["name"]
241
+ in app.state.config.MODEL_FILTER_LIST,
242
+ models["models"],
243
+ )
244
+ )
245
+ return models
246
+ return models
247
+ else:
248
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
249
+
250
+ r = None
251
+ try:
252
+ r = requests.request(method="GET", url=f"{url}/api/tags")
253
+ r.raise_for_status()
254
+
255
+ return r.json()
256
+ except Exception as e:
257
+ log.exception(e)
258
+ error_detail = "Open WebUI: Server Connection Error"
259
+ if r is not None:
260
+ try:
261
+ res = r.json()
262
+ if "error" in res:
263
+ error_detail = f"Ollama: {res['error']}"
264
+ except:
265
+ error_detail = f"Ollama: {e}"
266
+
267
+ raise HTTPException(
268
+ status_code=r.status_code if r else 500,
269
+ detail=error_detail,
270
+ )
271
+
272
+
273
+ @app.get("/api/version")
274
+ @app.get("/api/version/{url_idx}")
275
+ async def get_ollama_versions(url_idx: Optional[int] = None):
276
+ if app.state.config.ENABLE_OLLAMA_API:
277
+ if url_idx == None:
278
+
279
+ # returns lowest version
280
+ tasks = [
281
+ fetch_url(f"{url}/api/version")
282
+ for url in app.state.config.OLLAMA_BASE_URLS
283
+ ]
284
+ responses = await asyncio.gather(*tasks)
285
+ responses = list(filter(lambda x: x is not None, responses))
286
+
287
+ if len(responses) > 0:
288
+ lowest_version = min(
289
+ responses,
290
+ key=lambda x: tuple(
291
+ map(int, re.sub(r"^v|-.*", "", x["version"]).split("."))
292
+ ),
293
+ )
294
+
295
+ return {"version": lowest_version["version"]}
296
+ else:
297
+ raise HTTPException(
298
+ status_code=500,
299
+ detail=ERROR_MESSAGES.OLLAMA_NOT_FOUND,
300
+ )
301
+ else:
302
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
303
+
304
+ r = None
305
+ try:
306
+ r = requests.request(method="GET", url=f"{url}/api/version")
307
+ r.raise_for_status()
308
+
309
+ return r.json()
310
+ except Exception as e:
311
+ log.exception(e)
312
+ error_detail = "Open WebUI: Server Connection Error"
313
+ if r is not None:
314
+ try:
315
+ res = r.json()
316
+ if "error" in res:
317
+ error_detail = f"Ollama: {res['error']}"
318
+ except:
319
+ error_detail = f"Ollama: {e}"
320
+
321
+ raise HTTPException(
322
+ status_code=r.status_code if r else 500,
323
+ detail=error_detail,
324
+ )
325
+ else:
326
+ return {"version": False}
327
+
328
+
329
+ class ModelNameForm(BaseModel):
330
+ name: str
331
+
332
+
333
+ @app.post("/api/pull")
334
+ @app.post("/api/pull/{url_idx}")
335
+ async def pull_model(
336
+ form_data: ModelNameForm, url_idx: int = 0, user=Depends(get_admin_user)
337
+ ):
338
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
339
+ log.info(f"url: {url}")
340
+
341
+ r = None
342
+
343
+ # Admin should be able to pull models from any source
344
+ payload = {**form_data.model_dump(exclude_none=True), "insecure": True}
345
+
346
+ return await post_streaming_url(f"{url}/api/pull", json.dumps(payload))
347
+
348
+
349
+ class PushModelForm(BaseModel):
350
+ name: str
351
+ insecure: Optional[bool] = None
352
+ stream: Optional[bool] = None
353
+
354
+
355
+ @app.delete("/api/push")
356
+ @app.delete("/api/push/{url_idx}")
357
+ async def push_model(
358
+ form_data: PushModelForm,
359
+ url_idx: Optional[int] = None,
360
+ user=Depends(get_admin_user),
361
+ ):
362
+ if url_idx == None:
363
+ if form_data.name in app.state.MODELS:
364
+ url_idx = app.state.MODELS[form_data.name]["urls"][0]
365
+ else:
366
+ raise HTTPException(
367
+ status_code=400,
368
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.name),
369
+ )
370
+
371
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
372
+ log.debug(f"url: {url}")
373
+
374
+ return await post_streaming_url(
375
+ f"{url}/api/push", form_data.model_dump_json(exclude_none=True).encode()
376
+ )
377
+
378
+
379
+ class CreateModelForm(BaseModel):
380
+ name: str
381
+ modelfile: Optional[str] = None
382
+ stream: Optional[bool] = None
383
+ path: Optional[str] = None
384
+
385
+
386
+ @app.post("/api/create")
387
+ @app.post("/api/create/{url_idx}")
388
+ async def create_model(
389
+ form_data: CreateModelForm, url_idx: int = 0, user=Depends(get_admin_user)
390
+ ):
391
+ log.debug(f"form_data: {form_data}")
392
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
393
+ log.info(f"url: {url}")
394
+
395
+ return await post_streaming_url(
396
+ f"{url}/api/create", form_data.model_dump_json(exclude_none=True).encode()
397
+ )
398
+
399
+
400
+ class CopyModelForm(BaseModel):
401
+ source: str
402
+ destination: str
403
+
404
+
405
+ @app.post("/api/copy")
406
+ @app.post("/api/copy/{url_idx}")
407
+ async def copy_model(
408
+ form_data: CopyModelForm,
409
+ url_idx: Optional[int] = None,
410
+ user=Depends(get_admin_user),
411
+ ):
412
+ if url_idx == None:
413
+ if form_data.source in app.state.MODELS:
414
+ url_idx = app.state.MODELS[form_data.source]["urls"][0]
415
+ else:
416
+ raise HTTPException(
417
+ status_code=400,
418
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.source),
419
+ )
420
+
421
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
422
+ log.info(f"url: {url}")
423
+
424
+ try:
425
+ r = requests.request(
426
+ method="POST",
427
+ url=f"{url}/api/copy",
428
+ data=form_data.model_dump_json(exclude_none=True).encode(),
429
+ )
430
+ r.raise_for_status()
431
+
432
+ log.debug(f"r.text: {r.text}")
433
+
434
+ return True
435
+ except Exception as e:
436
+ log.exception(e)
437
+ error_detail = "Open WebUI: Server Connection Error"
438
+ if r is not None:
439
+ try:
440
+ res = r.json()
441
+ if "error" in res:
442
+ error_detail = f"Ollama: {res['error']}"
443
+ except:
444
+ error_detail = f"Ollama: {e}"
445
+
446
+ raise HTTPException(
447
+ status_code=r.status_code if r else 500,
448
+ detail=error_detail,
449
+ )
450
+
451
+
452
+ @app.delete("/api/delete")
453
+ @app.delete("/api/delete/{url_idx}")
454
+ async def delete_model(
455
+ form_data: ModelNameForm,
456
+ url_idx: Optional[int] = None,
457
+ user=Depends(get_admin_user),
458
+ ):
459
+ if url_idx == None:
460
+ if form_data.name in app.state.MODELS:
461
+ url_idx = app.state.MODELS[form_data.name]["urls"][0]
462
+ else:
463
+ raise HTTPException(
464
+ status_code=400,
465
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.name),
466
+ )
467
+
468
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
469
+ log.info(f"url: {url}")
470
+
471
+ try:
472
+ r = requests.request(
473
+ method="DELETE",
474
+ url=f"{url}/api/delete",
475
+ data=form_data.model_dump_json(exclude_none=True).encode(),
476
+ )
477
+ r.raise_for_status()
478
+
479
+ log.debug(f"r.text: {r.text}")
480
+
481
+ return True
482
+ except Exception as e:
483
+ log.exception(e)
484
+ error_detail = "Open WebUI: Server Connection Error"
485
+ if r is not None:
486
+ try:
487
+ res = r.json()
488
+ if "error" in res:
489
+ error_detail = f"Ollama: {res['error']}"
490
+ except:
491
+ error_detail = f"Ollama: {e}"
492
+
493
+ raise HTTPException(
494
+ status_code=r.status_code if r else 500,
495
+ detail=error_detail,
496
+ )
497
+
498
+
499
+ @app.post("/api/show")
500
+ async def show_model_info(form_data: ModelNameForm, user=Depends(get_verified_user)):
501
+ if form_data.name not in app.state.MODELS:
502
+ raise HTTPException(
503
+ status_code=400,
504
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.name),
505
+ )
506
+
507
+ url_idx = random.choice(app.state.MODELS[form_data.name]["urls"])
508
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
509
+ log.info(f"url: {url}")
510
+
511
+ try:
512
+ r = requests.request(
513
+ method="POST",
514
+ url=f"{url}/api/show",
515
+ data=form_data.model_dump_json(exclude_none=True).encode(),
516
+ )
517
+ r.raise_for_status()
518
+
519
+ return r.json()
520
+ except Exception as e:
521
+ log.exception(e)
522
+ error_detail = "Open WebUI: Server Connection Error"
523
+ if r is not None:
524
+ try:
525
+ res = r.json()
526
+ if "error" in res:
527
+ error_detail = f"Ollama: {res['error']}"
528
+ except:
529
+ error_detail = f"Ollama: {e}"
530
+
531
+ raise HTTPException(
532
+ status_code=r.status_code if r else 500,
533
+ detail=error_detail,
534
+ )
535
+
536
+
537
+ class GenerateEmbeddingsForm(BaseModel):
538
+ model: str
539
+ prompt: str
540
+ options: Optional[dict] = None
541
+ keep_alive: Optional[Union[int, str]] = None
542
+
543
+
544
+ @app.post("/api/embeddings")
545
+ @app.post("/api/embeddings/{url_idx}")
546
+ async def generate_embeddings(
547
+ form_data: GenerateEmbeddingsForm,
548
+ url_idx: Optional[int] = None,
549
+ user=Depends(get_verified_user),
550
+ ):
551
+ if url_idx == None:
552
+ model = form_data.model
553
+
554
+ if ":" not in model:
555
+ model = f"{model}:latest"
556
+
557
+ if model in app.state.MODELS:
558
+ url_idx = random.choice(app.state.MODELS[model]["urls"])
559
+ else:
560
+ raise HTTPException(
561
+ status_code=400,
562
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.model),
563
+ )
564
+
565
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
566
+ log.info(f"url: {url}")
567
+
568
+ try:
569
+ r = requests.request(
570
+ method="POST",
571
+ url=f"{url}/api/embeddings",
572
+ data=form_data.model_dump_json(exclude_none=True).encode(),
573
+ )
574
+ r.raise_for_status()
575
+
576
+ return r.json()
577
+ except Exception as e:
578
+ log.exception(e)
579
+ error_detail = "Open WebUI: Server Connection Error"
580
+ if r is not None:
581
+ try:
582
+ res = r.json()
583
+ if "error" in res:
584
+ error_detail = f"Ollama: {res['error']}"
585
+ except:
586
+ error_detail = f"Ollama: {e}"
587
+
588
+ raise HTTPException(
589
+ status_code=r.status_code if r else 500,
590
+ detail=error_detail,
591
+ )
592
+
593
+
594
+ def generate_ollama_embeddings(
595
+ form_data: GenerateEmbeddingsForm,
596
+ url_idx: Optional[int] = None,
597
+ ):
598
+
599
+ log.info(f"generate_ollama_embeddings {form_data}")
600
+
601
+ if url_idx == None:
602
+ model = form_data.model
603
+
604
+ if ":" not in model:
605
+ model = f"{model}:latest"
606
+
607
+ if model in app.state.MODELS:
608
+ url_idx = random.choice(app.state.MODELS[model]["urls"])
609
+ else:
610
+ raise HTTPException(
611
+ status_code=400,
612
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.model),
613
+ )
614
+
615
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
616
+ log.info(f"url: {url}")
617
+
618
+ try:
619
+ r = requests.request(
620
+ method="POST",
621
+ url=f"{url}/api/embeddings",
622
+ data=form_data.model_dump_json(exclude_none=True).encode(),
623
+ )
624
+ r.raise_for_status()
625
+
626
+ data = r.json()
627
+
628
+ log.info(f"generate_ollama_embeddings {data}")
629
+
630
+ if "embedding" in data:
631
+ return data["embedding"]
632
+ else:
633
+ raise "Something went wrong :/"
634
+ except Exception as e:
635
+ log.exception(e)
636
+ error_detail = "Open WebUI: Server Connection Error"
637
+ if r is not None:
638
+ try:
639
+ res = r.json()
640
+ if "error" in res:
641
+ error_detail = f"Ollama: {res['error']}"
642
+ except:
643
+ error_detail = f"Ollama: {e}"
644
+
645
+ raise error_detail
646
+
647
+
648
+ class GenerateCompletionForm(BaseModel):
649
+ model: str
650
+ prompt: str
651
+ images: Optional[List[str]] = None
652
+ format: Optional[str] = None
653
+ options: Optional[dict] = None
654
+ system: Optional[str] = None
655
+ template: Optional[str] = None
656
+ context: Optional[str] = None
657
+ stream: Optional[bool] = True
658
+ raw: Optional[bool] = None
659
+ keep_alive: Optional[Union[int, str]] = None
660
+
661
+
662
+ @app.post("/api/generate")
663
+ @app.post("/api/generate/{url_idx}")
664
+ async def generate_completion(
665
+ form_data: GenerateCompletionForm,
666
+ url_idx: Optional[int] = None,
667
+ user=Depends(get_verified_user),
668
+ ):
669
+
670
+ if url_idx == None:
671
+ model = form_data.model
672
+
673
+ if ":" not in model:
674
+ model = f"{model}:latest"
675
+
676
+ if model in app.state.MODELS:
677
+ url_idx = random.choice(app.state.MODELS[model]["urls"])
678
+ else:
679
+ raise HTTPException(
680
+ status_code=400,
681
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.model),
682
+ )
683
+
684
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
685
+ log.info(f"url: {url}")
686
+
687
+ return await post_streaming_url(
688
+ f"{url}/api/generate", form_data.model_dump_json(exclude_none=True).encode()
689
+ )
690
+
691
+
692
+ class ChatMessage(BaseModel):
693
+ role: str
694
+ content: str
695
+ images: Optional[List[str]] = None
696
+
697
+
698
+ class GenerateChatCompletionForm(BaseModel):
699
+ model: str
700
+ messages: List[ChatMessage]
701
+ format: Optional[str] = None
702
+ options: Optional[dict] = None
703
+ template: Optional[str] = None
704
+ stream: Optional[bool] = None
705
+ keep_alive: Optional[Union[int, str]] = None
706
+
707
+
708
+ @app.post("/api/chat")
709
+ @app.post("/api/chat/{url_idx}")
710
+ async def generate_chat_completion(
711
+ form_data: GenerateChatCompletionForm,
712
+ url_idx: Optional[int] = None,
713
+ user=Depends(get_verified_user),
714
+ ):
715
+
716
+ log.debug(
717
+ "form_data.model_dump_json(exclude_none=True).encode(): {0} ".format(
718
+ form_data.model_dump_json(exclude_none=True).encode()
719
+ )
720
+ )
721
+
722
+ payload = {
723
+ **form_data.model_dump(exclude_none=True),
724
+ }
725
+
726
+ model_id = form_data.model
727
+ model_info = Models.get_model_by_id(model_id)
728
+
729
+ if model_info:
730
+ if model_info.base_model_id:
731
+ payload["model"] = model_info.base_model_id
732
+
733
+ model_info.params = model_info.params.model_dump()
734
+
735
+ if model_info.params:
736
+ payload["options"] = {}
737
+
738
+ if model_info.params.get("mirostat", None):
739
+ payload["options"]["mirostat"] = model_info.params.get("mirostat", None)
740
+
741
+ if model_info.params.get("mirostat_eta", None):
742
+ payload["options"]["mirostat_eta"] = model_info.params.get(
743
+ "mirostat_eta", None
744
+ )
745
+
746
+ if model_info.params.get("mirostat_tau", None):
747
+
748
+ payload["options"]["mirostat_tau"] = model_info.params.get(
749
+ "mirostat_tau", None
750
+ )
751
+
752
+ if model_info.params.get("num_ctx", None):
753
+ payload["options"]["num_ctx"] = model_info.params.get("num_ctx", None)
754
+
755
+ if model_info.params.get("num_batch", None):
756
+ payload["options"]["num_batch"] = model_info.params.get(
757
+ "num_batch", None
758
+ )
759
+
760
+ if model_info.params.get("num_keep", None):
761
+ payload["options"]["num_keep"] = model_info.params.get("num_keep", None)
762
+
763
+ if model_info.params.get("repeat_last_n", None):
764
+ payload["options"]["repeat_last_n"] = model_info.params.get(
765
+ "repeat_last_n", None
766
+ )
767
+
768
+ if model_info.params.get("frequency_penalty", None):
769
+ payload["options"]["repeat_penalty"] = model_info.params.get(
770
+ "frequency_penalty", None
771
+ )
772
+
773
+ if model_info.params.get("temperature", None) is not None:
774
+ payload["options"]["temperature"] = model_info.params.get(
775
+ "temperature", None
776
+ )
777
+
778
+ if model_info.params.get("seed", None):
779
+ payload["options"]["seed"] = model_info.params.get("seed", None)
780
+
781
+ if model_info.params.get("stop", None):
782
+ payload["options"]["stop"] = (
783
+ [
784
+ bytes(stop, "utf-8").decode("unicode_escape")
785
+ for stop in model_info.params["stop"]
786
+ ]
787
+ if model_info.params.get("stop", None)
788
+ else None
789
+ )
790
+
791
+ if model_info.params.get("tfs_z", None):
792
+ payload["options"]["tfs_z"] = model_info.params.get("tfs_z", None)
793
+
794
+ if model_info.params.get("max_tokens", None):
795
+ payload["options"]["num_predict"] = model_info.params.get(
796
+ "max_tokens", None
797
+ )
798
+
799
+ if model_info.params.get("top_k", None):
800
+ payload["options"]["top_k"] = model_info.params.get("top_k", None)
801
+
802
+ if model_info.params.get("top_p", None):
803
+ payload["options"]["top_p"] = model_info.params.get("top_p", None)
804
+
805
+ if model_info.params.get("use_mmap", None):
806
+ payload["options"]["use_mmap"] = model_info.params.get("use_mmap", None)
807
+
808
+ if model_info.params.get("use_mlock", None):
809
+ payload["options"]["use_mlock"] = model_info.params.get(
810
+ "use_mlock", None
811
+ )
812
+
813
+ if model_info.params.get("num_thread", None):
814
+ payload["options"]["num_thread"] = model_info.params.get(
815
+ "num_thread", None
816
+ )
817
+
818
+ system = model_info.params.get("system", None)
819
+ if system:
820
+ # Check if the payload already has a system message
821
+ # If not, add a system message to the payload
822
+ system = prompt_template(
823
+ system,
824
+ **(
825
+ {
826
+ "user_name": user.name,
827
+ "user_location": (
828
+ user.info.get("location") if user.info else None
829
+ ),
830
+ }
831
+ if user
832
+ else {}
833
+ ),
834
+ )
835
+
836
+ if payload.get("messages"):
837
+ payload["messages"] = add_or_update_system_message(
838
+ system, payload["messages"]
839
+ )
840
+
841
+ if url_idx == None:
842
+ if ":" not in payload["model"]:
843
+ payload["model"] = f"{payload['model']}:latest"
844
+
845
+ if payload["model"] in app.state.MODELS:
846
+ url_idx = random.choice(app.state.MODELS[payload["model"]]["urls"])
847
+ else:
848
+ raise HTTPException(
849
+ status_code=400,
850
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.model),
851
+ )
852
+
853
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
854
+ log.info(f"url: {url}")
855
+ log.debug(payload)
856
+
857
+ return await post_streaming_url(f"{url}/api/chat", json.dumps(payload))
858
+
859
+
860
+ # TODO: we should update this part once Ollama supports other types
861
+ class OpenAIChatMessageContent(BaseModel):
862
+ type: str
863
+ model_config = ConfigDict(extra="allow")
864
+
865
+
866
+ class OpenAIChatMessage(BaseModel):
867
+ role: str
868
+ content: Union[str, OpenAIChatMessageContent]
869
+
870
+ model_config = ConfigDict(extra="allow")
871
+
872
+
873
+ class OpenAIChatCompletionForm(BaseModel):
874
+ model: str
875
+ messages: List[OpenAIChatMessage]
876
+
877
+ model_config = ConfigDict(extra="allow")
878
+
879
+
880
+ @app.post("/v1/chat/completions")
881
+ @app.post("/v1/chat/completions/{url_idx}")
882
+ async def generate_openai_chat_completion(
883
+ form_data: dict,
884
+ url_idx: Optional[int] = None,
885
+ user=Depends(get_verified_user),
886
+ ):
887
+ form_data = OpenAIChatCompletionForm(**form_data)
888
+
889
+ payload = {
890
+ **form_data.model_dump(exclude_none=True),
891
+ }
892
+
893
+ model_id = form_data.model
894
+ model_info = Models.get_model_by_id(model_id)
895
+
896
+ if model_info:
897
+ if model_info.base_model_id:
898
+ payload["model"] = model_info.base_model_id
899
+
900
+ model_info.params = model_info.params.model_dump()
901
+
902
+ if model_info.params:
903
+ payload["temperature"] = model_info.params.get("temperature", None)
904
+ payload["top_p"] = model_info.params.get("top_p", None)
905
+ payload["max_tokens"] = model_info.params.get("max_tokens", None)
906
+ payload["frequency_penalty"] = model_info.params.get(
907
+ "frequency_penalty", None
908
+ )
909
+ payload["seed"] = model_info.params.get("seed", None)
910
+ payload["stop"] = (
911
+ [
912
+ bytes(stop, "utf-8").decode("unicode_escape")
913
+ for stop in model_info.params["stop"]
914
+ ]
915
+ if model_info.params.get("stop", None)
916
+ else None
917
+ )
918
+
919
+ system = model_info.params.get("system", None)
920
+
921
+ if system:
922
+ system = prompt_template(
923
+ system,
924
+ **(
925
+ {
926
+ "user_name": user.name,
927
+ "user_location": (
928
+ user.info.get("location") if user.info else None
929
+ ),
930
+ }
931
+ if user
932
+ else {}
933
+ ),
934
+ )
935
+ # Check if the payload already has a system message
936
+ # If not, add a system message to the payload
937
+ if payload.get("messages"):
938
+ for message in payload["messages"]:
939
+ if message.get("role") == "system":
940
+ message["content"] = system + message["content"]
941
+ break
942
+ else:
943
+ payload["messages"].insert(
944
+ 0,
945
+ {
946
+ "role": "system",
947
+ "content": system,
948
+ },
949
+ )
950
+
951
+ if url_idx == None:
952
+ if ":" not in payload["model"]:
953
+ payload["model"] = f"{payload['model']}:latest"
954
+
955
+ if payload["model"] in app.state.MODELS:
956
+ url_idx = random.choice(app.state.MODELS[payload["model"]]["urls"])
957
+ else:
958
+ raise HTTPException(
959
+ status_code=400,
960
+ detail=ERROR_MESSAGES.MODEL_NOT_FOUND(form_data.model),
961
+ )
962
+
963
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
964
+ log.info(f"url: {url}")
965
+
966
+ return await post_streaming_url(f"{url}/v1/chat/completions", json.dumps(payload))
967
+
968
+
969
+ @app.get("/v1/models")
970
+ @app.get("/v1/models/{url_idx}")
971
+ async def get_openai_models(
972
+ url_idx: Optional[int] = None,
973
+ user=Depends(get_verified_user),
974
+ ):
975
+ if url_idx == None:
976
+ models = await get_all_models()
977
+
978
+ if app.state.config.ENABLE_MODEL_FILTER:
979
+ if user.role == "user":
980
+ models["models"] = list(
981
+ filter(
982
+ lambda model: model["name"]
983
+ in app.state.config.MODEL_FILTER_LIST,
984
+ models["models"],
985
+ )
986
+ )
987
+
988
+ return {
989
+ "data": [
990
+ {
991
+ "id": model["model"],
992
+ "object": "model",
993
+ "created": int(time.time()),
994
+ "owned_by": "openai",
995
+ }
996
+ for model in models["models"]
997
+ ],
998
+ "object": "list",
999
+ }
1000
+
1001
+ else:
1002
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
1003
+ try:
1004
+ r = requests.request(method="GET", url=f"{url}/api/tags")
1005
+ r.raise_for_status()
1006
+
1007
+ models = r.json()
1008
+
1009
+ return {
1010
+ "data": [
1011
+ {
1012
+ "id": model["model"],
1013
+ "object": "model",
1014
+ "created": int(time.time()),
1015
+ "owned_by": "openai",
1016
+ }
1017
+ for model in models["models"]
1018
+ ],
1019
+ "object": "list",
1020
+ }
1021
+
1022
+ except Exception as e:
1023
+ log.exception(e)
1024
+ error_detail = "Open WebUI: Server Connection Error"
1025
+ if r is not None:
1026
+ try:
1027
+ res = r.json()
1028
+ if "error" in res:
1029
+ error_detail = f"Ollama: {res['error']}"
1030
+ except:
1031
+ error_detail = f"Ollama: {e}"
1032
+
1033
+ raise HTTPException(
1034
+ status_code=r.status_code if r else 500,
1035
+ detail=error_detail,
1036
+ )
1037
+
1038
+
1039
+ class UrlForm(BaseModel):
1040
+ url: str
1041
+
1042
+
1043
+ class UploadBlobForm(BaseModel):
1044
+ filename: str
1045
+
1046
+
1047
+ def parse_huggingface_url(hf_url):
1048
+ try:
1049
+ # Parse the URL
1050
+ parsed_url = urlparse(hf_url)
1051
+
1052
+ # Get the path and split it into components
1053
+ path_components = parsed_url.path.split("/")
1054
+
1055
+ # Extract the desired output
1056
+ user_repo = "/".join(path_components[1:3])
1057
+ model_file = path_components[-1]
1058
+
1059
+ return model_file
1060
+ except ValueError:
1061
+ return None
1062
+
1063
+
1064
+ async def download_file_stream(
1065
+ ollama_url, file_url, file_path, file_name, chunk_size=1024 * 1024
1066
+ ):
1067
+ done = False
1068
+
1069
+ if os.path.exists(file_path):
1070
+ current_size = os.path.getsize(file_path)
1071
+ else:
1072
+ current_size = 0
1073
+
1074
+ headers = {"Range": f"bytes={current_size}-"} if current_size > 0 else {}
1075
+
1076
+ timeout = aiohttp.ClientTimeout(total=600) # Set the timeout
1077
+
1078
+ async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session:
1079
+ async with session.get(file_url, headers=headers) as response:
1080
+ total_size = int(response.headers.get("content-length", 0)) + current_size
1081
+
1082
+ with open(file_path, "ab+") as file:
1083
+ async for data in response.content.iter_chunked(chunk_size):
1084
+ current_size += len(data)
1085
+ file.write(data)
1086
+
1087
+ done = current_size == total_size
1088
+ progress = round((current_size / total_size) * 100, 2)
1089
+
1090
+ yield f'data: {{"progress": {progress}, "completed": {current_size}, "total": {total_size}}}\n\n'
1091
+
1092
+ if done:
1093
+ file.seek(0)
1094
+ hashed = calculate_sha256(file)
1095
+ file.seek(0)
1096
+
1097
+ url = f"{ollama_url}/api/blobs/sha256:{hashed}"
1098
+ response = requests.post(url, data=file)
1099
+
1100
+ if response.ok:
1101
+ res = {
1102
+ "done": done,
1103
+ "blob": f"sha256:{hashed}",
1104
+ "name": file_name,
1105
+ }
1106
+ os.remove(file_path)
1107
+
1108
+ yield f"data: {json.dumps(res)}\n\n"
1109
+ else:
1110
+ raise "Ollama: Could not create blob, Please try again."
1111
+
1112
+
1113
+ # url = "https://huggingface.co/TheBloke/stablelm-zephyr-3b-GGUF/resolve/main/stablelm-zephyr-3b.Q2_K.gguf"
1114
+ @app.post("/models/download")
1115
+ @app.post("/models/download/{url_idx}")
1116
+ async def download_model(
1117
+ form_data: UrlForm,
1118
+ url_idx: Optional[int] = None,
1119
+ user=Depends(get_admin_user),
1120
+ ):
1121
+
1122
+ allowed_hosts = ["https://huggingface.co/", "https://github.com/"]
1123
+
1124
+ if not any(form_data.url.startswith(host) for host in allowed_hosts):
1125
+ raise HTTPException(
1126
+ status_code=400,
1127
+ detail="Invalid file_url. Only URLs from allowed hosts are permitted.",
1128
+ )
1129
+
1130
+ if url_idx == None:
1131
+ url_idx = 0
1132
+ url = app.state.config.OLLAMA_BASE_URLS[url_idx]
1133
+
1134
+ file_name = parse_huggingface_url(form_data.url)
1135
+
1136
+ if file_name:
1137
+ file_path = f"{UPLOAD_DIR}/{file_name}"
1138
+
1139
+ return StreamingResponse(
1140
+ download_file_stream(url, form_data.url, file_path, file_name),
1141
+ )
1142
+ else:
1143
+ return None
1144
+
1145
+
1146
+ @app.post("/models/upload")
1147
+ @app.post("/models/upload/{url_idx}")
1148
+ def upload_model(
1149
+ file: UploadFile = File(...),
1150
+ url_idx: Optional[int] = None,
1151
+ user=Depends(get_admin_user),
1152
+ ):
1153
+ if url_idx == None:
1154
+ url_idx = 0
1155
+ ollama_url = app.state.config.OLLAMA_BASE_URLS[url_idx]
1156
+
1157
+ file_path = f"{UPLOAD_DIR}/{file.filename}"
1158
+
1159
+ # Save file in chunks
1160
+ with open(file_path, "wb+") as f:
1161
+ for chunk in file.file:
1162
+ f.write(chunk)
1163
+
1164
+ def file_process_stream():
1165
+ nonlocal ollama_url
1166
+ total_size = os.path.getsize(file_path)
1167
+ chunk_size = 1024 * 1024
1168
+ try:
1169
+ with open(file_path, "rb") as f:
1170
+ total = 0
1171
+ done = False
1172
+
1173
+ while not done:
1174
+ chunk = f.read(chunk_size)
1175
+ if not chunk:
1176
+ done = True
1177
+ continue
1178
+
1179
+ total += len(chunk)
1180
+ progress = round((total / total_size) * 100, 2)
1181
+
1182
+ res = {
1183
+ "progress": progress,
1184
+ "total": total_size,
1185
+ "completed": total,
1186
+ }
1187
+ yield f"data: {json.dumps(res)}\n\n"
1188
+
1189
+ if done:
1190
+ f.seek(0)
1191
+ hashed = calculate_sha256(f)
1192
+ f.seek(0)
1193
+
1194
+ url = f"{ollama_url}/api/blobs/sha256:{hashed}"
1195
+ response = requests.post(url, data=f)
1196
+
1197
+ if response.ok:
1198
+ res = {
1199
+ "done": done,
1200
+ "blob": f"sha256:{hashed}",
1201
+ "name": file.filename,
1202
+ }
1203
+ os.remove(file_path)
1204
+ yield f"data: {json.dumps(res)}\n\n"
1205
+ else:
1206
+ raise Exception(
1207
+ "Ollama: Could not create blob, Please try again."
1208
+ )
1209
+
1210
+ except Exception as e:
1211
+ res = {"error": str(e)}
1212
+ yield f"data: {json.dumps(res)}\n\n"
1213
+
1214
+ return StreamingResponse(file_process_stream(), media_type="text/event-stream")
backend/apps/openai/main.py ADDED
@@ -0,0 +1,569 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request, Response, HTTPException, Depends
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from fastapi.responses import StreamingResponse, JSONResponse, FileResponse
4
+
5
+ import requests
6
+ import aiohttp
7
+ import asyncio
8
+ import json
9
+ import logging
10
+
11
+ from pydantic import BaseModel
12
+ from starlette.background import BackgroundTask
13
+
14
+ from apps.webui.models.models import Models
15
+ from apps.webui.models.users import Users
16
+ from constants import ERROR_MESSAGES
17
+ from utils.utils import (
18
+ decode_token,
19
+ get_current_user,
20
+ get_verified_user,
21
+ get_admin_user,
22
+ )
23
+ from utils.task import prompt_template
24
+
25
+ from config import (
26
+ SRC_LOG_LEVELS,
27
+ ENABLE_OPENAI_API,
28
+ OPENAI_API_BASE_URLS,
29
+ OPENAI_API_KEYS,
30
+ CACHE_DIR,
31
+ ENABLE_MODEL_FILTER,
32
+ MODEL_FILTER_LIST,
33
+ AppConfig,
34
+ )
35
+ from typing import List, Optional
36
+
37
+
38
+ import hashlib
39
+ from pathlib import Path
40
+
41
+ log = logging.getLogger(__name__)
42
+ log.setLevel(SRC_LOG_LEVELS["OPENAI"])
43
+
44
+ app = FastAPI()
45
+ app.add_middleware(
46
+ CORSMiddleware,
47
+ allow_origins=["*"],
48
+ allow_credentials=True,
49
+ allow_methods=["*"],
50
+ allow_headers=["*"],
51
+ )
52
+
53
+
54
+ app.state.config = AppConfig()
55
+
56
+ app.state.config.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER
57
+ app.state.config.MODEL_FILTER_LIST = MODEL_FILTER_LIST
58
+
59
+ app.state.config.ENABLE_OPENAI_API = ENABLE_OPENAI_API
60
+ app.state.config.OPENAI_API_BASE_URLS = OPENAI_API_BASE_URLS
61
+ app.state.config.OPENAI_API_KEYS = OPENAI_API_KEYS
62
+
63
+ app.state.MODELS = {}
64
+
65
+
66
+ @app.middleware("http")
67
+ async def check_url(request: Request, call_next):
68
+ if len(app.state.MODELS) == 0:
69
+ await get_all_models()
70
+ else:
71
+ pass
72
+
73
+ response = await call_next(request)
74
+ return response
75
+
76
+
77
+ @app.get("/config")
78
+ async def get_config(user=Depends(get_admin_user)):
79
+ return {"ENABLE_OPENAI_API": app.state.config.ENABLE_OPENAI_API}
80
+
81
+
82
+ class OpenAIConfigForm(BaseModel):
83
+ enable_openai_api: Optional[bool] = None
84
+
85
+
86
+ @app.post("/config/update")
87
+ async def update_config(form_data: OpenAIConfigForm, user=Depends(get_admin_user)):
88
+ app.state.config.ENABLE_OPENAI_API = form_data.enable_openai_api
89
+ return {"ENABLE_OPENAI_API": app.state.config.ENABLE_OPENAI_API}
90
+
91
+
92
+ class UrlsUpdateForm(BaseModel):
93
+ urls: List[str]
94
+
95
+
96
+ class KeysUpdateForm(BaseModel):
97
+ keys: List[str]
98
+
99
+
100
+ @app.get("/urls")
101
+ async def get_openai_urls(user=Depends(get_admin_user)):
102
+ return {"OPENAI_API_BASE_URLS": app.state.config.OPENAI_API_BASE_URLS}
103
+
104
+
105
+ @app.post("/urls/update")
106
+ async def update_openai_urls(form_data: UrlsUpdateForm, user=Depends(get_admin_user)):
107
+ await get_all_models()
108
+ app.state.config.OPENAI_API_BASE_URLS = form_data.urls
109
+ return {"OPENAI_API_BASE_URLS": app.state.config.OPENAI_API_BASE_URLS}
110
+
111
+
112
+ @app.get("/keys")
113
+ async def get_openai_keys(user=Depends(get_admin_user)):
114
+ return {"OPENAI_API_KEYS": app.state.config.OPENAI_API_KEYS}
115
+
116
+
117
+ @app.post("/keys/update")
118
+ async def update_openai_key(form_data: KeysUpdateForm, user=Depends(get_admin_user)):
119
+ app.state.config.OPENAI_API_KEYS = form_data.keys
120
+ return {"OPENAI_API_KEYS": app.state.config.OPENAI_API_KEYS}
121
+
122
+
123
+ @app.post("/audio/speech")
124
+ async def speech(request: Request, user=Depends(get_verified_user)):
125
+ idx = None
126
+ try:
127
+ idx = app.state.config.OPENAI_API_BASE_URLS.index("https://api.openai.com/v1")
128
+ body = await request.body()
129
+ name = hashlib.sha256(body).hexdigest()
130
+
131
+ SPEECH_CACHE_DIR = Path(CACHE_DIR).joinpath("./audio/speech/")
132
+ SPEECH_CACHE_DIR.mkdir(parents=True, exist_ok=True)
133
+ file_path = SPEECH_CACHE_DIR.joinpath(f"{name}.mp3")
134
+ file_body_path = SPEECH_CACHE_DIR.joinpath(f"{name}.json")
135
+
136
+ # Check if the file already exists in the cache
137
+ if file_path.is_file():
138
+ return FileResponse(file_path)
139
+
140
+ headers = {}
141
+ headers["Authorization"] = f"Bearer {app.state.config.OPENAI_API_KEYS[idx]}"
142
+ headers["Content-Type"] = "application/json"
143
+ if "openrouter.ai" in app.state.config.OPENAI_API_BASE_URLS[idx]:
144
+ headers["HTTP-Referer"] = "https://openwebui.com/"
145
+ headers["X-Title"] = "Open WebUI"
146
+ r = None
147
+ try:
148
+ r = requests.post(
149
+ url=f"{app.state.config.OPENAI_API_BASE_URLS[idx]}/audio/speech",
150
+ data=body,
151
+ headers=headers,
152
+ stream=True,
153
+ )
154
+
155
+ r.raise_for_status()
156
+
157
+ # Save the streaming content to a file
158
+ with open(file_path, "wb") as f:
159
+ for chunk in r.iter_content(chunk_size=8192):
160
+ f.write(chunk)
161
+
162
+ with open(file_body_path, "w") as f:
163
+ json.dump(json.loads(body.decode("utf-8")), f)
164
+
165
+ # Return the saved file
166
+ return FileResponse(file_path)
167
+
168
+ except Exception as e:
169
+ log.exception(e)
170
+ error_detail = "Open WebUI: Server Connection Error"
171
+ if r is not None:
172
+ try:
173
+ res = r.json()
174
+ if "error" in res:
175
+ error_detail = f"External: {res['error']}"
176
+ except:
177
+ error_detail = f"External: {e}"
178
+
179
+ raise HTTPException(
180
+ status_code=r.status_code if r else 500, detail=error_detail
181
+ )
182
+
183
+ except ValueError:
184
+ raise HTTPException(status_code=401, detail=ERROR_MESSAGES.OPENAI_NOT_FOUND)
185
+
186
+
187
+ async def fetch_url(url, key):
188
+ timeout = aiohttp.ClientTimeout(total=5)
189
+ try:
190
+ headers = {"Authorization": f"Bearer {key}"}
191
+ async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session:
192
+ async with session.get(url, headers=headers) as response:
193
+ return await response.json()
194
+ except Exception as e:
195
+ # Handle connection error here
196
+ log.error(f"Connection error: {e}")
197
+ return None
198
+
199
+
200
+ async def cleanup_response(
201
+ response: Optional[aiohttp.ClientResponse],
202
+ session: Optional[aiohttp.ClientSession],
203
+ ):
204
+ if response:
205
+ response.close()
206
+ if session:
207
+ await session.close()
208
+
209
+
210
+ def merge_models_lists(model_lists):
211
+ log.debug(f"merge_models_lists {model_lists}")
212
+ merged_list = []
213
+
214
+ for idx, models in enumerate(model_lists):
215
+ if models is not None and "error" not in models:
216
+ merged_list.extend(
217
+ [
218
+ {
219
+ **model,
220
+ "name": model.get("name", model["id"]),
221
+ "owned_by": "openai",
222
+ "openai": model,
223
+ "urlIdx": idx,
224
+ }
225
+ for model in models
226
+ if "api.openai.com"
227
+ not in app.state.config.OPENAI_API_BASE_URLS[idx]
228
+ or "gpt" in model["id"]
229
+ ]
230
+ )
231
+
232
+ return merged_list
233
+
234
+
235
+ async def get_all_models(raw: bool = False):
236
+ log.info("get_all_models()")
237
+
238
+ if (
239
+ len(app.state.config.OPENAI_API_KEYS) == 1
240
+ and app.state.config.OPENAI_API_KEYS[0] == ""
241
+ ) or not app.state.config.ENABLE_OPENAI_API:
242
+ models = {"data": []}
243
+ else:
244
+ # Check if API KEYS length is same than API URLS length
245
+ if len(app.state.config.OPENAI_API_KEYS) != len(
246
+ app.state.config.OPENAI_API_BASE_URLS
247
+ ):
248
+ # if there are more keys than urls, remove the extra keys
249
+ if len(app.state.config.OPENAI_API_KEYS) > len(
250
+ app.state.config.OPENAI_API_BASE_URLS
251
+ ):
252
+ app.state.config.OPENAI_API_KEYS = app.state.config.OPENAI_API_KEYS[
253
+ : len(app.state.config.OPENAI_API_BASE_URLS)
254
+ ]
255
+ # if there are more urls than keys, add empty keys
256
+ else:
257
+ app.state.config.OPENAI_API_KEYS += [
258
+ ""
259
+ for _ in range(
260
+ len(app.state.config.OPENAI_API_BASE_URLS)
261
+ - len(app.state.config.OPENAI_API_KEYS)
262
+ )
263
+ ]
264
+
265
+ tasks = [
266
+ fetch_url(f"{url}/models", app.state.config.OPENAI_API_KEYS[idx])
267
+ for idx, url in enumerate(app.state.config.OPENAI_API_BASE_URLS)
268
+ ]
269
+
270
+ responses = await asyncio.gather(*tasks)
271
+ log.debug(f"get_all_models:responses() {responses}")
272
+
273
+ if raw:
274
+ return responses
275
+
276
+ models = {
277
+ "data": merge_models_lists(
278
+ list(
279
+ map(
280
+ lambda response: (
281
+ response["data"]
282
+ if (response and "data" in response)
283
+ else (response if isinstance(response, list) else None)
284
+ ),
285
+ responses,
286
+ )
287
+ )
288
+ )
289
+ }
290
+
291
+ log.debug(f"models: {models}")
292
+ app.state.MODELS = {model["id"]: model for model in models["data"]}
293
+
294
+ return models
295
+
296
+
297
+ @app.get("/models")
298
+ @app.get("/models/{url_idx}")
299
+ async def get_models(url_idx: Optional[int] = None, user=Depends(get_current_user)):
300
+ if url_idx == None:
301
+ models = await get_all_models()
302
+ if app.state.config.ENABLE_MODEL_FILTER:
303
+ if user.role == "user":
304
+ models["data"] = list(
305
+ filter(
306
+ lambda model: model["id"] in app.state.config.MODEL_FILTER_LIST,
307
+ models["data"],
308
+ )
309
+ )
310
+ return models
311
+ return models
312
+ else:
313
+ url = app.state.config.OPENAI_API_BASE_URLS[url_idx]
314
+ key = app.state.config.OPENAI_API_KEYS[url_idx]
315
+
316
+ headers = {}
317
+ headers["Authorization"] = f"Bearer {key}"
318
+ headers["Content-Type"] = "application/json"
319
+
320
+ r = None
321
+
322
+ try:
323
+ r = requests.request(method="GET", url=f"{url}/models", headers=headers)
324
+ r.raise_for_status()
325
+
326
+ response_data = r.json()
327
+ if "api.openai.com" in url:
328
+ response_data["data"] = list(
329
+ filter(lambda model: "gpt" in model["id"], response_data["data"])
330
+ )
331
+
332
+ return response_data
333
+ except Exception as e:
334
+ log.exception(e)
335
+ error_detail = "Open WebUI: Server Connection Error"
336
+ if r is not None:
337
+ try:
338
+ res = r.json()
339
+ if "error" in res:
340
+ error_detail = f"External: {res['error']}"
341
+ except:
342
+ error_detail = f"External: {e}"
343
+
344
+ raise HTTPException(
345
+ status_code=r.status_code if r else 500,
346
+ detail=error_detail,
347
+ )
348
+
349
+
350
+ @app.post("/chat/completions")
351
+ @app.post("/chat/completions/{url_idx}")
352
+ async def generate_chat_completion(
353
+ form_data: dict,
354
+ url_idx: Optional[int] = None,
355
+ user=Depends(get_verified_user),
356
+ ):
357
+ idx = 0
358
+ payload = {**form_data}
359
+
360
+ model_id = form_data.get("model")
361
+ model_info = Models.get_model_by_id(model_id)
362
+
363
+ if model_info:
364
+ if model_info.base_model_id:
365
+ payload["model"] = model_info.base_model_id
366
+
367
+ model_info.params = model_info.params.model_dump()
368
+
369
+ if model_info.params:
370
+ if model_info.params.get("temperature", None) is not None:
371
+ payload["temperature"] = float(model_info.params.get("temperature"))
372
+
373
+ if model_info.params.get("top_p", None):
374
+ payload["top_p"] = int(model_info.params.get("top_p", None))
375
+
376
+ if model_info.params.get("max_tokens", None):
377
+ payload["max_tokens"] = int(model_info.params.get("max_tokens", None))
378
+
379
+ if model_info.params.get("frequency_penalty", None):
380
+ payload["frequency_penalty"] = int(
381
+ model_info.params.get("frequency_penalty", None)
382
+ )
383
+
384
+ if model_info.params.get("seed", None):
385
+ payload["seed"] = model_info.params.get("seed", None)
386
+
387
+ if model_info.params.get("stop", None):
388
+ payload["stop"] = (
389
+ [
390
+ bytes(stop, "utf-8").decode("unicode_escape")
391
+ for stop in model_info.params["stop"]
392
+ ]
393
+ if model_info.params.get("stop", None)
394
+ else None
395
+ )
396
+
397
+ system = model_info.params.get("system", None)
398
+ if system:
399
+ system = prompt_template(
400
+ system,
401
+ **(
402
+ {
403
+ "user_name": user.name,
404
+ "user_location": (
405
+ user.info.get("location") if user.info else None
406
+ ),
407
+ }
408
+ if user
409
+ else {}
410
+ ),
411
+ )
412
+ # Check if the payload already has a system message
413
+ # If not, add a system message to the payload
414
+ if payload.get("messages"):
415
+ for message in payload["messages"]:
416
+ if message.get("role") == "system":
417
+ message["content"] = system + message["content"]
418
+ break
419
+ else:
420
+ payload["messages"].insert(
421
+ 0,
422
+ {
423
+ "role": "system",
424
+ "content": system,
425
+ },
426
+ )
427
+
428
+ else:
429
+ pass
430
+
431
+ model = app.state.MODELS[payload.get("model")]
432
+ idx = model["urlIdx"]
433
+
434
+ if "pipeline" in model and model.get("pipeline"):
435
+ payload["user"] = {
436
+ "name": user.name,
437
+ "id": user.id,
438
+ "email": user.email,
439
+ "role": user.role,
440
+ }
441
+
442
+ # Check if the model is "gpt-4-vision-preview" and set "max_tokens" to 4000
443
+ # This is a workaround until OpenAI fixes the issue with this model
444
+ if payload.get("model") == "gpt-4-vision-preview":
445
+ if "max_tokens" not in payload:
446
+ payload["max_tokens"] = 4000
447
+ log.debug("Modified payload:", payload)
448
+
449
+ # Convert the modified body back to JSON
450
+ payload = json.dumps(payload)
451
+
452
+ log.debug(payload)
453
+
454
+ url = app.state.config.OPENAI_API_BASE_URLS[idx]
455
+ key = app.state.config.OPENAI_API_KEYS[idx]
456
+
457
+ headers = {}
458
+ headers["Authorization"] = f"Bearer {key}"
459
+ headers["Content-Type"] = "application/json"
460
+
461
+ r = None
462
+ session = None
463
+ streaming = False
464
+
465
+ try:
466
+ session = aiohttp.ClientSession(trust_env=True)
467
+ r = await session.request(
468
+ method="POST",
469
+ url=f"{url}/chat/completions",
470
+ data=payload,
471
+ headers=headers,
472
+ )
473
+
474
+ r.raise_for_status()
475
+
476
+ # Check if response is SSE
477
+ if "text/event-stream" in r.headers.get("Content-Type", ""):
478
+ streaming = True
479
+ return StreamingResponse(
480
+ r.content,
481
+ status_code=r.status,
482
+ headers=dict(r.headers),
483
+ background=BackgroundTask(
484
+ cleanup_response, response=r, session=session
485
+ ),
486
+ )
487
+ else:
488
+ response_data = await r.json()
489
+ return response_data
490
+ except Exception as e:
491
+ log.exception(e)
492
+ error_detail = "Open WebUI: Server Connection Error"
493
+ if r is not None:
494
+ try:
495
+ res = await r.json()
496
+ print(res)
497
+ if "error" in res:
498
+ error_detail = f"External: {res['error']['message'] if 'message' in res['error'] else res['error']}"
499
+ except:
500
+ error_detail = f"External: {e}"
501
+ raise HTTPException(status_code=r.status if r else 500, detail=error_detail)
502
+ finally:
503
+ if not streaming and session:
504
+ if r:
505
+ r.close()
506
+ await session.close()
507
+
508
+
509
+ @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
510
+ async def proxy(path: str, request: Request, user=Depends(get_verified_user)):
511
+ idx = 0
512
+
513
+ body = await request.body()
514
+
515
+ url = app.state.config.OPENAI_API_BASE_URLS[idx]
516
+ key = app.state.config.OPENAI_API_KEYS[idx]
517
+
518
+ target_url = f"{url}/{path}"
519
+
520
+ headers = {}
521
+ headers["Authorization"] = f"Bearer {key}"
522
+ headers["Content-Type"] = "application/json"
523
+
524
+ r = None
525
+ session = None
526
+ streaming = False
527
+
528
+ try:
529
+ session = aiohttp.ClientSession(trust_env=True)
530
+ r = await session.request(
531
+ method=request.method,
532
+ url=target_url,
533
+ data=body,
534
+ headers=headers,
535
+ )
536
+
537
+ r.raise_for_status()
538
+
539
+ # Check if response is SSE
540
+ if "text/event-stream" in r.headers.get("Content-Type", ""):
541
+ streaming = True
542
+ return StreamingResponse(
543
+ r.content,
544
+ status_code=r.status,
545
+ headers=dict(r.headers),
546
+ background=BackgroundTask(
547
+ cleanup_response, response=r, session=session
548
+ ),
549
+ )
550
+ else:
551
+ response_data = await r.json()
552
+ return response_data
553
+ except Exception as e:
554
+ log.exception(e)
555
+ error_detail = "Open WebUI: Server Connection Error"
556
+ if r is not None:
557
+ try:
558
+ res = await r.json()
559
+ print(res)
560
+ if "error" in res:
561
+ error_detail = f"External: {res['error']['message'] if 'message' in res['error'] else res['error']}"
562
+ except:
563
+ error_detail = f"External: {e}"
564
+ raise HTTPException(status_code=r.status if r else 500, detail=error_detail)
565
+ finally:
566
+ if not streaming and session:
567
+ if r:
568
+ r.close()
569
+ await session.close()
backend/apps/rag/main.py ADDED
@@ -0,0 +1,1368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import (
2
+ FastAPI,
3
+ Depends,
4
+ HTTPException,
5
+ status,
6
+ UploadFile,
7
+ File,
8
+ Form,
9
+ )
10
+ from fastapi.middleware.cors import CORSMiddleware
11
+ import requests
12
+ import os, shutil, logging, re
13
+ from datetime import datetime
14
+
15
+ from pathlib import Path
16
+ from typing import List, Union, Sequence, Iterator, Any
17
+
18
+ from chromadb.utils.batch_utils import create_batches
19
+ from langchain_core.documents import Document
20
+
21
+ from langchain_community.document_loaders import (
22
+ WebBaseLoader,
23
+ TextLoader,
24
+ PyPDFLoader,
25
+ CSVLoader,
26
+ BSHTMLLoader,
27
+ Docx2txtLoader,
28
+ UnstructuredEPubLoader,
29
+ UnstructuredWordDocumentLoader,
30
+ UnstructuredMarkdownLoader,
31
+ UnstructuredXMLLoader,
32
+ UnstructuredRSTLoader,
33
+ UnstructuredExcelLoader,
34
+ UnstructuredPowerPointLoader,
35
+ YoutubeLoader,
36
+ OutlookMessageLoader,
37
+ )
38
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
39
+
40
+ import validators
41
+ import urllib.parse
42
+ import socket
43
+
44
+
45
+ from pydantic import BaseModel
46
+ from typing import Optional
47
+ import mimetypes
48
+ import uuid
49
+ import json
50
+
51
+ import sentence_transformers
52
+
53
+ from apps.webui.models.documents import (
54
+ Documents,
55
+ DocumentForm,
56
+ DocumentResponse,
57
+ )
58
+ from apps.webui.models.files import (
59
+ Files,
60
+ )
61
+
62
+ from apps.rag.utils import (
63
+ get_model_path,
64
+ get_embedding_function,
65
+ query_doc,
66
+ query_doc_with_hybrid_search,
67
+ query_collection,
68
+ query_collection_with_hybrid_search,
69
+ )
70
+
71
+ from apps.rag.search.brave import search_brave
72
+ from apps.rag.search.google_pse import search_google_pse
73
+ from apps.rag.search.main import SearchResult
74
+ from apps.rag.search.searxng import search_searxng
75
+ from apps.rag.search.serper import search_serper
76
+ from apps.rag.search.serpstack import search_serpstack
77
+ from apps.rag.search.serply import search_serply
78
+ from apps.rag.search.duckduckgo import search_duckduckgo
79
+ from apps.rag.search.tavily import search_tavily
80
+
81
+ from utils.misc import (
82
+ calculate_sha256,
83
+ calculate_sha256_string,
84
+ sanitize_filename,
85
+ extract_folders_after_data_docs,
86
+ )
87
+ from utils.utils import get_current_user, get_admin_user
88
+
89
+ from config import (
90
+ AppConfig,
91
+ ENV,
92
+ SRC_LOG_LEVELS,
93
+ UPLOAD_DIR,
94
+ DOCS_DIR,
95
+ RAG_TOP_K,
96
+ RAG_RELEVANCE_THRESHOLD,
97
+ RAG_EMBEDDING_ENGINE,
98
+ RAG_EMBEDDING_MODEL,
99
+ RAG_EMBEDDING_MODEL_AUTO_UPDATE,
100
+ RAG_EMBEDDING_MODEL_TRUST_REMOTE_CODE,
101
+ ENABLE_RAG_HYBRID_SEARCH,
102
+ ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION,
103
+ RAG_RERANKING_MODEL,
104
+ PDF_EXTRACT_IMAGES,
105
+ RAG_RERANKING_MODEL_AUTO_UPDATE,
106
+ RAG_RERANKING_MODEL_TRUST_REMOTE_CODE,
107
+ RAG_OPENAI_API_BASE_URL,
108
+ RAG_OPENAI_API_KEY,
109
+ DEVICE_TYPE,
110
+ CHROMA_CLIENT,
111
+ CHUNK_SIZE,
112
+ CHUNK_OVERLAP,
113
+ RAG_TEMPLATE,
114
+ ENABLE_RAG_LOCAL_WEB_FETCH,
115
+ YOUTUBE_LOADER_LANGUAGE,
116
+ ENABLE_RAG_WEB_SEARCH,
117
+ RAG_WEB_SEARCH_ENGINE,
118
+ RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
119
+ SEARXNG_QUERY_URL,
120
+ GOOGLE_PSE_API_KEY,
121
+ GOOGLE_PSE_ENGINE_ID,
122
+ BRAVE_SEARCH_API_KEY,
123
+ SERPSTACK_API_KEY,
124
+ SERPSTACK_HTTPS,
125
+ SERPER_API_KEY,
126
+ SERPLY_API_KEY,
127
+ TAVILY_API_KEY,
128
+ RAG_WEB_SEARCH_RESULT_COUNT,
129
+ RAG_WEB_SEARCH_CONCURRENT_REQUESTS,
130
+ RAG_EMBEDDING_OPENAI_BATCH_SIZE,
131
+ )
132
+
133
+ from constants import ERROR_MESSAGES
134
+
135
+ log = logging.getLogger(__name__)
136
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
137
+
138
+ app = FastAPI()
139
+
140
+ app.state.config = AppConfig()
141
+
142
+ app.state.config.TOP_K = RAG_TOP_K
143
+ app.state.config.RELEVANCE_THRESHOLD = RAG_RELEVANCE_THRESHOLD
144
+
145
+ app.state.config.ENABLE_RAG_HYBRID_SEARCH = ENABLE_RAG_HYBRID_SEARCH
146
+ app.state.config.ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION = (
147
+ ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION
148
+ )
149
+
150
+ app.state.config.CHUNK_SIZE = CHUNK_SIZE
151
+ app.state.config.CHUNK_OVERLAP = CHUNK_OVERLAP
152
+
153
+ app.state.config.RAG_EMBEDDING_ENGINE = RAG_EMBEDDING_ENGINE
154
+ app.state.config.RAG_EMBEDDING_MODEL = RAG_EMBEDDING_MODEL
155
+ app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE = RAG_EMBEDDING_OPENAI_BATCH_SIZE
156
+ app.state.config.RAG_RERANKING_MODEL = RAG_RERANKING_MODEL
157
+ app.state.config.RAG_TEMPLATE = RAG_TEMPLATE
158
+
159
+
160
+ app.state.config.OPENAI_API_BASE_URL = RAG_OPENAI_API_BASE_URL
161
+ app.state.config.OPENAI_API_KEY = RAG_OPENAI_API_KEY
162
+
163
+ app.state.config.PDF_EXTRACT_IMAGES = PDF_EXTRACT_IMAGES
164
+
165
+
166
+ app.state.config.YOUTUBE_LOADER_LANGUAGE = YOUTUBE_LOADER_LANGUAGE
167
+ app.state.YOUTUBE_LOADER_TRANSLATION = None
168
+
169
+
170
+ app.state.config.ENABLE_RAG_WEB_SEARCH = ENABLE_RAG_WEB_SEARCH
171
+ app.state.config.RAG_WEB_SEARCH_ENGINE = RAG_WEB_SEARCH_ENGINE
172
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST = RAG_WEB_SEARCH_DOMAIN_FILTER_LIST
173
+
174
+ app.state.config.SEARXNG_QUERY_URL = SEARXNG_QUERY_URL
175
+ app.state.config.GOOGLE_PSE_API_KEY = GOOGLE_PSE_API_KEY
176
+ app.state.config.GOOGLE_PSE_ENGINE_ID = GOOGLE_PSE_ENGINE_ID
177
+ app.state.config.BRAVE_SEARCH_API_KEY = BRAVE_SEARCH_API_KEY
178
+ app.state.config.SERPSTACK_API_KEY = SERPSTACK_API_KEY
179
+ app.state.config.SERPSTACK_HTTPS = SERPSTACK_HTTPS
180
+ app.state.config.SERPER_API_KEY = SERPER_API_KEY
181
+ app.state.config.SERPLY_API_KEY = SERPLY_API_KEY
182
+ app.state.config.TAVILY_API_KEY = TAVILY_API_KEY
183
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT = RAG_WEB_SEARCH_RESULT_COUNT
184
+ app.state.config.RAG_WEB_SEARCH_CONCURRENT_REQUESTS = RAG_WEB_SEARCH_CONCURRENT_REQUESTS
185
+
186
+
187
+ def update_embedding_model(
188
+ embedding_model: str,
189
+ update_model: bool = False,
190
+ ):
191
+ if embedding_model and app.state.config.RAG_EMBEDDING_ENGINE == "":
192
+ app.state.sentence_transformer_ef = sentence_transformers.SentenceTransformer(
193
+ get_model_path(embedding_model, update_model),
194
+ device=DEVICE_TYPE,
195
+ trust_remote_code=RAG_EMBEDDING_MODEL_TRUST_REMOTE_CODE,
196
+ )
197
+ else:
198
+ app.state.sentence_transformer_ef = None
199
+
200
+
201
+ def update_reranking_model(
202
+ reranking_model: str,
203
+ update_model: bool = False,
204
+ ):
205
+ if reranking_model:
206
+ app.state.sentence_transformer_rf = sentence_transformers.CrossEncoder(
207
+ get_model_path(reranking_model, update_model),
208
+ device=DEVICE_TYPE,
209
+ trust_remote_code=RAG_RERANKING_MODEL_TRUST_REMOTE_CODE,
210
+ )
211
+ else:
212
+ app.state.sentence_transformer_rf = None
213
+
214
+
215
+ update_embedding_model(
216
+ app.state.config.RAG_EMBEDDING_MODEL,
217
+ RAG_EMBEDDING_MODEL_AUTO_UPDATE,
218
+ )
219
+
220
+ update_reranking_model(
221
+ app.state.config.RAG_RERANKING_MODEL,
222
+ RAG_RERANKING_MODEL_AUTO_UPDATE,
223
+ )
224
+
225
+
226
+ app.state.EMBEDDING_FUNCTION = get_embedding_function(
227
+ app.state.config.RAG_EMBEDDING_ENGINE,
228
+ app.state.config.RAG_EMBEDDING_MODEL,
229
+ app.state.sentence_transformer_ef,
230
+ app.state.config.OPENAI_API_KEY,
231
+ app.state.config.OPENAI_API_BASE_URL,
232
+ app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE,
233
+ )
234
+
235
+ origins = ["*"]
236
+
237
+
238
+ app.add_middleware(
239
+ CORSMiddleware,
240
+ allow_origins=origins,
241
+ allow_credentials=True,
242
+ allow_methods=["*"],
243
+ allow_headers=["*"],
244
+ )
245
+
246
+
247
+ class CollectionNameForm(BaseModel):
248
+ collection_name: Optional[str] = "test"
249
+
250
+
251
+ class UrlForm(CollectionNameForm):
252
+ url: str
253
+
254
+
255
+ class SearchForm(CollectionNameForm):
256
+ query: str
257
+
258
+
259
+ @app.get("/")
260
+ async def get_status():
261
+ return {
262
+ "status": True,
263
+ "chunk_size": app.state.config.CHUNK_SIZE,
264
+ "chunk_overlap": app.state.config.CHUNK_OVERLAP,
265
+ "template": app.state.config.RAG_TEMPLATE,
266
+ "embedding_engine": app.state.config.RAG_EMBEDDING_ENGINE,
267
+ "embedding_model": app.state.config.RAG_EMBEDDING_MODEL,
268
+ "reranking_model": app.state.config.RAG_RERANKING_MODEL,
269
+ "openai_batch_size": app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE,
270
+ }
271
+
272
+
273
+ @app.get("/embedding")
274
+ async def get_embedding_config(user=Depends(get_admin_user)):
275
+ return {
276
+ "status": True,
277
+ "embedding_engine": app.state.config.RAG_EMBEDDING_ENGINE,
278
+ "embedding_model": app.state.config.RAG_EMBEDDING_MODEL,
279
+ "openai_config": {
280
+ "url": app.state.config.OPENAI_API_BASE_URL,
281
+ "key": app.state.config.OPENAI_API_KEY,
282
+ "batch_size": app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE,
283
+ },
284
+ }
285
+
286
+
287
+ @app.get("/reranking")
288
+ async def get_reraanking_config(user=Depends(get_admin_user)):
289
+ return {
290
+ "status": True,
291
+ "reranking_model": app.state.config.RAG_RERANKING_MODEL,
292
+ }
293
+
294
+
295
+ class OpenAIConfigForm(BaseModel):
296
+ url: str
297
+ key: str
298
+ batch_size: Optional[int] = None
299
+
300
+
301
+ class EmbeddingModelUpdateForm(BaseModel):
302
+ openai_config: Optional[OpenAIConfigForm] = None
303
+ embedding_engine: str
304
+ embedding_model: str
305
+
306
+
307
+ @app.post("/embedding/update")
308
+ async def update_embedding_config(
309
+ form_data: EmbeddingModelUpdateForm, user=Depends(get_admin_user)
310
+ ):
311
+ log.info(
312
+ f"Updating embedding model: {app.state.config.RAG_EMBEDDING_MODEL} to {form_data.embedding_model}"
313
+ )
314
+ try:
315
+ app.state.config.RAG_EMBEDDING_ENGINE = form_data.embedding_engine
316
+ app.state.config.RAG_EMBEDDING_MODEL = form_data.embedding_model
317
+
318
+ if app.state.config.RAG_EMBEDDING_ENGINE in ["ollama", "openai"]:
319
+ if form_data.openai_config is not None:
320
+ app.state.config.OPENAI_API_BASE_URL = form_data.openai_config.url
321
+ app.state.config.OPENAI_API_KEY = form_data.openai_config.key
322
+ app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE = (
323
+ form_data.openai_config.batch_size
324
+ if form_data.openai_config.batch_size
325
+ else 1
326
+ )
327
+
328
+ update_embedding_model(app.state.config.RAG_EMBEDDING_MODEL)
329
+
330
+ app.state.EMBEDDING_FUNCTION = get_embedding_function(
331
+ app.state.config.RAG_EMBEDDING_ENGINE,
332
+ app.state.config.RAG_EMBEDDING_MODEL,
333
+ app.state.sentence_transformer_ef,
334
+ app.state.config.OPENAI_API_KEY,
335
+ app.state.config.OPENAI_API_BASE_URL,
336
+ app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE,
337
+ )
338
+
339
+ return {
340
+ "status": True,
341
+ "embedding_engine": app.state.config.RAG_EMBEDDING_ENGINE,
342
+ "embedding_model": app.state.config.RAG_EMBEDDING_MODEL,
343
+ "openai_config": {
344
+ "url": app.state.config.OPENAI_API_BASE_URL,
345
+ "key": app.state.config.OPENAI_API_KEY,
346
+ "batch_size": app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE,
347
+ },
348
+ }
349
+ except Exception as e:
350
+ log.exception(f"Problem updating embedding model: {e}")
351
+ raise HTTPException(
352
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
353
+ detail=ERROR_MESSAGES.DEFAULT(e),
354
+ )
355
+
356
+
357
+ class RerankingModelUpdateForm(BaseModel):
358
+ reranking_model: str
359
+
360
+
361
+ @app.post("/reranking/update")
362
+ async def update_reranking_config(
363
+ form_data: RerankingModelUpdateForm, user=Depends(get_admin_user)
364
+ ):
365
+ log.info(
366
+ f"Updating reranking model: {app.state.config.RAG_RERANKING_MODEL} to {form_data.reranking_model}"
367
+ )
368
+ try:
369
+ app.state.config.RAG_RERANKING_MODEL = form_data.reranking_model
370
+
371
+ update_reranking_model(app.state.config.RAG_RERANKING_MODEL), True
372
+
373
+ return {
374
+ "status": True,
375
+ "reranking_model": app.state.config.RAG_RERANKING_MODEL,
376
+ }
377
+ except Exception as e:
378
+ log.exception(f"Problem updating reranking model: {e}")
379
+ raise HTTPException(
380
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
381
+ detail=ERROR_MESSAGES.DEFAULT(e),
382
+ )
383
+
384
+
385
+ @app.get("/config")
386
+ async def get_rag_config(user=Depends(get_admin_user)):
387
+ return {
388
+ "status": True,
389
+ "pdf_extract_images": app.state.config.PDF_EXTRACT_IMAGES,
390
+ "chunk": {
391
+ "chunk_size": app.state.config.CHUNK_SIZE,
392
+ "chunk_overlap": app.state.config.CHUNK_OVERLAP,
393
+ },
394
+ "youtube": {
395
+ "language": app.state.config.YOUTUBE_LOADER_LANGUAGE,
396
+ "translation": app.state.YOUTUBE_LOADER_TRANSLATION,
397
+ },
398
+ "web": {
399
+ "ssl_verification": app.state.config.ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION,
400
+ "search": {
401
+ "enabled": app.state.config.ENABLE_RAG_WEB_SEARCH,
402
+ "engine": app.state.config.RAG_WEB_SEARCH_ENGINE,
403
+ "searxng_query_url": app.state.config.SEARXNG_QUERY_URL,
404
+ "google_pse_api_key": app.state.config.GOOGLE_PSE_API_KEY,
405
+ "google_pse_engine_id": app.state.config.GOOGLE_PSE_ENGINE_ID,
406
+ "brave_search_api_key": app.state.config.BRAVE_SEARCH_API_KEY,
407
+ "serpstack_api_key": app.state.config.SERPSTACK_API_KEY,
408
+ "serpstack_https": app.state.config.SERPSTACK_HTTPS,
409
+ "serper_api_key": app.state.config.SERPER_API_KEY,
410
+ "serply_api_key": app.state.config.SERPLY_API_KEY,
411
+ "tavily_api_key": app.state.config.TAVILY_API_KEY,
412
+ "result_count": app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
413
+ "concurrent_requests": app.state.config.RAG_WEB_SEARCH_CONCURRENT_REQUESTS,
414
+ },
415
+ },
416
+ }
417
+
418
+
419
+ class ChunkParamUpdateForm(BaseModel):
420
+ chunk_size: int
421
+ chunk_overlap: int
422
+
423
+
424
+ class YoutubeLoaderConfig(BaseModel):
425
+ language: List[str]
426
+ translation: Optional[str] = None
427
+
428
+
429
+ class WebSearchConfig(BaseModel):
430
+ enabled: bool
431
+ engine: Optional[str] = None
432
+ searxng_query_url: Optional[str] = None
433
+ google_pse_api_key: Optional[str] = None
434
+ google_pse_engine_id: Optional[str] = None
435
+ brave_search_api_key: Optional[str] = None
436
+ serpstack_api_key: Optional[str] = None
437
+ serpstack_https: Optional[bool] = None
438
+ serper_api_key: Optional[str] = None
439
+ serply_api_key: Optional[str] = None
440
+ tavily_api_key: Optional[str] = None
441
+ result_count: Optional[int] = None
442
+ concurrent_requests: Optional[int] = None
443
+
444
+
445
+ class WebConfig(BaseModel):
446
+ search: WebSearchConfig
447
+ web_loader_ssl_verification: Optional[bool] = None
448
+
449
+
450
+ class ConfigUpdateForm(BaseModel):
451
+ pdf_extract_images: Optional[bool] = None
452
+ chunk: Optional[ChunkParamUpdateForm] = None
453
+ youtube: Optional[YoutubeLoaderConfig] = None
454
+ web: Optional[WebConfig] = None
455
+
456
+
457
+ @app.post("/config/update")
458
+ async def update_rag_config(form_data: ConfigUpdateForm, user=Depends(get_admin_user)):
459
+ app.state.config.PDF_EXTRACT_IMAGES = (
460
+ form_data.pdf_extract_images
461
+ if form_data.pdf_extract_images is not None
462
+ else app.state.config.PDF_EXTRACT_IMAGES
463
+ )
464
+
465
+ if form_data.chunk is not None:
466
+ app.state.config.CHUNK_SIZE = form_data.chunk.chunk_size
467
+ app.state.config.CHUNK_OVERLAP = form_data.chunk.chunk_overlap
468
+
469
+ if form_data.youtube is not None:
470
+ app.state.config.YOUTUBE_LOADER_LANGUAGE = form_data.youtube.language
471
+ app.state.YOUTUBE_LOADER_TRANSLATION = form_data.youtube.translation
472
+
473
+ if form_data.web is not None:
474
+ app.state.config.ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION = (
475
+ form_data.web.web_loader_ssl_verification
476
+ )
477
+
478
+ app.state.config.ENABLE_RAG_WEB_SEARCH = form_data.web.search.enabled
479
+ app.state.config.RAG_WEB_SEARCH_ENGINE = form_data.web.search.engine
480
+ app.state.config.SEARXNG_QUERY_URL = form_data.web.search.searxng_query_url
481
+ app.state.config.GOOGLE_PSE_API_KEY = form_data.web.search.google_pse_api_key
482
+ app.state.config.GOOGLE_PSE_ENGINE_ID = (
483
+ form_data.web.search.google_pse_engine_id
484
+ )
485
+ app.state.config.BRAVE_SEARCH_API_KEY = (
486
+ form_data.web.search.brave_search_api_key
487
+ )
488
+ app.state.config.SERPSTACK_API_KEY = form_data.web.search.serpstack_api_key
489
+ app.state.config.SERPSTACK_HTTPS = form_data.web.search.serpstack_https
490
+ app.state.config.SERPER_API_KEY = form_data.web.search.serper_api_key
491
+ app.state.config.SERPLY_API_KEY = form_data.web.search.serply_api_key
492
+ app.state.config.TAVILY_API_KEY = form_data.web.search.tavily_api_key
493
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT = form_data.web.search.result_count
494
+ app.state.config.RAG_WEB_SEARCH_CONCURRENT_REQUESTS = (
495
+ form_data.web.search.concurrent_requests
496
+ )
497
+
498
+ return {
499
+ "status": True,
500
+ "pdf_extract_images": app.state.config.PDF_EXTRACT_IMAGES,
501
+ "chunk": {
502
+ "chunk_size": app.state.config.CHUNK_SIZE,
503
+ "chunk_overlap": app.state.config.CHUNK_OVERLAP,
504
+ },
505
+ "youtube": {
506
+ "language": app.state.config.YOUTUBE_LOADER_LANGUAGE,
507
+ "translation": app.state.YOUTUBE_LOADER_TRANSLATION,
508
+ },
509
+ "web": {
510
+ "ssl_verification": app.state.config.ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION,
511
+ "search": {
512
+ "enabled": app.state.config.ENABLE_RAG_WEB_SEARCH,
513
+ "engine": app.state.config.RAG_WEB_SEARCH_ENGINE,
514
+ "searxng_query_url": app.state.config.SEARXNG_QUERY_URL,
515
+ "google_pse_api_key": app.state.config.GOOGLE_PSE_API_KEY,
516
+ "google_pse_engine_id": app.state.config.GOOGLE_PSE_ENGINE_ID,
517
+ "brave_search_api_key": app.state.config.BRAVE_SEARCH_API_KEY,
518
+ "serpstack_api_key": app.state.config.SERPSTACK_API_KEY,
519
+ "serpstack_https": app.state.config.SERPSTACK_HTTPS,
520
+ "serper_api_key": app.state.config.SERPER_API_KEY,
521
+ "serply_api_key": app.state.config.SERPLY_API_KEY,
522
+ "tavily_api_key": app.state.config.TAVILY_API_KEY,
523
+ "result_count": app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
524
+ "concurrent_requests": app.state.config.RAG_WEB_SEARCH_CONCURRENT_REQUESTS,
525
+ },
526
+ },
527
+ }
528
+
529
+
530
+ @app.get("/template")
531
+ async def get_rag_template(user=Depends(get_current_user)):
532
+ return {
533
+ "status": True,
534
+ "template": app.state.config.RAG_TEMPLATE,
535
+ }
536
+
537
+
538
+ @app.get("/query/settings")
539
+ async def get_query_settings(user=Depends(get_admin_user)):
540
+ return {
541
+ "status": True,
542
+ "template": app.state.config.RAG_TEMPLATE,
543
+ "k": app.state.config.TOP_K,
544
+ "r": app.state.config.RELEVANCE_THRESHOLD,
545
+ "hybrid": app.state.config.ENABLE_RAG_HYBRID_SEARCH,
546
+ }
547
+
548
+
549
+ class QuerySettingsForm(BaseModel):
550
+ k: Optional[int] = None
551
+ r: Optional[float] = None
552
+ template: Optional[str] = None
553
+ hybrid: Optional[bool] = None
554
+
555
+
556
+ @app.post("/query/settings/update")
557
+ async def update_query_settings(
558
+ form_data: QuerySettingsForm, user=Depends(get_admin_user)
559
+ ):
560
+ app.state.config.RAG_TEMPLATE = (
561
+ form_data.template if form_data.template else RAG_TEMPLATE
562
+ )
563
+ app.state.config.TOP_K = form_data.k if form_data.k else 4
564
+ app.state.config.RELEVANCE_THRESHOLD = form_data.r if form_data.r else 0.0
565
+ app.state.config.ENABLE_RAG_HYBRID_SEARCH = (
566
+ form_data.hybrid if form_data.hybrid else False
567
+ )
568
+ return {
569
+ "status": True,
570
+ "template": app.state.config.RAG_TEMPLATE,
571
+ "k": app.state.config.TOP_K,
572
+ "r": app.state.config.RELEVANCE_THRESHOLD,
573
+ "hybrid": app.state.config.ENABLE_RAG_HYBRID_SEARCH,
574
+ }
575
+
576
+
577
+ class QueryDocForm(BaseModel):
578
+ collection_name: str
579
+ query: str
580
+ k: Optional[int] = None
581
+ r: Optional[float] = None
582
+ hybrid: Optional[bool] = None
583
+
584
+
585
+ @app.post("/query/doc")
586
+ def query_doc_handler(
587
+ form_data: QueryDocForm,
588
+ user=Depends(get_current_user),
589
+ ):
590
+ try:
591
+ if app.state.config.ENABLE_RAG_HYBRID_SEARCH:
592
+ return query_doc_with_hybrid_search(
593
+ collection_name=form_data.collection_name,
594
+ query=form_data.query,
595
+ embedding_function=app.state.EMBEDDING_FUNCTION,
596
+ k=form_data.k if form_data.k else app.state.config.TOP_K,
597
+ reranking_function=app.state.sentence_transformer_rf,
598
+ r=(
599
+ form_data.r if form_data.r else app.state.config.RELEVANCE_THRESHOLD
600
+ ),
601
+ )
602
+ else:
603
+ return query_doc(
604
+ collection_name=form_data.collection_name,
605
+ query=form_data.query,
606
+ embedding_function=app.state.EMBEDDING_FUNCTION,
607
+ k=form_data.k if form_data.k else app.state.config.TOP_K,
608
+ )
609
+ except Exception as e:
610
+ log.exception(e)
611
+ raise HTTPException(
612
+ status_code=status.HTTP_400_BAD_REQUEST,
613
+ detail=ERROR_MESSAGES.DEFAULT(e),
614
+ )
615
+
616
+
617
+ class QueryCollectionsForm(BaseModel):
618
+ collection_names: List[str]
619
+ query: str
620
+ k: Optional[int] = None
621
+ r: Optional[float] = None
622
+ hybrid: Optional[bool] = None
623
+
624
+
625
+ @app.post("/query/collection")
626
+ def query_collection_handler(
627
+ form_data: QueryCollectionsForm,
628
+ user=Depends(get_current_user),
629
+ ):
630
+ try:
631
+ if app.state.config.ENABLE_RAG_HYBRID_SEARCH:
632
+ return query_collection_with_hybrid_search(
633
+ collection_names=form_data.collection_names,
634
+ query=form_data.query,
635
+ embedding_function=app.state.EMBEDDING_FUNCTION,
636
+ k=form_data.k if form_data.k else app.state.config.TOP_K,
637
+ reranking_function=app.state.sentence_transformer_rf,
638
+ r=(
639
+ form_data.r if form_data.r else app.state.config.RELEVANCE_THRESHOLD
640
+ ),
641
+ )
642
+ else:
643
+ return query_collection(
644
+ collection_names=form_data.collection_names,
645
+ query=form_data.query,
646
+ embedding_function=app.state.EMBEDDING_FUNCTION,
647
+ k=form_data.k if form_data.k else app.state.config.TOP_K,
648
+ )
649
+
650
+ except Exception as e:
651
+ log.exception(e)
652
+ raise HTTPException(
653
+ status_code=status.HTTP_400_BAD_REQUEST,
654
+ detail=ERROR_MESSAGES.DEFAULT(e),
655
+ )
656
+
657
+
658
+ @app.post("/youtube")
659
+ def store_youtube_video(form_data: UrlForm, user=Depends(get_current_user)):
660
+ try:
661
+ loader = YoutubeLoader.from_youtube_url(
662
+ form_data.url,
663
+ add_video_info=True,
664
+ language=app.state.config.YOUTUBE_LOADER_LANGUAGE,
665
+ translation=app.state.YOUTUBE_LOADER_TRANSLATION,
666
+ )
667
+ data = loader.load()
668
+
669
+ collection_name = form_data.collection_name
670
+ if collection_name == "":
671
+ collection_name = calculate_sha256_string(form_data.url)[:63]
672
+
673
+ store_data_in_vector_db(data, collection_name, overwrite=True)
674
+ return {
675
+ "status": True,
676
+ "collection_name": collection_name,
677
+ "filename": form_data.url,
678
+ }
679
+ except Exception as e:
680
+ log.exception(e)
681
+ raise HTTPException(
682
+ status_code=status.HTTP_400_BAD_REQUEST,
683
+ detail=ERROR_MESSAGES.DEFAULT(e),
684
+ )
685
+
686
+
687
+ @app.post("/web")
688
+ def store_web(form_data: UrlForm, user=Depends(get_current_user)):
689
+ # "https://www.gutenberg.org/files/1727/1727-h/1727-h.htm"
690
+ try:
691
+ loader = get_web_loader(
692
+ form_data.url,
693
+ verify_ssl=app.state.config.ENABLE_RAG_WEB_LOADER_SSL_VERIFICATION,
694
+ )
695
+ data = loader.load()
696
+
697
+ collection_name = form_data.collection_name
698
+ if collection_name == "":
699
+ collection_name = calculate_sha256_string(form_data.url)[:63]
700
+
701
+ store_data_in_vector_db(data, collection_name, overwrite=True)
702
+ return {
703
+ "status": True,
704
+ "collection_name": collection_name,
705
+ "filename": form_data.url,
706
+ }
707
+ except Exception as e:
708
+ log.exception(e)
709
+ raise HTTPException(
710
+ status_code=status.HTTP_400_BAD_REQUEST,
711
+ detail=ERROR_MESSAGES.DEFAULT(e),
712
+ )
713
+
714
+
715
+ def get_web_loader(url: Union[str, Sequence[str]], verify_ssl: bool = True):
716
+ # Check if the URL is valid
717
+ if not validate_url(url):
718
+ raise ValueError(ERROR_MESSAGES.INVALID_URL)
719
+ return SafeWebBaseLoader(
720
+ url,
721
+ verify_ssl=verify_ssl,
722
+ requests_per_second=RAG_WEB_SEARCH_CONCURRENT_REQUESTS,
723
+ continue_on_failure=True,
724
+ )
725
+
726
+
727
+ def validate_url(url: Union[str, Sequence[str]]):
728
+ if isinstance(url, str):
729
+ if isinstance(validators.url(url), validators.ValidationError):
730
+ raise ValueError(ERROR_MESSAGES.INVALID_URL)
731
+ if not ENABLE_RAG_LOCAL_WEB_FETCH:
732
+ # Local web fetch is disabled, filter out any URLs that resolve to private IP addresses
733
+ parsed_url = urllib.parse.urlparse(url)
734
+ # Get IPv4 and IPv6 addresses
735
+ ipv4_addresses, ipv6_addresses = resolve_hostname(parsed_url.hostname)
736
+ # Check if any of the resolved addresses are private
737
+ # This is technically still vulnerable to DNS rebinding attacks, as we don't control WebBaseLoader
738
+ for ip in ipv4_addresses:
739
+ if validators.ipv4(ip, private=True):
740
+ raise ValueError(ERROR_MESSAGES.INVALID_URL)
741
+ for ip in ipv6_addresses:
742
+ if validators.ipv6(ip, private=True):
743
+ raise ValueError(ERROR_MESSAGES.INVALID_URL)
744
+ return True
745
+ elif isinstance(url, Sequence):
746
+ return all(validate_url(u) for u in url)
747
+ else:
748
+ return False
749
+
750
+
751
+ def resolve_hostname(hostname):
752
+ # Get address information
753
+ addr_info = socket.getaddrinfo(hostname, None)
754
+
755
+ # Extract IP addresses from address information
756
+ ipv4_addresses = [info[4][0] for info in addr_info if info[0] == socket.AF_INET]
757
+ ipv6_addresses = [info[4][0] for info in addr_info if info[0] == socket.AF_INET6]
758
+
759
+ return ipv4_addresses, ipv6_addresses
760
+
761
+
762
+ def search_web(engine: str, query: str) -> list[SearchResult]:
763
+ """Search the web using a search engine and return the results as a list of SearchResult objects.
764
+ Will look for a search engine API key in environment variables in the following order:
765
+ - SEARXNG_QUERY_URL
766
+ - GOOGLE_PSE_API_KEY + GOOGLE_PSE_ENGINE_ID
767
+ - BRAVE_SEARCH_API_KEY
768
+ - SERPSTACK_API_KEY
769
+ - SERPER_API_KEY
770
+ - SERPLY_API_KEY
771
+ - TAVILY_API_KEY
772
+ Args:
773
+ query (str): The query to search for
774
+ """
775
+
776
+ # TODO: add playwright to search the web
777
+ if engine == "searxng":
778
+ if app.state.config.SEARXNG_QUERY_URL:
779
+ return search_searxng(
780
+ app.state.config.SEARXNG_QUERY_URL,
781
+ query,
782
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
783
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
784
+ )
785
+ else:
786
+ raise Exception("No SEARXNG_QUERY_URL found in environment variables")
787
+ elif engine == "google_pse":
788
+ if (
789
+ app.state.config.GOOGLE_PSE_API_KEY
790
+ and app.state.config.GOOGLE_PSE_ENGINE_ID
791
+ ):
792
+ return search_google_pse(
793
+ app.state.config.GOOGLE_PSE_API_KEY,
794
+ app.state.config.GOOGLE_PSE_ENGINE_ID,
795
+ query,
796
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
797
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
798
+ )
799
+ else:
800
+ raise Exception(
801
+ "No GOOGLE_PSE_API_KEY or GOOGLE_PSE_ENGINE_ID found in environment variables"
802
+ )
803
+ elif engine == "brave":
804
+ if app.state.config.BRAVE_SEARCH_API_KEY:
805
+ return search_brave(
806
+ app.state.config.BRAVE_SEARCH_API_KEY,
807
+ query,
808
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
809
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
810
+ )
811
+ else:
812
+ raise Exception("No BRAVE_SEARCH_API_KEY found in environment variables")
813
+ elif engine == "serpstack":
814
+ if app.state.config.SERPSTACK_API_KEY:
815
+ return search_serpstack(
816
+ app.state.config.SERPSTACK_API_KEY,
817
+ query,
818
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
819
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
820
+ https_enabled=app.state.config.SERPSTACK_HTTPS,
821
+ )
822
+ else:
823
+ raise Exception("No SERPSTACK_API_KEY found in environment variables")
824
+ elif engine == "serper":
825
+ if app.state.config.SERPER_API_KEY:
826
+ return search_serper(
827
+ app.state.config.SERPER_API_KEY,
828
+ query,
829
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
830
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
831
+ )
832
+ else:
833
+ raise Exception("No SERPER_API_KEY found in environment variables")
834
+ elif engine == "serply":
835
+ if app.state.config.SERPLY_API_KEY:
836
+ return search_serply(
837
+ app.state.config.SERPLY_API_KEY,
838
+ query,
839
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
840
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
841
+ )
842
+ else:
843
+ raise Exception("No SERPLY_API_KEY found in environment variables")
844
+ elif engine == "duckduckgo":
845
+ return search_duckduckgo(
846
+ query,
847
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
848
+ app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
849
+ )
850
+ elif engine == "tavily":
851
+ if app.state.config.TAVILY_API_KEY:
852
+ return search_tavily(
853
+ app.state.config.TAVILY_API_KEY,
854
+ query,
855
+ app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
856
+ )
857
+ else:
858
+ raise Exception("No TAVILY_API_KEY found in environment variables")
859
+ else:
860
+ raise Exception("No search engine API key found in environment variables")
861
+
862
+
863
+ @app.post("/web/search")
864
+ def store_web_search(form_data: SearchForm, user=Depends(get_current_user)):
865
+ try:
866
+ logging.info(
867
+ f"trying to web search with {app.state.config.RAG_WEB_SEARCH_ENGINE, form_data.query}"
868
+ )
869
+ web_results = search_web(
870
+ app.state.config.RAG_WEB_SEARCH_ENGINE, form_data.query
871
+ )
872
+ except Exception as e:
873
+ log.exception(e)
874
+
875
+ print(e)
876
+ raise HTTPException(
877
+ status_code=status.HTTP_400_BAD_REQUEST,
878
+ detail=ERROR_MESSAGES.WEB_SEARCH_ERROR(e),
879
+ )
880
+
881
+ try:
882
+ urls = [result.link for result in web_results]
883
+ loader = get_web_loader(urls)
884
+ data = loader.load()
885
+
886
+ collection_name = form_data.collection_name
887
+ if collection_name == "":
888
+ collection_name = calculate_sha256_string(form_data.query)[:63]
889
+
890
+ store_data_in_vector_db(data, collection_name, overwrite=True)
891
+ return {
892
+ "status": True,
893
+ "collection_name": collection_name,
894
+ "filenames": urls,
895
+ }
896
+ except Exception as e:
897
+ log.exception(e)
898
+ raise HTTPException(
899
+ status_code=status.HTTP_400_BAD_REQUEST,
900
+ detail=ERROR_MESSAGES.DEFAULT(e),
901
+ )
902
+
903
+
904
+ def store_data_in_vector_db(data, collection_name, overwrite: bool = False) -> bool:
905
+
906
+ text_splitter = RecursiveCharacterTextSplitter(
907
+ chunk_size=app.state.config.CHUNK_SIZE,
908
+ chunk_overlap=app.state.config.CHUNK_OVERLAP,
909
+ add_start_index=True,
910
+ )
911
+
912
+ docs = text_splitter.split_documents(data)
913
+
914
+ if len(docs) > 0:
915
+ log.info(f"store_data_in_vector_db {docs}")
916
+ return store_docs_in_vector_db(docs, collection_name, overwrite), None
917
+ else:
918
+ raise ValueError(ERROR_MESSAGES.EMPTY_CONTENT)
919
+
920
+
921
+ def store_text_in_vector_db(
922
+ text, metadata, collection_name, overwrite: bool = False
923
+ ) -> bool:
924
+ text_splitter = RecursiveCharacterTextSplitter(
925
+ chunk_size=app.state.config.CHUNK_SIZE,
926
+ chunk_overlap=app.state.config.CHUNK_OVERLAP,
927
+ add_start_index=True,
928
+ )
929
+ docs = text_splitter.create_documents([text], metadatas=[metadata])
930
+ return store_docs_in_vector_db(docs, collection_name, overwrite)
931
+
932
+
933
+ def store_docs_in_vector_db(docs, collection_name, overwrite: bool = False) -> bool:
934
+ log.info(f"store_docs_in_vector_db {docs} {collection_name}")
935
+
936
+ texts = [doc.page_content for doc in docs]
937
+ metadatas = [doc.metadata for doc in docs]
938
+
939
+ # ChromaDB does not like datetime formats
940
+ # for meta-data so convert them to string.
941
+ for metadata in metadatas:
942
+ for key, value in metadata.items():
943
+ if isinstance(value, datetime):
944
+ metadata[key] = str(value)
945
+
946
+ try:
947
+ if overwrite:
948
+ for collection in CHROMA_CLIENT.list_collections():
949
+ if collection_name == collection.name:
950
+ log.info(f"deleting existing collection {collection_name}")
951
+ CHROMA_CLIENT.delete_collection(name=collection_name)
952
+
953
+ collection = CHROMA_CLIENT.create_collection(name=collection_name)
954
+
955
+ embedding_func = get_embedding_function(
956
+ app.state.config.RAG_EMBEDDING_ENGINE,
957
+ app.state.config.RAG_EMBEDDING_MODEL,
958
+ app.state.sentence_transformer_ef,
959
+ app.state.config.OPENAI_API_KEY,
960
+ app.state.config.OPENAI_API_BASE_URL,
961
+ app.state.config.RAG_EMBEDDING_OPENAI_BATCH_SIZE,
962
+ )
963
+
964
+ embedding_texts = list(map(lambda x: x.replace("\n", " "), texts))
965
+ embeddings = embedding_func(embedding_texts)
966
+
967
+ for batch in create_batches(
968
+ api=CHROMA_CLIENT,
969
+ ids=[str(uuid.uuid4()) for _ in texts],
970
+ metadatas=metadatas,
971
+ embeddings=embeddings,
972
+ documents=texts,
973
+ ):
974
+ collection.add(*batch)
975
+
976
+ return True
977
+ except Exception as e:
978
+ log.exception(e)
979
+ if e.__class__.__name__ == "UniqueConstraintError":
980
+ return True
981
+
982
+ return False
983
+
984
+
985
+ def get_loader(filename: str, file_content_type: str, file_path: str):
986
+ file_ext = filename.split(".")[-1].lower()
987
+ known_type = True
988
+
989
+ known_source_ext = [
990
+ "go",
991
+ "py",
992
+ "java",
993
+ "sh",
994
+ "bat",
995
+ "ps1",
996
+ "cmd",
997
+ "js",
998
+ "ts",
999
+ "css",
1000
+ "cpp",
1001
+ "hpp",
1002
+ "h",
1003
+ "c",
1004
+ "cs",
1005
+ "sql",
1006
+ "log",
1007
+ "ini",
1008
+ "pl",
1009
+ "pm",
1010
+ "r",
1011
+ "dart",
1012
+ "dockerfile",
1013
+ "env",
1014
+ "php",
1015
+ "hs",
1016
+ "hsc",
1017
+ "lua",
1018
+ "nginxconf",
1019
+ "conf",
1020
+ "m",
1021
+ "mm",
1022
+ "plsql",
1023
+ "perl",
1024
+ "rb",
1025
+ "rs",
1026
+ "db2",
1027
+ "scala",
1028
+ "bash",
1029
+ "swift",
1030
+ "vue",
1031
+ "svelte",
1032
+ "msg",
1033
+ ]
1034
+
1035
+ if file_ext == "pdf":
1036
+ loader = PyPDFLoader(
1037
+ file_path, extract_images=app.state.config.PDF_EXTRACT_IMAGES
1038
+ )
1039
+ elif file_ext == "csv":
1040
+ loader = CSVLoader(file_path)
1041
+ elif file_ext == "rst":
1042
+ loader = UnstructuredRSTLoader(file_path, mode="elements")
1043
+ elif file_ext == "xml":
1044
+ loader = UnstructuredXMLLoader(file_path)
1045
+ elif file_ext in ["htm", "html"]:
1046
+ loader = BSHTMLLoader(file_path, open_encoding="unicode_escape")
1047
+ elif file_ext == "md":
1048
+ loader = UnstructuredMarkdownLoader(file_path)
1049
+ elif file_content_type == "application/epub+zip":
1050
+ loader = UnstructuredEPubLoader(file_path)
1051
+ elif (
1052
+ file_content_type
1053
+ == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
1054
+ or file_ext in ["doc", "docx"]
1055
+ ):
1056
+ loader = Docx2txtLoader(file_path)
1057
+ elif file_content_type in [
1058
+ "application/vnd.ms-excel",
1059
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1060
+ ] or file_ext in ["xls", "xlsx"]:
1061
+ loader = UnstructuredExcelLoader(file_path)
1062
+ elif file_content_type in [
1063
+ "application/vnd.ms-powerpoint",
1064
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
1065
+ ] or file_ext in ["ppt", "pptx"]:
1066
+ loader = UnstructuredPowerPointLoader(file_path)
1067
+ elif file_ext == "msg":
1068
+ loader = OutlookMessageLoader(file_path)
1069
+ elif file_ext in known_source_ext or (
1070
+ file_content_type and file_content_type.find("text/") >= 0
1071
+ ):
1072
+ loader = TextLoader(file_path, autodetect_encoding=True)
1073
+ else:
1074
+ loader = TextLoader(file_path, autodetect_encoding=True)
1075
+ known_type = False
1076
+
1077
+ return loader, known_type
1078
+
1079
+
1080
+ @app.post("/doc")
1081
+ def store_doc(
1082
+ collection_name: Optional[str] = Form(None),
1083
+ file: UploadFile = File(...),
1084
+ user=Depends(get_current_user),
1085
+ ):
1086
+ # "https://www.gutenberg.org/files/1727/1727-h/1727-h.htm"
1087
+
1088
+ log.info(f"file.content_type: {file.content_type}")
1089
+ try:
1090
+ unsanitized_filename = file.filename
1091
+ filename = os.path.basename(unsanitized_filename)
1092
+
1093
+ file_path = f"{UPLOAD_DIR}/{filename}"
1094
+
1095
+ contents = file.file.read()
1096
+ with open(file_path, "wb") as f:
1097
+ f.write(contents)
1098
+ f.close()
1099
+
1100
+ f = open(file_path, "rb")
1101
+ if collection_name == None:
1102
+ collection_name = calculate_sha256(f)[:63]
1103
+ f.close()
1104
+
1105
+ loader, known_type = get_loader(filename, file.content_type, file_path)
1106
+ data = loader.load()
1107
+
1108
+ try:
1109
+ result = store_data_in_vector_db(data, collection_name)
1110
+
1111
+ if result:
1112
+ return {
1113
+ "status": True,
1114
+ "collection_name": collection_name,
1115
+ "filename": filename,
1116
+ "known_type": known_type,
1117
+ }
1118
+ except Exception as e:
1119
+ raise HTTPException(
1120
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
1121
+ detail=e,
1122
+ )
1123
+ except Exception as e:
1124
+ log.exception(e)
1125
+ if "No pandoc was found" in str(e):
1126
+ raise HTTPException(
1127
+ status_code=status.HTTP_400_BAD_REQUEST,
1128
+ detail=ERROR_MESSAGES.PANDOC_NOT_INSTALLED,
1129
+ )
1130
+ else:
1131
+ raise HTTPException(
1132
+ status_code=status.HTTP_400_BAD_REQUEST,
1133
+ detail=ERROR_MESSAGES.DEFAULT(e),
1134
+ )
1135
+
1136
+
1137
+ class ProcessDocForm(BaseModel):
1138
+ file_id: str
1139
+ collection_name: Optional[str] = None
1140
+
1141
+
1142
+ @app.post("/process/doc")
1143
+ def process_doc(
1144
+ form_data: ProcessDocForm,
1145
+ user=Depends(get_current_user),
1146
+ ):
1147
+ try:
1148
+ file = Files.get_file_by_id(form_data.file_id)
1149
+ file_path = file.meta.get("path", f"{UPLOAD_DIR}/{file.filename}")
1150
+
1151
+ f = open(file_path, "rb")
1152
+
1153
+ collection_name = form_data.collection_name
1154
+ if collection_name == None:
1155
+ collection_name = calculate_sha256(f)[:63]
1156
+ f.close()
1157
+
1158
+ loader, known_type = get_loader(
1159
+ file.filename, file.meta.get("content_type"), file_path
1160
+ )
1161
+ data = loader.load()
1162
+
1163
+ try:
1164
+ result = store_data_in_vector_db(data, collection_name)
1165
+
1166
+ if result:
1167
+ return {
1168
+ "status": True,
1169
+ "collection_name": collection_name,
1170
+ "known_type": known_type,
1171
+ }
1172
+ except Exception as e:
1173
+ raise HTTPException(
1174
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
1175
+ detail=e,
1176
+ )
1177
+ except Exception as e:
1178
+ log.exception(e)
1179
+ if "No pandoc was found" in str(e):
1180
+ raise HTTPException(
1181
+ status_code=status.HTTP_400_BAD_REQUEST,
1182
+ detail=ERROR_MESSAGES.PANDOC_NOT_INSTALLED,
1183
+ )
1184
+ else:
1185
+ raise HTTPException(
1186
+ status_code=status.HTTP_400_BAD_REQUEST,
1187
+ detail=ERROR_MESSAGES.DEFAULT(e),
1188
+ )
1189
+
1190
+
1191
+ class TextRAGForm(BaseModel):
1192
+ name: str
1193
+ content: str
1194
+ collection_name: Optional[str] = None
1195
+
1196
+
1197
+ @app.post("/text")
1198
+ def store_text(
1199
+ form_data: TextRAGForm,
1200
+ user=Depends(get_current_user),
1201
+ ):
1202
+
1203
+ collection_name = form_data.collection_name
1204
+ if collection_name == None:
1205
+ collection_name = calculate_sha256_string(form_data.content)
1206
+
1207
+ result = store_text_in_vector_db(
1208
+ form_data.content,
1209
+ metadata={"name": form_data.name, "created_by": user.id},
1210
+ collection_name=collection_name,
1211
+ )
1212
+
1213
+ if result:
1214
+ return {"status": True, "collection_name": collection_name}
1215
+ else:
1216
+ raise HTTPException(
1217
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
1218
+ detail=ERROR_MESSAGES.DEFAULT(),
1219
+ )
1220
+
1221
+
1222
+ @app.get("/scan")
1223
+ def scan_docs_dir(user=Depends(get_admin_user)):
1224
+ for path in Path(DOCS_DIR).rglob("./**/*"):
1225
+ try:
1226
+ if path.is_file() and not path.name.startswith("."):
1227
+ tags = extract_folders_after_data_docs(path)
1228
+ filename = path.name
1229
+ file_content_type = mimetypes.guess_type(path)
1230
+
1231
+ f = open(path, "rb")
1232
+ collection_name = calculate_sha256(f)[:63]
1233
+ f.close()
1234
+
1235
+ loader, known_type = get_loader(
1236
+ filename, file_content_type[0], str(path)
1237
+ )
1238
+ data = loader.load()
1239
+
1240
+ try:
1241
+ result = store_data_in_vector_db(data, collection_name)
1242
+
1243
+ if result:
1244
+ sanitized_filename = sanitize_filename(filename)
1245
+ doc = Documents.get_doc_by_name(sanitized_filename)
1246
+
1247
+ if doc == None:
1248
+ doc = Documents.insert_new_doc(
1249
+ user.id,
1250
+ DocumentForm(
1251
+ **{
1252
+ "name": sanitized_filename,
1253
+ "title": filename,
1254
+ "collection_name": collection_name,
1255
+ "filename": filename,
1256
+ "content": (
1257
+ json.dumps(
1258
+ {
1259
+ "tags": list(
1260
+ map(
1261
+ lambda name: {"name": name},
1262
+ tags,
1263
+ )
1264
+ )
1265
+ }
1266
+ )
1267
+ if len(tags)
1268
+ else "{}"
1269
+ ),
1270
+ }
1271
+ ),
1272
+ )
1273
+ except Exception as e:
1274
+ log.exception(e)
1275
+ pass
1276
+
1277
+ except Exception as e:
1278
+ log.exception(e)
1279
+
1280
+ return True
1281
+
1282
+
1283
+ @app.get("/reset/db")
1284
+ def reset_vector_db(user=Depends(get_admin_user)):
1285
+ CHROMA_CLIENT.reset()
1286
+
1287
+
1288
+ @app.get("/reset/uploads")
1289
+ def reset_upload_dir(user=Depends(get_admin_user)) -> bool:
1290
+ folder = f"{UPLOAD_DIR}"
1291
+ try:
1292
+ # Check if the directory exists
1293
+ if os.path.exists(folder):
1294
+ # Iterate over all the files and directories in the specified directory
1295
+ for filename in os.listdir(folder):
1296
+ file_path = os.path.join(folder, filename)
1297
+ try:
1298
+ if os.path.isfile(file_path) or os.path.islink(file_path):
1299
+ os.unlink(file_path) # Remove the file or link
1300
+ elif os.path.isdir(file_path):
1301
+ shutil.rmtree(file_path) # Remove the directory
1302
+ except Exception as e:
1303
+ print(f"Failed to delete {file_path}. Reason: {e}")
1304
+ else:
1305
+ print(f"The directory {folder} does not exist")
1306
+ except Exception as e:
1307
+ print(f"Failed to process the directory {folder}. Reason: {e}")
1308
+
1309
+ return True
1310
+
1311
+
1312
+ @app.get("/reset")
1313
+ def reset(user=Depends(get_admin_user)) -> bool:
1314
+ folder = f"{UPLOAD_DIR}"
1315
+ for filename in os.listdir(folder):
1316
+ file_path = os.path.join(folder, filename)
1317
+ try:
1318
+ if os.path.isfile(file_path) or os.path.islink(file_path):
1319
+ os.unlink(file_path)
1320
+ elif os.path.isdir(file_path):
1321
+ shutil.rmtree(file_path)
1322
+ except Exception as e:
1323
+ log.error("Failed to delete %s. Reason: %s" % (file_path, e))
1324
+
1325
+ try:
1326
+ CHROMA_CLIENT.reset()
1327
+ except Exception as e:
1328
+ log.exception(e)
1329
+
1330
+ return True
1331
+
1332
+
1333
+ class SafeWebBaseLoader(WebBaseLoader):
1334
+ """WebBaseLoader with enhanced error handling for URLs."""
1335
+
1336
+ def lazy_load(self) -> Iterator[Document]:
1337
+ """Lazy load text from the url(s) in web_path with error handling."""
1338
+ for path in self.web_paths:
1339
+ try:
1340
+ soup = self._scrape(path, bs_kwargs=self.bs_kwargs)
1341
+ text = soup.get_text(**self.bs_get_text_kwargs)
1342
+
1343
+ # Build metadata
1344
+ metadata = {"source": path}
1345
+ if title := soup.find("title"):
1346
+ metadata["title"] = title.get_text()
1347
+ if description := soup.find("meta", attrs={"name": "description"}):
1348
+ metadata["description"] = description.get(
1349
+ "content", "No description found."
1350
+ )
1351
+ if html := soup.find("html"):
1352
+ metadata["language"] = html.get("lang", "No language found.")
1353
+
1354
+ yield Document(page_content=text, metadata=metadata)
1355
+ except Exception as e:
1356
+ # Log the error and continue with the next URL
1357
+ log.error(f"Error loading {path}: {e}")
1358
+
1359
+
1360
+ if ENV == "dev":
1361
+
1362
+ @app.get("/ef")
1363
+ async def get_embeddings():
1364
+ return {"result": app.state.EMBEDDING_FUNCTION("hello world")}
1365
+
1366
+ @app.get("/ef/{text}")
1367
+ async def get_embeddings_text(text: str):
1368
+ return {"result": app.state.EMBEDDING_FUNCTION(text)}
backend/apps/rag/search/brave.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from typing import List, Optional
3
+ import requests
4
+
5
+ from apps.rag.search.main import SearchResult, get_filtered_results
6
+ from config import SRC_LOG_LEVELS
7
+
8
+ log = logging.getLogger(__name__)
9
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
10
+
11
+
12
+ def search_brave(
13
+ api_key: str, query: str, count: int, filter_list: Optional[List[str]] = None
14
+ ) -> list[SearchResult]:
15
+ """Search using Brave's Search API and return the results as a list of SearchResult objects.
16
+
17
+ Args:
18
+ api_key (str): A Brave Search API key
19
+ query (str): The query to search for
20
+ """
21
+ url = "https://api.search.brave.com/res/v1/web/search"
22
+ headers = {
23
+ "Accept": "application/json",
24
+ "Accept-Encoding": "gzip",
25
+ "X-Subscription-Token": api_key,
26
+ }
27
+ params = {"q": query, "count": count}
28
+
29
+ response = requests.get(url, headers=headers, params=params)
30
+ response.raise_for_status()
31
+
32
+ json_response = response.json()
33
+ results = json_response.get("web", {}).get("results", [])
34
+ if filter_list:
35
+ results = get_filtered_results(results, filter_list)
36
+
37
+ return [
38
+ SearchResult(
39
+ link=result["url"], title=result.get("title"), snippet=result.get("snippet")
40
+ )
41
+ for result in results[:count]
42
+ ]
backend/apps/rag/search/duckduckgo.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from typing import List, Optional
3
+ from apps.rag.search.main import SearchResult, get_filtered_results
4
+ from duckduckgo_search import DDGS
5
+ from config import SRC_LOG_LEVELS
6
+
7
+ log = logging.getLogger(__name__)
8
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
9
+
10
+
11
+ def search_duckduckgo(
12
+ query: str, count: int, filter_list: Optional[List[str]] = None
13
+ ) -> list[SearchResult]:
14
+ """
15
+ Search using DuckDuckGo's Search API and return the results as a list of SearchResult objects.
16
+ Args:
17
+ query (str): The query to search for
18
+ count (int): The number of results to return
19
+
20
+ Returns:
21
+ List[SearchResult]: A list of search results
22
+ """
23
+ # Use the DDGS context manager to create a DDGS object
24
+ with DDGS() as ddgs:
25
+ # Use the ddgs.text() method to perform the search
26
+ ddgs_gen = ddgs.text(
27
+ query, safesearch="moderate", max_results=count, backend="api"
28
+ )
29
+ # Check if there are search results
30
+ if ddgs_gen:
31
+ # Convert the search results into a list
32
+ search_results = [r for r in ddgs_gen]
33
+
34
+ # Create an empty list to store the SearchResult objects
35
+ results = []
36
+ # Iterate over each search result
37
+ for result in search_results:
38
+ # Create a SearchResult object and append it to the results list
39
+ results.append(
40
+ SearchResult(
41
+ link=result["href"],
42
+ title=result.get("title"),
43
+ snippet=result.get("body"),
44
+ )
45
+ )
46
+ if filter_list:
47
+ results = get_filtered_results(results, filter_list)
48
+ # Return the list of search results
49
+ return results
backend/apps/rag/search/google_pse.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ from typing import List, Optional
4
+ import requests
5
+
6
+ from apps.rag.search.main import SearchResult, get_filtered_results
7
+ from config import SRC_LOG_LEVELS
8
+
9
+ log = logging.getLogger(__name__)
10
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
11
+
12
+
13
+ def search_google_pse(
14
+ api_key: str,
15
+ search_engine_id: str,
16
+ query: str,
17
+ count: int,
18
+ filter_list: Optional[List[str]] = None,
19
+ ) -> list[SearchResult]:
20
+ """Search using Google's Programmable Search Engine API and return the results as a list of SearchResult objects.
21
+
22
+ Args:
23
+ api_key (str): A Programmable Search Engine API key
24
+ search_engine_id (str): A Programmable Search Engine ID
25
+ query (str): The query to search for
26
+ """
27
+ url = "https://www.googleapis.com/customsearch/v1"
28
+
29
+ headers = {"Content-Type": "application/json"}
30
+ params = {
31
+ "cx": search_engine_id,
32
+ "q": query,
33
+ "key": api_key,
34
+ "num": count,
35
+ }
36
+
37
+ response = requests.request("GET", url, headers=headers, params=params)
38
+ response.raise_for_status()
39
+
40
+ json_response = response.json()
41
+ results = json_response.get("items", [])
42
+ if filter_list:
43
+ results = get_filtered_results(results, filter_list)
44
+ return [
45
+ SearchResult(
46
+ link=result["link"],
47
+ title=result.get("title"),
48
+ snippet=result.get("snippet"),
49
+ )
50
+ for result in results
51
+ ]
backend/apps/rag/search/main.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional
2
+ from urllib.parse import urlparse
3
+ from pydantic import BaseModel
4
+
5
+
6
+ def get_filtered_results(results, filter_list):
7
+ if not filter_list:
8
+ return results
9
+ filtered_results = []
10
+ for result in results:
11
+ domain = urlparse(result["url"]).netloc
12
+ if any(domain.endswith(filtered_domain) for filtered_domain in filter_list):
13
+ filtered_results.append(result)
14
+ return filtered_results
15
+
16
+
17
+ class SearchResult(BaseModel):
18
+ link: str
19
+ title: Optional[str]
20
+ snippet: Optional[str]
backend/apps/rag/search/searxng.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import requests
3
+
4
+ from typing import List, Optional
5
+
6
+ from apps.rag.search.main import SearchResult, get_filtered_results
7
+ from config import SRC_LOG_LEVELS
8
+
9
+ log = logging.getLogger(__name__)
10
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
11
+
12
+
13
+ def search_searxng(
14
+ query_url: str,
15
+ query: str,
16
+ count: int,
17
+ filter_list: Optional[List[str]] = None,
18
+ **kwargs,
19
+ ) -> List[SearchResult]:
20
+ """
21
+ Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
22
+
23
+ The function allows passing additional parameters such as language or time_range to tailor the search result.
24
+
25
+ Args:
26
+ query_url (str): The base URL of the SearXNG server.
27
+ query (str): The search term or question to find in the SearXNG database.
28
+ count (int): The maximum number of results to retrieve from the search.
29
+
30
+ Keyword Args:
31
+ language (str): Language filter for the search results; e.g., "en-US". Defaults to an empty string.
32
+ safesearch (int): Safe search filter for safer web results; 0 = off, 1 = moderate, 2 = strict. Defaults to 1 (moderate).
33
+ time_range (str): Time range for filtering results by date; e.g., "2023-04-05..today" or "all-time". Defaults to ''.
34
+ categories: (Optional[List[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
35
+
36
+ Returns:
37
+ List[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
38
+
39
+ Raise:
40
+ requests.exceptions.RequestException: If a request error occurs during the search process.
41
+ """
42
+
43
+ # Default values for optional parameters are provided as empty strings or None when not specified.
44
+ language = kwargs.get("language", "en-US")
45
+ safesearch = kwargs.get("safesearch", "1")
46
+ time_range = kwargs.get("time_range", "")
47
+ categories = "".join(kwargs.get("categories", []))
48
+
49
+ params = {
50
+ "q": query,
51
+ "format": "json",
52
+ "pageno": 1,
53
+ "safesearch": safesearch,
54
+ "language": language,
55
+ "time_range": time_range,
56
+ "categories": categories,
57
+ "theme": "simple",
58
+ "image_proxy": 0,
59
+ }
60
+
61
+ # Legacy query format
62
+ if "<query>" in query_url:
63
+ # Strip all query parameters from the URL
64
+ query_url = query_url.split("?")[0]
65
+
66
+ log.debug(f"searching {query_url}")
67
+
68
+ response = requests.get(
69
+ query_url,
70
+ headers={
71
+ "User-Agent": "Open WebUI (https://github.com/open-webui/open-webui) RAG Bot",
72
+ "Accept": "text/html",
73
+ "Accept-Encoding": "gzip, deflate",
74
+ "Accept-Language": "en-US,en;q=0.5",
75
+ "Connection": "keep-alive",
76
+ },
77
+ params=params,
78
+ )
79
+
80
+ response.raise_for_status() # Raise an exception for HTTP errors.
81
+
82
+ json_response = response.json()
83
+ results = json_response.get("results", [])
84
+ sorted_results = sorted(results, key=lambda x: x.get("score", 0), reverse=True)
85
+ if filter_list:
86
+ sorted_results = get_filtered_results(sorted_results, filter_list)
87
+ return [
88
+ SearchResult(
89
+ link=result["url"], title=result.get("title"), snippet=result.get("content")
90
+ )
91
+ for result in sorted_results[:count]
92
+ ]
backend/apps/rag/search/serper.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ from typing import List, Optional
4
+ import requests
5
+
6
+ from apps.rag.search.main import SearchResult, get_filtered_results
7
+ from config import SRC_LOG_LEVELS
8
+
9
+ log = logging.getLogger(__name__)
10
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
11
+
12
+
13
+ def search_serper(
14
+ api_key: str, query: str, count: int, filter_list: Optional[List[str]] = None
15
+ ) -> list[SearchResult]:
16
+ """Search using serper.dev's API and return the results as a list of SearchResult objects.
17
+
18
+ Args:
19
+ api_key (str): A serper.dev API key
20
+ query (str): The query to search for
21
+ """
22
+ url = "https://google.serper.dev/search"
23
+
24
+ payload = json.dumps({"q": query})
25
+ headers = {"X-API-KEY": api_key, "Content-Type": "application/json"}
26
+
27
+ response = requests.request("POST", url, headers=headers, data=payload)
28
+ response.raise_for_status()
29
+
30
+ json_response = response.json()
31
+ results = sorted(
32
+ json_response.get("organic", []), key=lambda x: x.get("position", 0)
33
+ )
34
+ if filter_list:
35
+ results = get_filtered_results(results, filter_list)
36
+ return [
37
+ SearchResult(
38
+ link=result["link"],
39
+ title=result.get("title"),
40
+ snippet=result.get("description"),
41
+ )
42
+ for result in results[:count]
43
+ ]
backend/apps/rag/search/serply.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ from typing import List, Optional
4
+ import requests
5
+ from urllib.parse import urlencode
6
+
7
+ from apps.rag.search.main import SearchResult, get_filtered_results
8
+ from config import SRC_LOG_LEVELS
9
+
10
+ log = logging.getLogger(__name__)
11
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
12
+
13
+
14
+ def search_serply(
15
+ api_key: str,
16
+ query: str,
17
+ count: int,
18
+ hl: str = "us",
19
+ limit: int = 10,
20
+ device_type: str = "desktop",
21
+ proxy_location: str = "US",
22
+ filter_list: Optional[List[str]] = None,
23
+ ) -> list[SearchResult]:
24
+ """Search using serper.dev's API and return the results as a list of SearchResult objects.
25
+
26
+ Args:
27
+ api_key (str): A serply.io API key
28
+ query (str): The query to search for
29
+ hl (str): Host Language code to display results in (reference https://developers.google.com/custom-search/docs/xml_results?hl=en#wsInterfaceLanguages)
30
+ limit (int): The maximum number of results to return [10-100, defaults to 10]
31
+ """
32
+ log.info("Searching with Serply")
33
+
34
+ url = "https://api.serply.io/v1/search/"
35
+
36
+ query_payload = {
37
+ "q": query,
38
+ "language": "en",
39
+ "num": limit,
40
+ "gl": proxy_location.upper(),
41
+ "hl": hl.lower(),
42
+ }
43
+
44
+ url = f"{url}{urlencode(query_payload)}"
45
+ headers = {
46
+ "X-API-KEY": api_key,
47
+ "X-User-Agent": device_type,
48
+ "User-Agent": "open-webui",
49
+ "X-Proxy-Location": proxy_location,
50
+ }
51
+
52
+ response = requests.request("GET", url, headers=headers)
53
+ response.raise_for_status()
54
+
55
+ json_response = response.json()
56
+ log.info(f"results from serply search: {json_response}")
57
+
58
+ results = sorted(
59
+ json_response.get("results", []), key=lambda x: x.get("realPosition", 0)
60
+ )
61
+ if filter_list:
62
+ results = get_filtered_results(results, filter_list)
63
+ return [
64
+ SearchResult(
65
+ link=result["link"],
66
+ title=result.get("title"),
67
+ snippet=result.get("description"),
68
+ )
69
+ for result in results[:count]
70
+ ]
backend/apps/rag/search/serpstack.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ from typing import List, Optional
4
+ import requests
5
+
6
+ from apps.rag.search.main import SearchResult, get_filtered_results
7
+ from config import SRC_LOG_LEVELS
8
+
9
+ log = logging.getLogger(__name__)
10
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
11
+
12
+
13
+ def search_serpstack(
14
+ api_key: str,
15
+ query: str,
16
+ count: int,
17
+ filter_list: Optional[List[str]] = None,
18
+ https_enabled: bool = True,
19
+ ) -> list[SearchResult]:
20
+ """Search using serpstack.com's and return the results as a list of SearchResult objects.
21
+
22
+ Args:
23
+ api_key (str): A serpstack.com API key
24
+ query (str): The query to search for
25
+ https_enabled (bool): Whether to use HTTPS or HTTP for the API request
26
+ """
27
+ url = f"{'https' if https_enabled else 'http'}://api.serpstack.com/search"
28
+
29
+ headers = {"Content-Type": "application/json"}
30
+ params = {
31
+ "access_key": api_key,
32
+ "query": query,
33
+ }
34
+
35
+ response = requests.request("POST", url, headers=headers, params=params)
36
+ response.raise_for_status()
37
+
38
+ json_response = response.json()
39
+ results = sorted(
40
+ json_response.get("organic_results", []), key=lambda x: x.get("position", 0)
41
+ )
42
+ if filter_list:
43
+ results = get_filtered_results(results, filter_list)
44
+ return [
45
+ SearchResult(
46
+ link=result["url"], title=result.get("title"), snippet=result.get("snippet")
47
+ )
48
+ for result in results[:count]
49
+ ]
backend/apps/rag/search/tavily.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+
3
+ import requests
4
+
5
+ from apps.rag.search.main import SearchResult
6
+ from config import SRC_LOG_LEVELS
7
+
8
+ log = logging.getLogger(__name__)
9
+ log.setLevel(SRC_LOG_LEVELS["RAG"])
10
+
11
+
12
+ def search_tavily(api_key: str, query: str, count: int) -> list[SearchResult]:
13
+ """Search using Tavily's Search API and return the results as a list of SearchResult objects.
14
+
15
+ Args:
16
+ api_key (str): A Tavily Search API key
17
+ query (str): The query to search for
18
+
19
+ Returns:
20
+ List[SearchResult]: A list of search results
21
+ """
22
+ url = "https://api.tavily.com/search"
23
+ data = {"query": query, "api_key": api_key}
24
+
25
+ response = requests.post(url, json=data)
26
+ response.raise_for_status()
27
+
28
+ json_response = response.json()
29
+
30
+ raw_search_results = json_response.get("results", [])
31
+
32
+ return [
33
+ SearchResult(
34
+ link=result["url"],
35
+ title=result.get("title", ""),
36
+ snippet=result.get("content"),
37
+ )
38
+ for result in raw_search_results[:count]
39
+ ]
backend/apps/rag/search/testdata/brave.json ADDED
@@ -0,0 +1,998 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "query": {
3
+ "original": "python",
4
+ "show_strict_warning": false,
5
+ "is_navigational": true,
6
+ "is_news_breaking": false,
7
+ "spellcheck_off": true,
8
+ "country": "us",
9
+ "bad_results": false,
10
+ "should_fallback": false,
11
+ "postal_code": "",
12
+ "city": "",
13
+ "header_country": "",
14
+ "more_results_available": true,
15
+ "state": ""
16
+ },
17
+ "mixed": {
18
+ "type": "mixed",
19
+ "main": [
20
+ {
21
+ "type": "web",
22
+ "index": 0,
23
+ "all": false
24
+ },
25
+ {
26
+ "type": "web",
27
+ "index": 1,
28
+ "all": false
29
+ },
30
+ {
31
+ "type": "news",
32
+ "all": true
33
+ },
34
+ {
35
+ "type": "web",
36
+ "index": 2,
37
+ "all": false
38
+ },
39
+ {
40
+ "type": "videos",
41
+ "all": true
42
+ },
43
+ {
44
+ "type": "web",
45
+ "index": 3,
46
+ "all": false
47
+ },
48
+ {
49
+ "type": "web",
50
+ "index": 4,
51
+ "all": false
52
+ },
53
+ {
54
+ "type": "web",
55
+ "index": 5,
56
+ "all": false
57
+ },
58
+ {
59
+ "type": "web",
60
+ "index": 6,
61
+ "all": false
62
+ },
63
+ {
64
+ "type": "web",
65
+ "index": 7,
66
+ "all": false
67
+ },
68
+ {
69
+ "type": "web",
70
+ "index": 8,
71
+ "all": false
72
+ },
73
+ {
74
+ "type": "web",
75
+ "index": 9,
76
+ "all": false
77
+ },
78
+ {
79
+ "type": "web",
80
+ "index": 10,
81
+ "all": false
82
+ },
83
+ {
84
+ "type": "web",
85
+ "index": 11,
86
+ "all": false
87
+ },
88
+ {
89
+ "type": "web",
90
+ "index": 12,
91
+ "all": false
92
+ },
93
+ {
94
+ "type": "web",
95
+ "index": 13,
96
+ "all": false
97
+ },
98
+ {
99
+ "type": "web",
100
+ "index": 14,
101
+ "all": false
102
+ },
103
+ {
104
+ "type": "web",
105
+ "index": 15,
106
+ "all": false
107
+ },
108
+ {
109
+ "type": "web",
110
+ "index": 16,
111
+ "all": false
112
+ },
113
+ {
114
+ "type": "web",
115
+ "index": 17,
116
+ "all": false
117
+ },
118
+ {
119
+ "type": "web",
120
+ "index": 18,
121
+ "all": false
122
+ },
123
+ {
124
+ "type": "web",
125
+ "index": 19,
126
+ "all": false
127
+ }
128
+ ],
129
+ "top": [],
130
+ "side": []
131
+ },
132
+ "news": {
133
+ "type": "news",
134
+ "results": [
135
+ {
136
+ "title": "Google lays off staff from Flutter, Dart and Python teams weeks before its developer conference | TechCrunch",
137
+ "url": "https://techcrunch.com/2024/05/01/google-lays-off-staff-from-flutter-dart-python-weeks-before-its-developer-conference/",
138
+ "is_source_local": false,
139
+ "is_source_both": false,
140
+ "description": "Google told TechCrunch that Flutter will have new updates to share at I/O this year.",
141
+ "page_age": "2024-05-02T17:40:05",
142
+ "family_friendly": true,
143
+ "meta_url": {
144
+ "scheme": "https",
145
+ "netloc": "techcrunch.com",
146
+ "hostname": "techcrunch.com",
147
+ "favicon": "https://imgs.search.brave.com/N6VSEVahheQOb7lqfb47dhUOB4XD-6sfQOP94sCe3Oo/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvZGI5Njk0Yzlk/YWM3ZWMwZjg1MTM1/NmIyMWEyNzBjZDZj/ZDQyNmFlNGU0NDRi/MDgyYjQwOGU0Y2Qy/ZWMwNWQ2ZC90ZWNo/Y3J1bmNoLmNvbS8",
148
+ "path": "› 2024 › 05 › 01 › google-lays-off-staff-from-flutter-dart-python-weeks-before-its-developer-conference"
149
+ },
150
+ "breaking": false,
151
+ "thumbnail": {
152
+ "src": "https://imgs.search.brave.com/gCI5UG8muOEOZDAx9vpu6L6r6R00mD7jOF08-biFoyQ/rs:fit:200:200:1/g:ce/aHR0cHM6Ly90ZWNo/Y3J1bmNoLmNvbS93/cC1jb250ZW50L3Vw/bG9hZHMvMjAxOC8x/MS9HZXR0eUltYWdl/cy0xMDAyNDg0NzQ2/LmpwZz9yZXNpemU9/MTIwMCw4MDA"
153
+ },
154
+ "age": "3 days ago",
155
+ "extra_snippets": [
156
+ "Ahead of Google’s annual I/O developer conference in May, the tech giant has laid off staff across key teams like Flutter, Dart, Python and others, according to reports from affected employees shared on social media. Google confirmed the layoffs to TechCrunch, but not the specific teams, roles or how many people were let go.",
157
+ "In a separate post on Reddit, another commenter noted the Python team affected by the layoffs were those who managed the internal Python runtimes and toolchains and worked with OSS Python. Included in this group were “multiple current and former core devs and steering council members,” they said.",
158
+ "Meanwhile, others shared on Y Combinator’s Hacker News, where a Python team member detailed their specific duties on the technical front and noted that, for years, much of the work was done with fewer than 10 people. Another Hacker News commenter said their early years on the Python team were spent paying down internal technical debt accumulated from not having a strong Python strategy.",
159
+ "CNBC reports that a total of 200 people were let go across Google’s “Core” teams, which included those working on Python, app platforms, and other engineering roles. Some jobs were being shifted to India and Mexico, it said, citing internal documents."
160
+ ]
161
+ }
162
+ ],
163
+ "mutated_by_goggles": false
164
+ },
165
+ "type": "search",
166
+ "videos": {
167
+ "type": "videos",
168
+ "results": [
169
+ {
170
+ "type": "video_result",
171
+ "url": "https://www.youtube.com/watch?v=b093aqAZiPU",
172
+ "title": "👩‍💻 Python for Beginners Tutorial - YouTube",
173
+ "description": "In this step-by-step Python for beginner's tutorial, learn how you can get started programming in Python. In this video, I assume that you are completely new...",
174
+ "age": "March 25, 2021",
175
+ "page_age": "2021-03-25T10:00:08",
176
+ "video": {},
177
+ "meta_url": {
178
+ "scheme": "https",
179
+ "netloc": "youtube.com",
180
+ "hostname": "www.youtube.com",
181
+ "favicon": "https://imgs.search.brave.com/Ux4Hee4evZhvjuTKwtapBycOGjGDci2Gvn2pbSzvbC0/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTkyZTZiMWU3/YzU3Nzc5YjExYzUy/N2VhZTIxOWNlYjM5/ZGVjN2MyZDY4Nzdh/ZDYzMTYxNmI5N2Rk/Y2Q3N2FkNy93d3cu/eW91dHViZS5jb20v",
182
+ "path": "› watch"
183
+ },
184
+ "thumbnail": {
185
+ "src": "https://imgs.search.brave.com/tZI4Do4_EYcTCsD_MvE3Jx8FzjIXwIJ5ZuKhwiWTyZs/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9pLnl0/aW1nLmNvbS92aS9i/MDkzYXFBWmlQVS9t/YXhyZXNkZWZhdWx0/LmpwZw"
186
+ }
187
+ },
188
+ {
189
+ "type": "video_result",
190
+ "url": "https://www.youtube.com/watch?v=rfscVS0vtbw",
191
+ "title": "Learn Python - Full Course for Beginners [Tutorial] - YouTube",
192
+ "description": "This course will give you a full introduction into all of the core concepts in python. Follow along with the videos and you'll be a python programmer in no t...",
193
+ "age": "July 11, 2018",
194
+ "page_age": "2018-07-11T18:00:42",
195
+ "video": {},
196
+ "meta_url": {
197
+ "scheme": "https",
198
+ "netloc": "youtube.com",
199
+ "hostname": "www.youtube.com",
200
+ "favicon": "https://imgs.search.brave.com/Ux4Hee4evZhvjuTKwtapBycOGjGDci2Gvn2pbSzvbC0/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTkyZTZiMWU3/YzU3Nzc5YjExYzUy/N2VhZTIxOWNlYjM5/ZGVjN2MyZDY4Nzdh/ZDYzMTYxNmI5N2Rk/Y2Q3N2FkNy93d3cu/eW91dHViZS5jb20v",
201
+ "path": "› watch"
202
+ },
203
+ "thumbnail": {
204
+ "src": "https://imgs.search.brave.com/65zkx_kPU_zJb-4nmvvY-q5-ZZwzceChz-N00V8cqvk/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9pLnl0/aW1nLmNvbS92aS9y/ZnNjVlMwdnRidy9t/YXhyZXNkZWZhdWx0/LmpwZw"
205
+ }
206
+ },
207
+ {
208
+ "type": "video_result",
209
+ "url": "https://www.youtube.com/watch?v=_uQrJ0TkZlc",
210
+ "title": "Python Tutorial - Python Full Course for Beginners - YouTube",
211
+ "description": "Become a Python pro! 🚀 This comprehensive tutorial takes you from beginner to hero, covering the basics, machine learning, and web development projects.🚀 W...",
212
+ "age": "February 18, 2019",
213
+ "page_age": "2019-02-18T15:00:08",
214
+ "video": {},
215
+ "meta_url": {
216
+ "scheme": "https",
217
+ "netloc": "youtube.com",
218
+ "hostname": "www.youtube.com",
219
+ "favicon": "https://imgs.search.brave.com/Ux4Hee4evZhvjuTKwtapBycOGjGDci2Gvn2pbSzvbC0/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTkyZTZiMWU3/YzU3Nzc5YjExYzUy/N2VhZTIxOWNlYjM5/ZGVjN2MyZDY4Nzdh/ZDYzMTYxNmI5N2Rk/Y2Q3N2FkNy93d3cu/eW91dHViZS5jb20v",
220
+ "path": "› watch"
221
+ },
222
+ "thumbnail": {
223
+ "src": "https://imgs.search.brave.com/Djiv1pXLq1ClqBSE_86jQnEYR8bW8UJP6Cs7LrgyQzQ/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9pLnl0/aW1nLmNvbS92aS9f/dVFySjBUa1psYy9t/YXhyZXNkZWZhdWx0/LmpwZw"
224
+ }
225
+ },
226
+ {
227
+ "type": "video_result",
228
+ "url": "https://www.youtube.com/watch?v=wRKgzC-MhIc",
229
+ "title": "[] and {} vs list() and dict(), which is better?",
230
+ "description": "Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.",
231
+ "video": {},
232
+ "meta_url": {
233
+ "scheme": "https",
234
+ "netloc": "youtube.com",
235
+ "hostname": "www.youtube.com",
236
+ "favicon": "https://imgs.search.brave.com/Ux4Hee4evZhvjuTKwtapBycOGjGDci2Gvn2pbSzvbC0/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTkyZTZiMWU3/YzU3Nzc5YjExYzUy/N2VhZTIxOWNlYjM5/ZGVjN2MyZDY4Nzdh/ZDYzMTYxNmI5N2Rk/Y2Q3N2FkNy93d3cu/eW91dHViZS5jb20v",
237
+ "path": "› watch"
238
+ },
239
+ "thumbnail": {
240
+ "src": "https://imgs.search.brave.com/Hw9ep2Pio13X1VZjRw_h9R2VH_XvZFOuGlQJVnVkeq0/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9pLnl0/aW1nLmNvbS92aS93/UktnekMtTWhJYy9o/cWRlZmF1bHQuanBn"
241
+ }
242
+ },
243
+ {
244
+ "type": "video_result",
245
+ "url": "https://www.youtube.com/watch?v=LWdsF79H1Pg",
246
+ "title": "print() vs. return in Python Functions - YouTube",
247
+ "description": "In this video, you will learn the differences between the return statement and the print function when they are used inside Python functions. We will see an ...",
248
+ "age": "June 11, 2022",
249
+ "page_age": "2022-06-11T21:33:26",
250
+ "video": {},
251
+ "meta_url": {
252
+ "scheme": "https",
253
+ "netloc": "youtube.com",
254
+ "hostname": "www.youtube.com",
255
+ "favicon": "https://imgs.search.brave.com/Ux4Hee4evZhvjuTKwtapBycOGjGDci2Gvn2pbSzvbC0/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTkyZTZiMWU3/YzU3Nzc5YjExYzUy/N2VhZTIxOWNlYjM5/ZGVjN2MyZDY4Nzdh/ZDYzMTYxNmI5N2Rk/Y2Q3N2FkNy93d3cu/eW91dHViZS5jb20v",
256
+ "path": "› watch"
257
+ },
258
+ "thumbnail": {
259
+ "src": "https://imgs.search.brave.com/ebglnr5_jwHHpvon3WU-5hzt0eHdTZSVGg3Ts6R38xY/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9pLnl0/aW1nLmNvbS92aS9M/V2RzRjc5SDFQZy9t/YXhyZXNkZWZhdWx0/LmpwZw"
260
+ }
261
+ },
262
+ {
263
+ "type": "video_result",
264
+ "url": "https://www.youtube.com/watch?v=AovxLr8jUH4",
265
+ "title": "Python Tutorial for Beginners 5 - Python print() and input() Function ...",
266
+ "description": "In this Video I am going to show How to use print() Function and input() Function in Python. In python The print() function is used to print the specified ...",
267
+ "age": "August 28, 2018",
268
+ "page_age": "2018-08-28T20:11:09",
269
+ "video": {},
270
+ "meta_url": {
271
+ "scheme": "https",
272
+ "netloc": "youtube.com",
273
+ "hostname": "www.youtube.com",
274
+ "favicon": "https://imgs.search.brave.com/Ux4Hee4evZhvjuTKwtapBycOGjGDci2Gvn2pbSzvbC0/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTkyZTZiMWU3/YzU3Nzc5YjExYzUy/N2VhZTIxOWNlYjM5/ZGVjN2MyZDY4Nzdh/ZDYzMTYxNmI5N2Rk/Y2Q3N2FkNy93d3cu/eW91dHViZS5jb20v",
275
+ "path": "› watch"
276
+ },
277
+ "thumbnail": {
278
+ "src": "https://imgs.search.brave.com/nCoLEcWkKtiecprWbS6nufwGCaSbPH7o0-sMeIkFmjI/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9pLnl0/aW1nLmNvbS92aS9B/b3Z4THI4alVINC9o/cWRlZmF1bHQuanBn"
279
+ }
280
+ }
281
+ ],
282
+ "mutated_by_goggles": false
283
+ },
284
+ "web": {
285
+ "type": "search",
286
+ "results": [
287
+ {
288
+ "title": "Welcome to Python.org",
289
+ "url": "https://www.python.org",
290
+ "is_source_local": false,
291
+ "is_source_both": false,
292
+ "description": "The official home of the <strong>Python</strong> Programming Language",
293
+ "page_age": "2023-09-09T15:55:05",
294
+ "profile": {
295
+ "name": "Python",
296
+ "url": "https://www.python.org",
297
+ "long_name": "python.org",
298
+ "img": "https://imgs.search.brave.com/vBaRH-v6oPS4csO4cdvuKhZ7-xDVvydin3oe3zXYxAI/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvNTJjMzZjNDBj/MmIzODgwMGUyOTRj/Y2E5MjM3YjRkYTZj/YWI1Yzk1NTlmYTgw/ZDBjNzM0MGMxZjQz/YWFjNTczYy93d3cu/cHl0aG9uLm9yZy8"
299
+ },
300
+ "language": "en",
301
+ "family_friendly": true,
302
+ "type": "search_result",
303
+ "subtype": "generic",
304
+ "meta_url": {
305
+ "scheme": "https",
306
+ "netloc": "python.org",
307
+ "hostname": "www.python.org",
308
+ "favicon": "https://imgs.search.brave.com/vBaRH-v6oPS4csO4cdvuKhZ7-xDVvydin3oe3zXYxAI/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvNTJjMzZjNDBj/MmIzODgwMGUyOTRj/Y2E5MjM3YjRkYTZj/YWI1Yzk1NTlmYTgw/ZDBjNzM0MGMxZjQz/YWFjNTczYy93d3cu/cHl0aG9uLm9yZy8",
309
+ "path": ""
310
+ },
311
+ "thumbnail": {
312
+ "src": "https://imgs.search.brave.com/GGfNfe5rxJ8QWEoxXniSLc0-POLU3qPyTIpuqPdbmXk/rs:fit:200:200:1/g:ce/aHR0cHM6Ly93d3cu/cHl0aG9uLm9yZy9z/dGF0aWMvb3Blbmdy/YXBoLWljb24tMjAw/eDIwMC5wbmc",
313
+ "original": "https://www.python.org/static/opengraph-icon-200x200.png",
314
+ "logo": false
315
+ },
316
+ "age": "September 9, 2023",
317
+ "cluster_type": "generic",
318
+ "cluster": [
319
+ {
320
+ "title": "Downloads",
321
+ "url": "https://www.python.org/downloads/",
322
+ "is_source_local": false,
323
+ "is_source_both": false,
324
+ "description": "The official home of the <strong>Python</strong> Programming Language",
325
+ "family_friendly": true
326
+ },
327
+ {
328
+ "title": "Macos",
329
+ "url": "https://www.python.org/downloads/macos/",
330
+ "is_source_local": false,
331
+ "is_source_both": false,
332
+ "description": "The official home of the <strong>Python</strong> Programming Language",
333
+ "family_friendly": true
334
+ },
335
+ {
336
+ "title": "Windows",
337
+ "url": "https://www.python.org/downloads/windows/",
338
+ "is_source_local": false,
339
+ "is_source_both": false,
340
+ "description": "The official home of the <strong>Python</strong> Programming Language",
341
+ "family_friendly": true
342
+ },
343
+ {
344
+ "title": "Getting Started",
345
+ "url": "https://www.python.org/about/gettingstarted/",
346
+ "is_source_local": false,
347
+ "is_source_both": false,
348
+ "description": "The official home of the <strong>Python</strong> Programming Language",
349
+ "family_friendly": true
350
+ }
351
+ ],
352
+ "extra_snippets": [
353
+ "Calculations are simple with Python, and expression syntax is straightforward: the operators +, -, * and / work as expected; parentheses () can be used for grouping. More about simple math functions in Python 3.",
354
+ "The core of extensible programming is defining functions. Python allows mandatory and optional arguments, keyword arguments, and even arbitrary argument lists. More about defining functions in Python 3",
355
+ "Lists (known as arrays in other languages) are one of the compound data types that Python understands. Lists can be indexed, sliced and manipulated with other built-in functions. More about lists in Python 3",
356
+ "# Python 3: Simple output (with Unicode) >>> print(\"Hello, I'm Python!\") Hello, I'm Python! # Input, assignment >>> name = input('What is your name?\\n') >>> print('Hi, %s.' % name) What is your name? Python Hi, Python."
357
+ ]
358
+ },
359
+ {
360
+ "title": "Python (programming language) - Wikipedia",
361
+ "url": "https://en.wikipedia.org/wiki/Python_(programming_language)",
362
+ "is_source_local": false,
363
+ "is_source_both": false,
364
+ "description": "<strong>Python</strong> is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. <strong>Python</strong> is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), ...",
365
+ "page_age": "2024-05-01T12:54:03",
366
+ "profile": {
367
+ "name": "Wikipedia",
368
+ "url": "https://en.wikipedia.org/wiki/Python_(programming_language)",
369
+ "long_name": "en.wikipedia.org",
370
+ "img": "https://imgs.search.brave.com/0kxnVOiqv-faZvOJc7zpym4Zin1CTs1f1svfNZSzmfU/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvNjQwNGZhZWY0/ZTQ1YWUzYzQ3MDUw/MmMzMGY3NTQ0ZjNj/NDUwMDk5ZTI3MWRk/NWYyNTM4N2UwOTE0/NTI3ZDQzNy9lbi53/aWtpcGVkaWEub3Jn/Lw"
371
+ },
372
+ "language": "en",
373
+ "family_friendly": true,
374
+ "type": "search_result",
375
+ "subtype": "generic",
376
+ "meta_url": {
377
+ "scheme": "https",
378
+ "netloc": "en.wikipedia.org",
379
+ "hostname": "en.wikipedia.org",
380
+ "favicon": "https://imgs.search.brave.com/0kxnVOiqv-faZvOJc7zpym4Zin1CTs1f1svfNZSzmfU/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvNjQwNGZhZWY0/ZTQ1YWUzYzQ3MDUw/MmMzMGY3NTQ0ZjNj/NDUwMDk5ZTI3MWRk/NWYyNTM4N2UwOTE0/NTI3ZDQzNy9lbi53/aWtpcGVkaWEub3Jn/Lw",
381
+ "path": "› wiki › Python_(programming_language)"
382
+ },
383
+ "age": "4 days ago",
384
+ "extra_snippets": [
385
+ "Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming. It is often described as a \"batteries included\" language due to its comprehensive standard library.",
386
+ "Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language and first released it in 1991 as Python 0.9.0. Python 2.0 was released in 2000. Python 3.0, released in 2008, was a major revision not completely backward-compatible with earlier versions. Python 2.7.18, released in 2020, was the last release of Python 2.",
387
+ "Python was invented in the late 1980s by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands as a successor to the ABC programming language, which was inspired by SETL, capable of exception handling and interfacing with the Amoeba operating system.",
388
+ "Python consistently ranks as one of the most popular programming languages, and has gained widespread use in the machine learning community."
389
+ ]
390
+ },
391
+ {
392
+ "title": "Python Tutorial",
393
+ "url": "https://www.w3schools.com/python/",
394
+ "is_source_local": false,
395
+ "is_source_both": false,
396
+ "description": "W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, <strong>Python</strong>, SQL, Java, and many, many more.",
397
+ "page_age": "2017-12-07T00:00:00",
398
+ "profile": {
399
+ "name": "W3Schools",
400
+ "url": "https://www.w3schools.com/python/",
401
+ "long_name": "w3schools.com",
402
+ "img": "https://imgs.search.brave.com/JwO5r7z3HTBkU29vgNH_4rrSWLf2M4-8FMWNvbxrKX8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjVlMGVkZDVj/ZGMyZWRmMzAwODRi/ZDAwZGE4NWI3NmU4/MjRhNjEzOGFhZWY3/ZGViMjY1OWY2ZDYw/YTZiOGUyZS93d3cu/dzNzY2hvb2xzLmNv/bS8"
403
+ },
404
+ "language": "en",
405
+ "family_friendly": true,
406
+ "type": "search_result",
407
+ "subtype": "generic",
408
+ "meta_url": {
409
+ "scheme": "https",
410
+ "netloc": "w3schools.com",
411
+ "hostname": "www.w3schools.com",
412
+ "favicon": "https://imgs.search.brave.com/JwO5r7z3HTBkU29vgNH_4rrSWLf2M4-8FMWNvbxrKX8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjVlMGVkZDVj/ZGMyZWRmMzAwODRi/ZDAwZGE4NWI3NmU4/MjRhNjEzOGFhZWY3/ZGViMjY1OWY2ZDYw/YTZiOGUyZS93d3cu/dzNzY2hvb2xzLmNv/bS8",
413
+ "path": "› python"
414
+ },
415
+ "thumbnail": {
416
+ "src": "https://imgs.search.brave.com/EMfp8dodbJehmj0yCJh8317RHuaumsddnHI4bujvFcg/rs:fit:200:200:1/g:ce/aHR0cHM6Ly93d3cu/dzNzY2hvb2xzLmNv/bS9pbWFnZXMvdzNz/Y2hvb2xzX2xvZ29f/NDM2XzIucG5n",
417
+ "original": "https://www.w3schools.com/images/w3schools_logo_436_2.png",
418
+ "logo": true
419
+ },
420
+ "age": "December 7, 2017",
421
+ "extra_snippets": [
422
+ "Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.",
423
+ "HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE",
424
+ "Python Variables Variable Names Assign Multiple Values Output Variables Global Variables Variable Exercises Python Data Types Python Numbers Python Casting Python Strings",
425
+ "Python Strings Slicing Strings Modify Strings Concatenate Strings Format Strings Escape Characters String Methods String Exercises Python Booleans Python Operators Python Lists"
426
+ ]
427
+ },
428
+ {
429
+ "title": "Online Python - IDE, Editor, Compiler, Interpreter",
430
+ "url": "https://www.online-python.com/",
431
+ "is_source_local": false,
432
+ "is_source_both": false,
433
+ "description": "Build and Run your <strong>Python</strong> code instantly. Online-<strong>Python</strong> is a quick and easy tool that helps you to build, compile, test your <strong>python</strong> programs.",
434
+ "profile": {
435
+ "name": "Online-python",
436
+ "url": "https://www.online-python.com/",
437
+ "long_name": "online-python.com",
438
+ "img": "https://imgs.search.brave.com/kfaEvapwHxSsRObO52-I-otYFPHpG1h7UXJyUqDM2Ec/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvZGYxODdjNWQ0/NjZjZTNiMjk5NDY1/MWI5MTgyYjU3Y2Q3/MTI3NGM5MjUzY2Fi/OGQ3MTQ4MmIxMTQx/ZTcxNWFhMC93d3cu/b25saW5lLXB5dGhv/bi5jb20v"
439
+ },
440
+ "language": "en",
441
+ "family_friendly": true,
442
+ "type": "search_result",
443
+ "subtype": "generic",
444
+ "meta_url": {
445
+ "scheme": "https",
446
+ "netloc": "online-python.com",
447
+ "hostname": "www.online-python.com",
448
+ "favicon": "https://imgs.search.brave.com/kfaEvapwHxSsRObO52-I-otYFPHpG1h7UXJyUqDM2Ec/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvZGYxODdjNWQ0/NjZjZTNiMjk5NDY1/MWI5MTgyYjU3Y2Q3/MTI3NGM5MjUzY2Fi/OGQ3MTQ4MmIxMTQx/ZTcxNWFhMC93d3cu/b25saW5lLXB5dGhv/bi5jb20v",
449
+ "path": ""
450
+ },
451
+ "extra_snippets": [
452
+ "Build, run, and share Python code online for free with the help of online-integrated python's development environment (IDE). It is one of the most efficient, dependable, and potent online compilers for the Python programming language. It is not necessary for you to bother about establishing a Python environment in your local.",
453
+ "It is one of the most efficient, dependable, and potent online compilers for the Python programming language. It is not necessary for you to bother about establishing a Python environment in your local. Now You can immediately execute the Python code in the web browser of your choice.",
454
+ "It is not necessary for you to bother about establishing a Python environment in your local. Now You can immediately execute the Python code in the web browser of your choice. Using this Python editor is simple and quick to get up and running with. Simply type in the programme, and then press the RUN button!",
455
+ "Now You can immediately execute the Python code in the web browser of your choice. Using this Python editor is simple and quick to get up and running with. Simply type in the programme, and then press the RUN button! The code can be saved online by choosing the SHARE option, which also gives you the ability to access your code from any location providing you have internet access."
456
+ ]
457
+ },
458
+ {
459
+ "title": "Python · GitHub",
460
+ "url": "https://github.com/python",
461
+ "is_source_local": false,
462
+ "is_source_both": false,
463
+ "description": "Repositories related to the <strong>Python</strong> Programming language - <strong>Python</strong>",
464
+ "page_age": "2023-03-06T00:00:00",
465
+ "profile": {
466
+ "name": "GitHub",
467
+ "url": "https://github.com/python",
468
+ "long_name": "github.com",
469
+ "img": "https://imgs.search.brave.com/v8685zI4XInM0zxlNI2s7oE_2Sb-EL7lAy81WXbkQD8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYWQyNWM1NjA5/ZjZmZjNlYzI2MDNk/N2VkNmJhYjE2MzZl/MDY5ZTMxMDUzZmY1/NmU3NWIzNWVmMjk0/NTBjMjJjZi9naXRo/dWIuY29tLw"
470
+ },
471
+ "language": "en",
472
+ "family_friendly": true,
473
+ "type": "search_result",
474
+ "subtype": "generic",
475
+ "meta_url": {
476
+ "scheme": "https",
477
+ "netloc": "github.com",
478
+ "hostname": "github.com",
479
+ "favicon": "https://imgs.search.brave.com/v8685zI4XInM0zxlNI2s7oE_2Sb-EL7lAy81WXbkQD8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYWQyNWM1NjA5/ZjZmZjNlYzI2MDNk/N2VkNmJhYjE2MzZl/MDY5ZTMxMDUzZmY1/NmU3NWIzNWVmMjk0/NTBjMjJjZi9naXRo/dWIuY29tLw",
480
+ "path": "› python"
481
+ },
482
+ "thumbnail": {
483
+ "src": "https://imgs.search.brave.com/POoaRfu_7gfp-D_O3qMNJrwDqJNbiDu1HuBpNJ_MpVQ/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9hdmF0/YXJzLmdpdGh1YnVz/ZXJjb250ZW50LmNv/bS91LzE1MjU5ODE_/cz0yMDAmYW1wO3Y9/NA",
484
+ "original": "https://avatars.githubusercontent.com/u/1525981?s=200&amp;v=4",
485
+ "logo": false
486
+ },
487
+ "age": "March 6, 2023",
488
+ "extra_snippets": ["Configuration for Python planets (e.g. http://planetpython.org)"]
489
+ },
490
+ {
491
+ "title": "Online Python Compiler (Interpreter)",
492
+ "url": "https://www.programiz.com/python-programming/online-compiler/",
493
+ "is_source_local": false,
494
+ "is_source_both": false,
495
+ "description": "Write and run <strong>Python</strong> code using our online compiler (interpreter). You can use <strong>Python</strong> Shell like IDLE, and take inputs from the user in our <strong>Python</strong> compiler.",
496
+ "page_age": "2020-06-02T00:00:00",
497
+ "profile": {
498
+ "name": "Programiz",
499
+ "url": "https://www.programiz.com/python-programming/online-compiler/",
500
+ "long_name": "programiz.com",
501
+ "img": "https://imgs.search.brave.com/ozj4JFayZ3Fs5c9eTp7M5g12azQ_Hblgu4dpTuHRz6U/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvMGJlN2U1YjVi/Y2M3ZDU5OGMwMWNi/M2Q3YjhjOTM1ZTFk/Y2NkZjE4NGQwOGIx/MTQ4NjI2YmNhODVj/MzFkMmJhYy93d3cu/cHJvZ3JhbWl6LmNv/bS8"
502
+ },
503
+ "language": "en",
504
+ "family_friendly": true,
505
+ "type": "search_result",
506
+ "subtype": "generic",
507
+ "meta_url": {
508
+ "scheme": "https",
509
+ "netloc": "programiz.com",
510
+ "hostname": "www.programiz.com",
511
+ "favicon": "https://imgs.search.brave.com/ozj4JFayZ3Fs5c9eTp7M5g12azQ_Hblgu4dpTuHRz6U/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvMGJlN2U1YjVi/Y2M3ZDU5OGMwMWNi/M2Q3YjhjOTM1ZTFk/Y2NkZjE4NGQwOGIx/MTQ4NjI2YmNhODVj/MzFkMmJhYy93d3cu/cHJvZ3JhbWl6LmNv/bS8",
512
+ "path": "› python-programming › online-compiler"
513
+ },
514
+ "age": "June 2, 2020",
515
+ "extra_snippets": [
516
+ "Python Online Compiler Online R Compiler SQL Online Editor Online HTML/CSS Editor Online Java Compiler C Online Compiler C++ Online Compiler C# Online Compiler JavaScript Online Compiler Online GoLang Compiler Online PHP Compiler Online Swift Compiler Online Rust Compiler",
517
+ "# Online Python compiler (interpreter) to run Python online. # Write Python 3 code in this online editor and run it. print(\"Try programiz.pro\")"
518
+ ]
519
+ },
520
+ {
521
+ "title": "Python Developer",
522
+ "url": "https://twitter.com/Python_Dv/status/1786763460992544791",
523
+ "is_source_local": false,
524
+ "is_source_both": false,
525
+ "description": "<strong>Python</strong> Developer",
526
+ "page_age": "2024-05-04T14:30:03",
527
+ "profile": {
528
+ "name": "X",
529
+ "url": "https://twitter.com/Python_Dv/status/1786763460992544791",
530
+ "long_name": "twitter.com",
531
+ "img": "https://imgs.search.brave.com/Zq483bGX0GnSgym-1P7iyOyEDX3PkDZSNT8m56F862A/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvN2MxOTUxNzhj/OTY1ZTQ3N2I0MjJk/MTY5NGM0MTRlYWVi/MjU1YWE2NDUwYmQ2/YTA2MDFhMDlkZDEx/NTAzZGNiNi90d2l0/dGVyLmNvbS8"
532
+ },
533
+ "language": "en",
534
+ "family_friendly": true,
535
+ "type": "search_result",
536
+ "subtype": "generic",
537
+ "meta_url": {
538
+ "scheme": "https",
539
+ "netloc": "twitter.com",
540
+ "hostname": "twitter.com",
541
+ "favicon": "https://imgs.search.brave.com/Zq483bGX0GnSgym-1P7iyOyEDX3PkDZSNT8m56F862A/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvN2MxOTUxNzhj/OTY1ZTQ3N2I0MjJk/MTY5NGM0MTRlYWVi/MjU1YWE2NDUwYmQ2/YTA2MDFhMDlkZDEx/NTAzZGNiNi90d2l0/dGVyLmNvbS8",
542
+ "path": "› Python_Dv › status › 1786763460992544791"
543
+ },
544
+ "age": "20 hours ago"
545
+ },
546
+ {
547
+ "title": "input table name? - python script - KNIME Extensions - KNIME Community Forum",
548
+ "url": "https://forum.knime.com/t/input-table-name-python-script/78978",
549
+ "is_source_local": false,
550
+ "is_source_both": false,
551
+ "description": "Hi, when running a <strong>python</strong> script node, I get the error seen on the screenshot Same happens with this code too: The script input is output from the csv reader node. How can I get the right name for that table? Best wishes, Dario",
552
+ "page_age": "2024-05-04T09:20:44",
553
+ "profile": {
554
+ "name": "Knime",
555
+ "url": "https://forum.knime.com/t/input-table-name-python-script/78978",
556
+ "long_name": "forum.knime.com",
557
+ "img": "https://imgs.search.brave.com/WQoOhAD5i6uEhJ-qXvlWMJwbGA52f2Ycc_ns36EK698/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTAxNzMxNjFl/MzJjNzU5NzRkOTMz/Mjg4NDU2OWUxM2Rj/YzVkOGM3MzIwNzI2/YTY1NzYxNzA1MDE5/NzQzOWU3NC9mb3J1/bS5rbmltZS5jb20v"
558
+ },
559
+ "language": "en",
560
+ "family_friendly": true,
561
+ "type": "search_result",
562
+ "subtype": "article",
563
+ "meta_url": {
564
+ "scheme": "https",
565
+ "netloc": "forum.knime.com",
566
+ "hostname": "forum.knime.com",
567
+ "favicon": "https://imgs.search.brave.com/WQoOhAD5i6uEhJ-qXvlWMJwbGA52f2Ycc_ns36EK698/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTAxNzMxNjFl/MzJjNzU5NzRkOTMz/Mjg4NDU2OWUxM2Rj/YzVkOGM3MzIwNzI2/YTY1NzYxNzA1MDE5/NzQzOWU3NC9mb3J1/bS5rbmltZS5jb20v",
568
+ "path": " › knime extensions"
569
+ },
570
+ "thumbnail": {
571
+ "src": "https://imgs.search.brave.com/DtEl38dcvuM1kGfhN0T5HfOrsMJcztWNyriLvtDJmKI/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9mb3J1/bS1jZG4ua25pbWUu/Y29tL3VwbG9hZHMv/ZGVmYXVsdC9vcmln/aW5hbC8zWC9lLzYv/ZTY0M2M2NzFlNzAz/MDg2MjkwMWY2YzJh/OWFjOWI5ZmEwM2M3/ZjMwZi5wbmc",
572
+ "original": "https://forum-cdn.knime.com/uploads/default/original/3X/e/6/e643c671e7030862901f6c2a9ac9b9fa03c7f30f.png",
573
+ "logo": false
574
+ },
575
+ "age": "1 day ago",
576
+ "extra_snippets": [
577
+ "Hi, when running a python script node, I get the error seen on the screenshot Same happens with this code too: The script input is output from the csv reader node. How can I get the right name for that table? …"
578
+ ]
579
+ },
580
+ {
581
+ "title": "What does the Double Star operator mean in Python? - GeeksforGeeks",
582
+ "url": "https://www.geeksforgeeks.org/what-does-the-double-star-operator-mean-in-python/",
583
+ "is_source_local": false,
584
+ "is_source_both": false,
585
+ "description": "A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.",
586
+ "page_age": "2023-03-14T17:15:04",
587
+ "profile": {
588
+ "name": "GeeksforGeeks",
589
+ "url": "https://www.geeksforgeeks.org/what-does-the-double-star-operator-mean-in-python/",
590
+ "long_name": "geeksforgeeks.org",
591
+ "img": "https://imgs.search.brave.com/fhzcfv5xltx6-YBvJI9RZgS7xZo0dPNaASsrB8YOsCs/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjBhOGQ3MmNi/ZWE5N2EwMmZjYzA1/ZTI0ZTFhMGUyMTE0/MGM0ZTBmMWZlM2Y2/Yzk2ODMxZTRhYTBi/NDdjYTE0OS93d3cu/Z2Vla3Nmb3JnZWVr/cy5vcmcv"
592
+ },
593
+ "language": "en",
594
+ "family_friendly": true,
595
+ "type": "search_result",
596
+ "subtype": "article",
597
+ "meta_url": {
598
+ "scheme": "https",
599
+ "netloc": "geeksforgeeks.org",
600
+ "hostname": "www.geeksforgeeks.org",
601
+ "favicon": "https://imgs.search.brave.com/fhzcfv5xltx6-YBvJI9RZgS7xZo0dPNaASsrB8YOsCs/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjBhOGQ3MmNi/ZWE5N2EwMmZjYzA1/ZTI0ZTFhMGUyMTE0/MGM0ZTBmMWZlM2Y2/Yzk2ODMxZTRhYTBi/NDdjYTE0OS93d3cu/Z2Vla3Nmb3JnZWVr/cy5vcmcv",
602
+ "path": "› what-does-the-double-star-operator-mean-in-python"
603
+ },
604
+ "thumbnail": {
605
+ "src": "https://imgs.search.brave.com/GcR-j_dLbyHkbHEI3ffLMi6xpXGhF_2Z8POIoqtokhM/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9tZWRp/YS5nZWVrc2Zvcmdl/ZWtzLm9yZy93cC1j/b250ZW50L3VwbG9h/ZHMvZ2ZnXzIwMFgy/MDAtMTAweDEwMC5w/bmc",
606
+ "original": "https://media.geeksforgeeks.org/wp-content/uploads/gfg_200X200-100x100.png",
607
+ "logo": false
608
+ },
609
+ "age": "March 14, 2023",
610
+ "extra_snippets": [
611
+ "Difference between / vs. // operator in Python",
612
+ "Double Star or (**) is one of the Arithmetic Operator (Like +, -, *, **, /, //, %) in Python Language. It is also known as Power Operator.",
613
+ "The time complexity of the given Python program is O(n), where n is the number of key-value pairs in the input dictionary.",
614
+ "Inplace Operators in Python | Set 2 (ixor(), iand(), ipow(),…)"
615
+ ]
616
+ },
617
+ {
618
+ "title": "r/Python",
619
+ "url": "https://www.reddit.com/r/Python/",
620
+ "is_source_local": false,
621
+ "is_source_both": false,
622
+ "description": "The official <strong>Python</strong> community for Reddit! Stay up to date with the latest news, packages, and meta information relating to the <strong>Python</strong> programming language. --- If you have questions or are new to <strong>Python</strong> use r/LearnPython",
623
+ "page_age": "2022-12-30T16:25:02",
624
+ "profile": {
625
+ "name": "Reddit",
626
+ "url": "https://www.reddit.com/r/Python/",
627
+ "long_name": "reddit.com",
628
+ "img": "https://imgs.search.brave.com/mAZYEK9Wi13WLDUge7XZ8YuDTwm6DP6gBjvz1GdYZVY/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvN2ZiNTU0M2Nj/MTFhZjRiYWViZDlk/MjJiMjBjMzFjMDRk/Y2IzYWI0MGI0MjVk/OGY5NzQzOGQ5NzQ5/NWJhMWI0NC93d3cu/cmVkZGl0LmNvbS8"
629
+ },
630
+ "language": "en",
631
+ "family_friendly": true,
632
+ "type": "search_result",
633
+ "subtype": "generic",
634
+ "meta_url": {
635
+ "scheme": "https",
636
+ "netloc": "reddit.com",
637
+ "hostname": "www.reddit.com",
638
+ "favicon": "https://imgs.search.brave.com/mAZYEK9Wi13WLDUge7XZ8YuDTwm6DP6gBjvz1GdYZVY/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvN2ZiNTU0M2Nj/MTFhZjRiYWViZDlk/MjJiMjBjMzFjMDRk/Y2IzYWI0MGI0MjVk/OGY5NzQzOGQ5NzQ5/NWJhMWI0NC93d3cu/cmVkZGl0LmNvbS8",
639
+ "path": "› r › Python"
640
+ },
641
+ "thumbnail": {
642
+ "src": "https://imgs.search.brave.com/zWd10t3zg34ciHiAB-K5WWK3h_H4LedeDot9BVX7Ydo/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9zdHls/ZXMucmVkZGl0bWVk/aWEuY29tL3Q1XzJx/aDB5L3N0eWxlcy9j/b21tdW5pdHlJY29u/X2NpZmVobDR4dDdu/YzEucG5n",
643
+ "original": "https://styles.redditmedia.com/t5_2qh0y/styles/communityIcon_cifehl4xt7nc1.png",
644
+ "logo": false
645
+ },
646
+ "age": "December 30, 2022",
647
+ "extra_snippets": [
648
+ "r/Python: The official Python community for Reddit! Stay up to date with the latest news, packages, and meta information relating to the Python…",
649
+ "By default, Python allows you to import and use anything, anywhere. Over time, this results in modules that were intended to be separate getting tightly coupled together, and domain boundaries breaking down. We experienced this first-hand at a unicorn startup, where the eng team paused development for over a year in an attempt to split up packages into independent services.",
650
+ "Hello r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!",
651
+ "Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here."
652
+ ]
653
+ },
654
+ {
655
+ "title": "GitHub - python/cpython: The Python programming language",
656
+ "url": "https://github.com/python/cpython",
657
+ "is_source_local": false,
658
+ "is_source_both": false,
659
+ "description": "The <strong>Python</strong> programming language. Contribute to <strong>python</strong>/cpython development by creating an account on GitHub.",
660
+ "page_age": "2022-10-29T00:00:00",
661
+ "profile": {
662
+ "name": "GitHub",
663
+ "url": "https://github.com/python/cpython",
664
+ "long_name": "github.com",
665
+ "img": "https://imgs.search.brave.com/v8685zI4XInM0zxlNI2s7oE_2Sb-EL7lAy81WXbkQD8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYWQyNWM1NjA5/ZjZmZjNlYzI2MDNk/N2VkNmJhYjE2MzZl/MDY5ZTMxMDUzZmY1/NmU3NWIzNWVmMjk0/NTBjMjJjZi9naXRo/dWIuY29tLw"
666
+ },
667
+ "language": "en",
668
+ "family_friendly": true,
669
+ "type": "search_result",
670
+ "subtype": "software",
671
+ "meta_url": {
672
+ "scheme": "https",
673
+ "netloc": "github.com",
674
+ "hostname": "github.com",
675
+ "favicon": "https://imgs.search.brave.com/v8685zI4XInM0zxlNI2s7oE_2Sb-EL7lAy81WXbkQD8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYWQyNWM1NjA5/ZjZmZjNlYzI2MDNk/N2VkNmJhYjE2MzZl/MDY5ZTMxMDUzZmY1/NmU3NWIzNWVmMjk0/NTBjMjJjZi9naXRo/dWIuY29tLw",
676
+ "path": "› python › cpython"
677
+ },
678
+ "thumbnail": {
679
+ "src": "https://imgs.search.brave.com/BJbWFRUqgP-tKIyGK9ByXjuYjHO2mtYigUOEFNz_gXk/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9vcGVu/Z3JhcGguZ2l0aHVi/YXNzZXRzLmNvbS82/MTY5YmJkNTQ0YzAy/NDg0MGU4NDdjYTU1/YTU3ZGZmMDA2ZDAw/YWQ1NDIzOTFmYTQ3/YmJjODg3OWM0NWYw/MTZhL3B5dGhvbi9j/cHl0aG9u",
680
+ "original": "https://opengraph.githubassets.com/6169bbd544c024840e847ca55a57dff006d00ad542391fa47bbc8879c45f016a/python/cpython",
681
+ "logo": false
682
+ },
683
+ "age": "October 29, 2022",
684
+ "extra_snippets": [
685
+ "You can pass many options to the configure script; run ./configure --help to find out more. On macOS case-insensitive file systems and on Cygwin, the executable is called python.exe; elsewhere it's just python.",
686
+ "Building a complete Python installation requires the use of various additional third-party libraries, depending on your build platform and configure options. Not all standard library modules are buildable or useable on all platforms. Refer to the Install dependencies section of the Developer Guide for current detailed information on dependencies for various Linux distributions and macOS.",
687
+ "To get an optimized build of Python, configure --enable-optimizations before you run make. This sets the default make targets up to enable Profile Guided Optimization (PGO) and may be used to auto-enable Link Time Optimization (LTO) on some platforms. For more details, see the sections below.",
688
+ "Copyright © 2001-2024 Python Software Foundation. All rights reserved."
689
+ ]
690
+ },
691
+ {
692
+ "title": "5. Data Structures — Python 3.12.3 documentation",
693
+ "url": "https://docs.python.org/3/tutorial/datastructures.html",
694
+ "is_source_local": false,
695
+ "is_source_both": false,
696
+ "description": "This chapter describes some things you’ve learned about already in more detail, and adds some new things as well. More on Lists: The list data type has some more methods. Here are all of the method...",
697
+ "page_age": "2023-07-04T00:00:00",
698
+ "profile": {
699
+ "name": "Python documentation",
700
+ "url": "https://docs.python.org/3/tutorial/datastructures.html",
701
+ "long_name": "docs.python.org",
702
+ "img": "https://imgs.search.brave.com/F5Ym7eSElhGdGUFKLRxDj9Z_tc180ldpeMvQ2Q6ARbA/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvMTUzOTFjOGVi/YTcyOTVmODA3ODIy/YjE2NzFjY2ViMjhl/NzRlY2JhYTc5YjNm/ZjhmODAyZWI2OGUw/ZjU4NDVlNy9kb2Nz/LnB5dGhvbi5vcmcv"
703
+ },
704
+ "language": "en",
705
+ "family_friendly": true,
706
+ "type": "search_result",
707
+ "subtype": "generic",
708
+ "meta_url": {
709
+ "scheme": "https",
710
+ "netloc": "docs.python.org",
711
+ "hostname": "docs.python.org",
712
+ "favicon": "https://imgs.search.brave.com/F5Ym7eSElhGdGUFKLRxDj9Z_tc180ldpeMvQ2Q6ARbA/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvMTUzOTFjOGVi/YTcyOTVmODA3ODIy/YjE2NzFjY2ViMjhl/NzRlY2JhYTc5YjNm/ZjhmODAyZWI2OGUw/ZjU4NDVlNy9kb2Nz/LnB5dGhvbi5vcmcv",
713
+ "path": "› 3 › tutorial › datastructures.html"
714
+ },
715
+ "thumbnail": {
716
+ "src": "https://imgs.search.brave.com/Y7GrMRF8WorDIMLuOl97XC8ltYpoOCqNwWF2pQIIKls/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9kb2Nz/LnB5dGhvbi5vcmcv/My9fc3RhdGljL29n/LWltYWdlLnBuZw",
717
+ "original": "https://docs.python.org/3/_static/og-image.png",
718
+ "logo": false
719
+ },
720
+ "age": "July 4, 2023",
721
+ "extra_snippets": [
722
+ "You might have noticed that methods like insert, remove or sort that only modify the list have no return value printed – they return the default None. [1] This is a design principle for all mutable data structures in Python.",
723
+ "We saw that lists and strings have many common properties, such as indexing and slicing operations. They are two examples of sequence data types (see Sequence Types — list, tuple, range). Since Python is an evolving language, other sequence data types may be added. There is also another standard sequence data type: the tuple.",
724
+ "Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.",
725
+ "Another useful data type built into Python is the dictionary (see Mapping Types — dict). Dictionaries are sometimes found in other languages as “associative memories” or “associative arrays”. Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys."
726
+ ]
727
+ },
728
+ {
729
+ "title": "Something wrong with python packages / AUR Issues, Discussion & PKGBUILD Requests / Arch Linux Forums",
730
+ "url": "https://bbs.archlinux.org/viewtopic.php?id=295466",
731
+ "is_source_local": false,
732
+ "is_source_both": false,
733
+ "description": "Big <strong>Python</strong> updates require <strong>Python</strong> packages to be rebuild. For some reason they didn&#x27;t think a bump that made it necessary to rebuild half the official repo was a news post.",
734
+ "page_age": "2024-05-04T08:30:02",
735
+ "profile": {
736
+ "name": "Archlinux",
737
+ "url": "https://bbs.archlinux.org/viewtopic.php?id=295466",
738
+ "long_name": "bbs.archlinux.org",
739
+ "img": "https://imgs.search.brave.com/3au9oqkzSri_aLEec3jo-0bFgLuICkydrWfjFcC8lkI/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvNWNkODM1MWJl/ZmJhMzkzNzYzMDkz/NmEyMWMxNjI5MjNk/NGJmZjFhNTBlZDNl/Mzk5MzJjOGZkYjZl/MjNmY2IzNS9iYnMu/YXJjaGxpbnV4Lm9y/Zy8"
740
+ },
741
+ "language": "en",
742
+ "family_friendly": true,
743
+ "type": "search_result",
744
+ "subtype": "generic",
745
+ "meta_url": {
746
+ "scheme": "https",
747
+ "netloc": "bbs.archlinux.org",
748
+ "hostname": "bbs.archlinux.org",
749
+ "favicon": "https://imgs.search.brave.com/3au9oqkzSri_aLEec3jo-0bFgLuICkydrWfjFcC8lkI/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvNWNkODM1MWJl/ZmJhMzkzNzYzMDkz/NmEyMWMxNjI5MjNk/NGJmZjFhNTBlZDNl/Mzk5MzJjOGZkYjZl/MjNmY2IzNS9iYnMu/YXJjaGxpbnV4Lm9y/Zy8",
750
+ "path": "› viewtopic.php"
751
+ },
752
+ "age": "1 day ago",
753
+ "extra_snippets": [
754
+ "Traceback (most recent call last): File \"/usr/lib/python3.12/importlib/metadata/__init__.py\", line 397, in from_name return next(cls.discover(name=name)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File \"/usr/bin/informant\", line 33, in <module> sys.exit(load_entry_point('informant==0.5.0', 'console_scripts', 'informant')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File \"/usr/bin/informant\", line 22, in importlib_load_entry_point for entry_point in distribution(dis"
755
+ ]
756
+ },
757
+ {
758
+ "title": "Introduction to Python",
759
+ "url": "https://www.w3schools.com/python/python_intro.asp",
760
+ "is_source_local": false,
761
+ "is_source_both": false,
762
+ "description": "W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, <strong>Python</strong>, SQL, Java, and many, many more.",
763
+ "profile": {
764
+ "name": "W3Schools",
765
+ "url": "https://www.w3schools.com/python/python_intro.asp",
766
+ "long_name": "w3schools.com",
767
+ "img": "https://imgs.search.brave.com/JwO5r7z3HTBkU29vgNH_4rrSWLf2M4-8FMWNvbxrKX8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjVlMGVkZDVj/ZGMyZWRmMzAwODRi/ZDAwZGE4NWI3NmU4/MjRhNjEzOGFhZWY3/ZGViMjY1OWY2ZDYw/YTZiOGUyZS93d3cu/dzNzY2hvb2xzLmNv/bS8"
768
+ },
769
+ "language": "en",
770
+ "family_friendly": true,
771
+ "type": "search_result",
772
+ "subtype": "generic",
773
+ "meta_url": {
774
+ "scheme": "https",
775
+ "netloc": "w3schools.com",
776
+ "hostname": "www.w3schools.com",
777
+ "favicon": "https://imgs.search.brave.com/JwO5r7z3HTBkU29vgNH_4rrSWLf2M4-8FMWNvbxrKX8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjVlMGVkZDVj/ZGMyZWRmMzAwODRi/ZDAwZGE4NWI3NmU4/MjRhNjEzOGFhZWY3/ZGViMjY1OWY2ZDYw/YTZiOGUyZS93d3cu/dzNzY2hvb2xzLmNv/bS8",
778
+ "path": "› python › python_intro.asp"
779
+ },
780
+ "thumbnail": {
781
+ "src": "https://imgs.search.brave.com/EMfp8dodbJehmj0yCJh8317RHuaumsddnHI4bujvFcg/rs:fit:200:200:1/g:ce/aHR0cHM6Ly93d3cu/dzNzY2hvb2xzLmNv/bS9pbWFnZXMvdzNz/Y2hvb2xzX2xvZ29f/NDM2XzIucG5n",
782
+ "original": "https://www.w3schools.com/images/w3schools_logo_436_2.png",
783
+ "logo": true
784
+ },
785
+ "extra_snippets": [
786
+ "Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.",
787
+ "HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE",
788
+ "Python Variables Variable Names Assign Multiple Values Output Variables Global Variables Variable Exercises Python Data Types Python Numbers Python Casting Python Strings",
789
+ "Python Strings Slicing Strings Modify Strings Concatenate Strings Format Strings Escape Characters String Methods String Exercises Python Booleans Python Operators Python Lists"
790
+ ]
791
+ },
792
+ {
793
+ "title": "bug: AUR package wants to use python but does not find any preset version · Issue #1740 · asdf-vm/asdf",
794
+ "url": "https://github.com/asdf-vm/asdf/issues/1740",
795
+ "is_source_local": false,
796
+ "is_source_both": false,
797
+ "description": "Describe the Bug I am not sure why this is happening, I am trying to install tlpui from AUR and it fails, here are some logs to help: ==&gt; Making package: tlpui 2:1.6.5-1 (Mi 10 apr 2024 23:19:15 +0...",
798
+ "page_age": "2024-05-04T06:45:04",
799
+ "profile": {
800
+ "name": "GitHub",
801
+ "url": "https://github.com/asdf-vm/asdf/issues/1740",
802
+ "long_name": "github.com",
803
+ "img": "https://imgs.search.brave.com/v8685zI4XInM0zxlNI2s7oE_2Sb-EL7lAy81WXbkQD8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYWQyNWM1NjA5/ZjZmZjNlYzI2MDNk/N2VkNmJhYjE2MzZl/MDY5ZTMxMDUzZmY1/NmU3NWIzNWVmMjk0/NTBjMjJjZi9naXRo/dWIuY29tLw"
804
+ },
805
+ "language": "en",
806
+ "family_friendly": true,
807
+ "type": "search_result",
808
+ "subtype": "software",
809
+ "meta_url": {
810
+ "scheme": "https",
811
+ "netloc": "github.com",
812
+ "hostname": "github.com",
813
+ "favicon": "https://imgs.search.brave.com/v8685zI4XInM0zxlNI2s7oE_2Sb-EL7lAy81WXbkQD8/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYWQyNWM1NjA5/ZjZmZjNlYzI2MDNk/N2VkNmJhYjE2MzZl/MDY5ZTMxMDUzZmY1/NmU3NWIzNWVmMjk0/NTBjMjJjZi9naXRo/dWIuY29tLw",
814
+ "path": "› asdf-vm › asdf › issues › 1740"
815
+ },
816
+ "thumbnail": {
817
+ "src": "https://imgs.search.brave.com/KrLW5s_2n4jyP8XLbc3ZPVBaLD963tQgWzG9EWPZlQs/rs:fit:200:200:1/g:ce/aHR0cHM6Ly9vcGVu/Z3JhcGguZ2l0aHVi/YXNzZXRzLmNvbS81/MTE0ZTdkOGIwODM2/YmQ2MTY3NzQ1ZGI4/MmZjMGE3OGUyMjcw/MGFlY2ZjMWZkODBl/MDYzZTNiN2ZjOWNj/NzYyL2FzZGYtdm0v/YXNkZi9pc3N1ZXMv/MTc0MA",
818
+ "original": "https://opengraph.githubassets.com/5114e7d8b0836bd6167745db82fc0a78e22700aecfc1fd80e063e3b7fc9cc762/asdf-vm/asdf/issues/1740",
819
+ "logo": false
820
+ },
821
+ "age": "1 day ago",
822
+ "extra_snippets": [
823
+ "==> Starting build()... No preset version installed for command python Please install a version by running one of the following: asdf install python 3.8 or add one of the following versions in your config file at /home/ferret/.tool-versions python 3.11.0 python 3.12.1 python 3.12.3 ==> ERROR: A failure occurred in build(). Aborting...",
824
+ "-> error making: tlpui-exit status 4 -> Failed to install the following packages. Manual intervention is required: tlpui - exit status 4 ferret@FX505DT in ~ $ cat /home/ferret/.tool-versions nodejs 21.6.0 python 3.12.3 ferret@FX505DT in ~ $ python -V Python 3.12.3 ferret@FX505DT in ~ $ which python /home/ferret/.asdf/shims/python",
825
+ "Describe the Bug I am not sure why this is happening, I am trying to install tlpui from AUR and it fails, here are some logs to help: ==> Making package: tlpui 2:1.6.5-1 (Mi 10 apr 2024 23:19:15 +0300) ==> Retrieving sources... -> Found ..."
826
+ ]
827
+ },
828
+ {
829
+ "title": "What are python.exe and python3.exe, and why do they appear to point to App Installer? | Windows 11 Forum",
830
+ "url": "https://www.elevenforum.com/t/what-are-python-exe-and-python3-exe-and-why-do-they-appear-to-point-to-app-installer.24886/",
831
+ "is_source_local": false,
832
+ "is_source_both": false,
833
+ "description": "I was looking at App execution aliases (Settings &gt; Apps &gt; Advanced app settings &gt; App execution aliases) on my new computer -- my first Windows 11 computer. Why are <strong>python</strong>.exe and python3.exe listed as App Installer? I assume that App Installer refers to installation of Microsoft Store / UWP...",
834
+ "page_age": "2024-05-03T17:30:04",
835
+ "profile": {
836
+ "name": "Windows 11 Forum",
837
+ "url": "https://www.elevenforum.com/t/what-are-python-exe-and-python3-exe-and-why-do-they-appear-to-point-to-app-installer.24886/",
838
+ "long_name": "elevenforum.com",
839
+ "img": "https://imgs.search.brave.com/XVRAYMEj6Im8i7jV5RxeTwpiRPtY9IWg4wRIuh-WhEw/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvZjk5MDZkMDIw/M2U1OWIwNjM5Y2U1/M2U2NzNiNzVkNTA5/NzA5OTI1ZTFmOTc4/MzU3OTlhYzU5OTVi/ZGNjNTY4MS93d3cu/ZWxldmVuZm9ydW0u/Y29tLw"
840
+ },
841
+ "language": "en",
842
+ "family_friendly": true,
843
+ "type": "search_result",
844
+ "subtype": "generic",
845
+ "meta_url": {
846
+ "scheme": "https",
847
+ "netloc": "elevenforum.com",
848
+ "hostname": "www.elevenforum.com",
849
+ "favicon": "https://imgs.search.brave.com/XVRAYMEj6Im8i7jV5RxeTwpiRPtY9IWg4wRIuh-WhEw/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvZjk5MDZkMDIw/M2U1OWIwNjM5Y2U1/M2U2NzNiNzVkNTA5/NzA5OTI1ZTFmOTc4/MzU3OTlhYzU5OTVi/ZGNjNTY4MS93d3cu/ZWxldmVuZm9ydW0u/Y29tLw",
850
+ "path": " › windows support forums › apps and software"
851
+ },
852
+ "thumbnail": {
853
+ "src": "https://imgs.search.brave.com/DVoFcE6d_-lx3BVGNS-RZK_lZzxQ8VhwZVf3AVqEJFA/rs:fit:200:200:1/g:ce/aHR0cHM6Ly93d3cu/ZWxldmVuZm9ydW0u/Y29tL2RhdGEvYXNz/ZXRzL2xvZ28vbWV0/YTEtMjAxLnBuZw",
854
+ "original": "https://www.elevenforum.com/data/assets/logo/meta1-201.png",
855
+ "logo": true
856
+ },
857
+ "age": "2 days ago",
858
+ "extra_snippets": [
859
+ "Why are python.exe and python3.exe listed as App Installer? I assume that App Installer refers to installation of Microsoft Store / UWP apps, but if that's the case, then why are they called python.exe and python3.exe? Or are python.exe and python3.exe simply serving as aliases / pointers pointing to App Installer, which is itself a Microsoft Store App?",
860
+ "Or are python.exe and python3.exe simply serving as aliases / pointers pointing to App Installer, which is itself a Microsoft Store App? I wish to soon install Python, along with an integrated development editor (IDE), on my machine, so that I can code in Python.",
861
+ "I wish to soon install Python, along with an integrated development editor (IDE), on my machine, so that I can code in Python. But is a Python interpreter already on my computer as suggested, if obliquely, by the presence of python.exe and python3.exe? I kind of doubt it."
862
+ ]
863
+ },
864
+ {
865
+ "title": "How to Watermark Your Images Using Python OpenCV in ...",
866
+ "url": "https://medium.com/@daily_data_prep/how-to-watermark-your-images-using-python-opencv-in-bulk-e472085389a1",
867
+ "is_source_local": false,
868
+ "is_source_both": false,
869
+ "description": "Medium is an open platform where readers find dynamic thinking, and where expert and undiscovered voices can share their writing on any topic.",
870
+ "page_age": "2024-05-03T14:05:06",
871
+ "profile": {
872
+ "name": "Medium",
873
+ "url": "https://medium.com/@daily_data_prep/how-to-watermark-your-images-using-python-opencv-in-bulk-e472085389a1",
874
+ "long_name": "medium.com",
875
+ "img": "https://imgs.search.brave.com/qvE2kIQCiAsnPv2C6P9xM5J2VVWdm55g-A-2Q_yIJ0g/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTZhYmQ1N2Q4/NDg4ZDcyODIyMDZi/MzFmOWNhNjE3Y2E4/Y2YzMThjNjljNDIx/ZjllZmNhYTcwODhl/YTcwNDEzYy9tZWRp/dW0uY29tLw"
876
+ },
877
+ "language": "en",
878
+ "family_friendly": true,
879
+ "type": "search_result",
880
+ "subtype": "generic",
881
+ "meta_url": {
882
+ "scheme": "https",
883
+ "netloc": "medium.com",
884
+ "hostname": "medium.com",
885
+ "favicon": "https://imgs.search.brave.com/qvE2kIQCiAsnPv2C6P9xM5J2VVWdm55g-A-2Q_yIJ0g/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvOTZhYmQ1N2Q4/NDg4ZDcyODIyMDZi/MzFmOWNhNjE3Y2E4/Y2YzMThjNjljNDIx/ZjllZmNhYTcwODhl/YTcwNDEzYy9tZWRp/dW0uY29tLw",
886
+ "path": "› @daily_data_prep › how-to-watermark-your-images-using-python-opencv-in-bulk-e472085389a1"
887
+ },
888
+ "age": "2 days ago"
889
+ },
890
+ {
891
+ "title": "Increment and Decrement Operators in Python?",
892
+ "url": "https://www.tutorialspoint.com/increment-and-decrement-operators-in-python",
893
+ "is_source_local": false,
894
+ "is_source_both": false,
895
+ "description": "Increment and Decrement Operators in <strong>Python</strong> - <strong>Python</strong> does not have unary increment/decrement operator (++/--). Instead to increment a value, usea += 1to decrement a value, use −a -= 1Example&gt;&gt;&gt; a = 0 &gt;&gt;&gt; &gt;&gt;&gt; #Increment &gt;&gt;&gt; a +=1 &gt;&gt;&gt; &gt;&gt;&gt; #Decrement &gt;&gt;&gt; a -= 1 &gt;&gt;&gt; &gt;&gt;&gt; #value of a &gt;&gt;&gt; a 0Python ...",
896
+ "page_age": "2023-08-23T00:00:00",
897
+ "profile": {
898
+ "name": "Tutorialspoint",
899
+ "url": "https://www.tutorialspoint.com/increment-and-decrement-operators-in-python",
900
+ "long_name": "tutorialspoint.com",
901
+ "img": "https://imgs.search.brave.com/Wt8BSkivPlFwcU5yBtf7YzuvTuRExyd_502cdABCS5c/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjcyYjAzYmVl/ODU4MzZiMjJiYTFh/MjJhZDNmNWE4YzA5/MDgyYTZhMDg3NTYw/M2NiY2NiZTUxN2I5/MjU1MWFmMS93d3cu/dHV0b3JpYWxzcG9p/bnQuY29tLw"
902
+ },
903
+ "language": "en",
904
+ "family_friendly": true,
905
+ "type": "search_result",
906
+ "subtype": "generic",
907
+ "meta_url": {
908
+ "scheme": "https",
909
+ "netloc": "tutorialspoint.com",
910
+ "hostname": "www.tutorialspoint.com",
911
+ "favicon": "https://imgs.search.brave.com/Wt8BSkivPlFwcU5yBtf7YzuvTuRExyd_502cdABCS5c/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYjcyYjAzYmVl/ODU4MzZiMjJiYTFh/MjJhZDNmNWE4YzA5/MDgyYTZhMDg3NTYw/M2NiY2NiZTUxN2I5/MjU1MWFmMS93d3cu/dHV0b3JpYWxzcG9p/bnQuY29tLw",
912
+ "path": "› increment-and-decrement-operators-in-python"
913
+ },
914
+ "thumbnail": {
915
+ "src": "https://imgs.search.brave.com/ddG5vyZGLVudvecEbQJPeG8tGuaZ7g3Xz6Gyjdl5WA8/rs:fit:200:200:1/g:ce/aHR0cHM6Ly93d3cu/dHV0b3JpYWxzcG9p/bnQuY29tL2ltYWdl/cy90cF9sb2dvXzQz/Ni5wbmc",
916
+ "original": "https://www.tutorialspoint.com/images/tp_logo_436.png",
917
+ "logo": true
918
+ },
919
+ "age": "August 23, 2023",
920
+ "extra_snippets": [
921
+ "Increment and Decrement Operators in Python - Python does not have unary increment/decrement operator (++/--). Instead to increment a value, usea += 1to decrement a value, use −a -= 1Example>>> a = 0 >>> >>> #Increment >>> a +=1 >>> >>> #Decrement >>> a -= 1 >>> >>> #value of a >>> a 0Python does not provide multiple ways to do the same thing",
922
+ "So what above statement means in python is: create an object of type int having value 1 and give the name a to it. The object is an instance of int having value 1 and the name a refers to it. The assigned name a and the object to which it refers are distinct.",
923
+ "Python does not provide multiple ways to do the same thing .",
924
+ "However, be careful if you are coming from a language like C, Python doesn’t have \"variables\" in the sense that C does, instead python uses names and objects and in python integers (int’s) are immutable."
925
+ ]
926
+ },
927
+ {
928
+ "title": "Gumroad – How not to suck at Python / SideFX Houdini | CG Persia",
929
+ "url": "https://cgpersia.com/2024/05/gumroad-how-not-to-suck-at-python-sidefx-houdini-195370.html",
930
+ "is_source_local": false,
931
+ "is_source_both": false,
932
+ "description": "Info: This course is made for artists or TD (technical director) willing to learn <strong>Python</strong> to improve their workflows inside SideFX Houdini, get faster in production and develop all the tools you always wished you had.",
933
+ "page_age": "2024-05-03T08:35:03",
934
+ "profile": {
935
+ "name": "Cgpersia",
936
+ "url": "https://cgpersia.com/2024/05/gumroad-how-not-to-suck-at-python-sidefx-houdini-195370.html",
937
+ "long_name": "cgpersia.com",
938
+ "img": "https://imgs.search.brave.com/VjyaopAm-M9sWvM7n-KnGZ3T5swIOwwE80iF5QVqQPg/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYmE0MzQ4NmI2/NjFhMTA1ZDBiN2Iw/ZWNiNDUxNjUwYjdh/MGE5ZjQ0ZjIxNzll/NmVkZDE2YzYyMDBh/NDNiMDgwMy9jZ3Bl/cnNpYS5jb20v"
939
+ },
940
+ "language": "en",
941
+ "family_friendly": true,
942
+ "type": "search_result",
943
+ "subtype": "generic",
944
+ "meta_url": {
945
+ "scheme": "https",
946
+ "netloc": "cgpersia.com",
947
+ "hostname": "cgpersia.com",
948
+ "favicon": "https://imgs.search.brave.com/VjyaopAm-M9sWvM7n-KnGZ3T5swIOwwE80iF5QVqQPg/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvYmE0MzQ4NmI2/NjFhMTA1ZDBiN2Iw/ZWNiNDUxNjUwYjdh/MGE5ZjQ0ZjIxNzll/NmVkZDE2YzYyMDBh/NDNiMDgwMy9jZ3Bl/cnNpYS5jb20v",
949
+ "path": "› 2024 › 05 › gumroad-how-not-to-suck-at-python-sidefx-houdini-195370.html"
950
+ },
951
+ "age": "2 days ago",
952
+ "extra_snippets": [
953
+ "Posted in: 2D, CG Releases, Downloads, Learning, Tutorials, Videos. Tagged: Gumroad, Python, Sidefx. Leave a Comment",
954
+ "01 – Python – Fundamentals Get the Fundamentals of python before starting the fun stuff ! 02 – Python Construction Part02 digging further into python concepts 03 – Houdini – Python Basics Applying some basic python in Houdini and starting to make tools !",
955
+ "02 – Python Construction Part02 digging further into python concepts 03 – Houdini – Python Basics Applying some basic python in Houdini and starting to make tools ! 04 – Houdini – Python Intermediate Applying some more advanced python in Houdini to make tools ! 05 – Houdini – Python Expert Using QtDesigner in combinaison with Houdini Python/Pyside to create advanced tools."
956
+ ]
957
+ },
958
+ {
959
+ "title": "How to install Python: The complete Python programmer’s guide",
960
+ "url": "https://www.pluralsight.com/resources/blog/software-development/python-installation-guide",
961
+ "is_source_local": false,
962
+ "is_source_both": false,
963
+ "description": "An easy guide on how set up your operating system so you can program in <strong>Python</strong>, and how to update or uninstall it. For Linux, Windows, and macOS.",
964
+ "page_age": "2024-05-02T07:30:02",
965
+ "profile": {
966
+ "name": "Pluralsight",
967
+ "url": "https://www.pluralsight.com/resources/blog/software-development/python-installation-guide",
968
+ "long_name": "pluralsight.com",
969
+ "img": "https://imgs.search.brave.com/zvwQNSVu9-jR2CRlNcsTzxjaXKPlXNuh-Jo9-0yA1OE/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvMTNkNWQyNjk3/M2Q0NzYyMmUyNDc3/ZjYwMWFlZDI5YTI4/ODhmYzc2MDkzMjAy/MjNkMWY1MDE3NTQw/MzI5NWVkZS93d3cu/cGx1cmFsc2lnaHQu/Y29tLw"
970
+ },
971
+ "language": "en",
972
+ "family_friendly": true,
973
+ "type": "search_result",
974
+ "subtype": "generic",
975
+ "meta_url": {
976
+ "scheme": "https",
977
+ "netloc": "pluralsight.com",
978
+ "hostname": "www.pluralsight.com",
979
+ "favicon": "https://imgs.search.brave.com/zvwQNSVu9-jR2CRlNcsTzxjaXKPlXNuh-Jo9-0yA1OE/rs:fit:32:32:1/g:ce/aHR0cDovL2Zhdmlj/b25zLnNlYXJjaC5i/cmF2ZS5jb20vaWNv/bnMvMTNkNWQyNjk3/M2Q0NzYyMmUyNDc3/ZjYwMWFlZDI5YTI4/ODhmYzc2MDkzMjAy/MjNkMWY1MDE3NTQw/MzI5NWVkZS93d3cu/cGx1cmFsc2lnaHQu/Y29tLw",
980
+ "path": " › blog › blog"
981
+ },
982
+ "thumbnail": {
983
+ "src": "https://imgs.search.brave.com/xrv5PHH2Bzmq2rcIYzk__8h5RqCj6kS3I6SGCNw5dZM/rs:fit:200:200:1/g:ce/aHR0cHM6Ly93d3cu/cGx1cmFsc2lnaHQu/Y29tL2NvbnRlbnQv/ZGFtL3BzL2ltYWdl/cy9yZXNvdXJjZS1j/ZW50ZXIvYmxvZy9o/ZWFkZXItaGVyby1p/bWFnZXMvUHl0aG9u/LndlYnA",
984
+ "original": "https://www.pluralsight.com/content/dam/ps/images/resource-center/blog/header-hero-images/Python.webp",
985
+ "logo": false
986
+ },
987
+ "age": "3 days ago",
988
+ "extra_snippets": [
989
+ "Whether it’s your first time programming or you’re a seasoned programmer, you’ll have to install or update Python every now and then --- or if necessary, uninstall it. In this article, you'll learn how to do just that.",
990
+ "Some systems come with Python, so to start off, we’ll first check to see if it’s installed on your system before we proceed. To do that, we’ll need to open a terminal. Since you might be new to programming, let’s go over how to open a terminal for Linux, Windows, and macOS.",
991
+ "Before we dive into setting up your system so you can program in Python, let’s talk terminal basics and benefits.",
992
+ "However, let’s focus on why we need it for working with Python. We use a terminal, or command line, to:"
993
+ ]
994
+ }
995
+ ],
996
+ "family_friendly": true
997
+ }
998
+ }