├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md ├── dependabot.yml └── workflows │ ├── ci.yml │ ├── codeql-analysis.yml │ ├── stale-issues.yml │ └── typos.yml ├── .gitignore ├── .markdownlint.json ├── LICENSE.txt ├── Makefile ├── README.md ├── examples_config ├── elyza.json ├── line.json └── rinna.json ├── package.json ├── pnpm-lock.yaml ├── poetry.lock ├── pyproject.toml ├── tests └── check_null.py └── tsukaima ├── model.py ├── schema ├── __init__.py ├── openai.py └── schema.py ├── serve.py └── streamer.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | --- 2 | github: shirayu 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41B Bug Report" 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Describe the bug 11 | 12 | 13 | ## To Reproduce 14 | 15 | 16 | ## Expected behavior 17 | 18 | 19 | ## Logs (Optional) 20 | 21 | ## Environment 22 | 23 | - OS: 24 | - Browser Version: 25 | - stable-diffusion-webui Version: 26 | - sd-webui-enable-checker Version: 27 | 28 | ## Additional context 29 | 30 | 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F680 Feature request" 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Description 11 | 12 | ## Additional context 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "❓ Question" 3 | about: Question 4 | title: '' 5 | labels: 'Type: Question' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Description 11 | 12 | 13 | 14 | ## Logs (Optional) 15 | 16 | ## Environment 17 | 18 | 19 | 20 | - OS: 21 | - stable-diffusion-webui Version: 22 | - sd-webui-enable-checker Version: 23 | 24 | ## Additional context 25 | 26 | 27 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "monthly" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "monthly" 11 | - package-ecosystem: "pip" 12 | directory: "/" 13 | schedule: 14 | interval: "monthly" 15 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | "on": 4 | push: 5 | pull_request: 6 | types: 7 | - opened 8 | - synchronize 9 | - reopened 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | os: [ubuntu-latest] 16 | python-version: ["3.11"] 17 | steps: 18 | - uses: actions/checkout@v4 19 | - uses: actions/setup-node@v4.0.1 20 | with: 21 | node-version: '18' 22 | - uses: actions/setup-python@v5 23 | with: 24 | python-version: ${{ matrix.python-version }} 25 | 26 | - name: Install Poetry Action 27 | uses: snok/install-poetry@v1.3.4 28 | with: 29 | virtualenvs-create: true 30 | virtualenvs-in-project: true 31 | 32 | - name: Load cached venv 33 | id: cached-poetry-dependencies 34 | uses: actions/cache@v3 35 | with: 36 | path: .venv 37 | key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/package-lock.json') }} 38 | 39 | - run: pip install poetry 40 | - run: poetry env use ${{ matrix.python-version }} 41 | - run: poetry install 42 | 43 | - name: Setup pnpm 44 | uses: pnpm/action-setup@v2.4.0 45 | with: 46 | version: 8 47 | run_install: false 48 | 49 | - name: Get pnpm store directory 50 | shell: bash 51 | run: | 52 | echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV 53 | 54 | - uses: actions/cache@v3 55 | name: Setup pnpm cache 56 | with: 57 | path: ${{ env.STORE_PATH }} 58 | key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} 59 | restore-keys: | 60 | ${{ runner.os }}-pnpm-store- 61 | 62 | - name: Install dependencies 63 | run: pnpm install 64 | 65 | - run: pnpm test 66 | - run: poetry run make -j $(nproc) lint_python pyright 67 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '35 2 * * 6' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: ['javascript'] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v4 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v3 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v3 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v3 72 | -------------------------------------------------------------------------------- /.github/workflows/stale-issues.yml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues 2 | on: 3 | schedule: 4 | - cron: "45 1 * * *" 5 | 6 | jobs: 7 | close-issues: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/stale@v9.0.0 11 | with: 12 | repo-token: ${{ secrets.GITHUB_TOKEN }} 13 | stale-issue-message: "This issue is stale because it has been open for 21 days with no activity." 14 | close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." 15 | stale-issue-label: "Status: Stale" 16 | only-labels: "Type: Question" 17 | exempt-issue-labels: "Status: In Progress" 18 | days-before-issue-stale: 21 19 | days-before-issue-close: 14 20 | days-before-pr-stale: -1 21 | days-before-pr-close: -1 22 | -------------------------------------------------------------------------------- /.github/workflows/typos.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # yamllint disable rule:line-length 3 | name: Typos 4 | 5 | "on": 6 | push: 7 | pull_request: 8 | types: 9 | - opened 10 | - synchronize 11 | - reopened 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: typos-action 21 | uses: crate-ci/typos@v1.16.26 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Microbundle cache 58 | .rpt2_cache/ 59 | .rts2_cache_cjs/ 60 | .rts2_cache_es/ 61 | .rts2_cache_umd/ 62 | 63 | # Optional REPL history 64 | .node_repl_history 65 | 66 | # Output of 'npm pack' 67 | *.tgz 68 | 69 | # Yarn Integrity file 70 | .yarn-integrity 71 | 72 | # dotenv environment variables file 73 | .env 74 | .env.test 75 | .env.production 76 | 77 | # parcel-bundler cache (https://parceljs.org/) 78 | .cache 79 | .parcel-cache 80 | 81 | # Next.js build output 82 | .next 83 | out 84 | 85 | # Nuxt.js build / generate output 86 | .nuxt 87 | dist 88 | 89 | # Gatsby files 90 | .cache/ 91 | # Comment in the public line in if your project uses Gatsby and not Next.js 92 | # https://nextjs.org/blog/next-9-1#public-directory-support 93 | # public 94 | 95 | # vuepress build output 96 | .vuepress/dist 97 | 98 | # Serverless directories 99 | .serverless/ 100 | 101 | # FuseBox cache 102 | .fusebox/ 103 | 104 | # DynamoDB Local files 105 | .dynamodb/ 106 | 107 | # TernJS port file 108 | .tern-port 109 | 110 | # Stores VSCode versions used for testing VSCode extensions 111 | .vscode-test 112 | 113 | # yarn v2 114 | .yarn/cache 115 | .yarn/unplugged 116 | .yarn/build-state.yml 117 | .yarn/install-state.gz 118 | .pnp.* 119 | src/3rd 120 | 121 | # Byte-compiled / optimized / DLL files 122 | __pycache__/ 123 | *.py[cod] 124 | *$py.class 125 | 126 | # C extensions 127 | *.so 128 | 129 | # Distribution / packaging 130 | .Python 131 | build/ 132 | develop-eggs/ 133 | dist/ 134 | downloads/ 135 | eggs/ 136 | .eggs/ 137 | lib/ 138 | lib64/ 139 | parts/ 140 | sdist/ 141 | var/ 142 | wheels/ 143 | share/python-wheels/ 144 | *.egg-info/ 145 | .installed.cfg 146 | *.egg 147 | MANIFEST 148 | 149 | # PyInstaller 150 | # Usually these files are written by a python script from a template 151 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 152 | *.manifest 153 | *.spec 154 | 155 | # Installer logs 156 | pip-log.txt 157 | pip-delete-this-directory.txt 158 | 159 | # Unit test / coverage reports 160 | htmlcov/ 161 | .tox/ 162 | .nox/ 163 | .coverage 164 | .coverage.* 165 | .cache 166 | nosetests.xml 167 | coverage.xml 168 | *.cover 169 | *.py,cover 170 | .hypothesis/ 171 | .pytest_cache/ 172 | cover/ 173 | 174 | # Translations 175 | *.mo 176 | *.pot 177 | 178 | # Django stuff: 179 | *.log 180 | local_settings.py 181 | db.sqlite3 182 | db.sqlite3-journal 183 | 184 | # Flask stuff: 185 | instance/ 186 | .webassets-cache 187 | 188 | # Scrapy stuff: 189 | .scrapy 190 | 191 | # Sphinx documentation 192 | docs/_build/ 193 | 194 | # PyBuilder 195 | .pybuilder/ 196 | target/ 197 | 198 | # Jupyter Notebook 199 | .ipynb_checkpoints 200 | 201 | # IPython 202 | profile_default/ 203 | ipython_config.py 204 | 205 | # pyenv 206 | # For a library or package, you might want to ignore these files since the code is 207 | # intended to run in multiple environments; otherwise, check them in: 208 | # .python-version 209 | 210 | # pipenv 211 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 212 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 213 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 214 | # install all needed dependencies. 215 | #Pipfile.lock 216 | 217 | # poetry 218 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 219 | # This is especially recommended for binary packages to ensure reproducibility, and is more 220 | # commonly ignored for libraries. 221 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 222 | #poetry.lock 223 | 224 | # pdm 225 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 226 | #pdm.lock 227 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 228 | # in version control. 229 | # https://pdm.fming.dev/#use-with-ide 230 | .pdm.toml 231 | 232 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 233 | __pypackages__/ 234 | 235 | # Celery stuff 236 | celerybeat-schedule 237 | celerybeat.pid 238 | 239 | # SageMath parsed files 240 | *.sage.py 241 | 242 | # Environments 243 | .env 244 | .venv 245 | env/ 246 | venv/ 247 | ENV/ 248 | env.bak/ 249 | venv.bak/ 250 | 251 | # Spyder project settings 252 | .spyderproject 253 | .spyproject 254 | 255 | # Rope project settings 256 | .ropeproject 257 | 258 | # mkdocs documentation 259 | /site 260 | 261 | # mypy 262 | .mypy_cache/ 263 | .dmypy.json 264 | dmypy.json 265 | 266 | # Pyre type checker 267 | .pyre/ 268 | 269 | # pytype static type analyzer 270 | .pytype/ 271 | 272 | # Cython debug symbols 273 | cython_debug/ 274 | 275 | # PyCharm 276 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 277 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 278 | # and can be added to the global gitignore or merged into this file. For a more nuclear 279 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 280 | #.idea/ 281 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "MD007": { 3 | "indent": 4 4 | }, 5 | "line-length": false, 6 | "no-inline-html": false, 7 | "MD026": false 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | SHELL=/bin/bash 3 | 4 | all: lint_node lint_python 5 | 6 | TARGET_DIRS:=./tsukaima 7 | 8 | ruff: 9 | ruff format --respect-gitignore --check 10 | ruff --respect-gitignore 11 | 12 | yamllint: 13 | find . \( -name node_modules -o -name .venv \) -prune -o -type f -name '*.yml' -print \ 14 | | xargs yamllint --no-warnings 15 | 16 | lint_python: ruff 17 | 18 | 19 | pyright: 20 | npx pyright 21 | 22 | markdownlint: 23 | find . -type d \( -name node_modules -o -name .venv \) -prune -o -type f -name '*.md' -print \ 24 | | xargs npx markdownlint --config ./.markdownlint.json 25 | 26 | lint_node: markdownlint pyright 27 | 28 | 29 | style: 30 | find $(TARGET_DIRS) | grep '\.py$$' | xargs black 31 | find $(TARGET_DIRS) | grep '\.py$$' | xargs isort 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # tsukaima 3 | 4 | [![License](https://img.shields.io/badge/License-AGPL%203.0-blue.svg)](https://github.com/shirayu/tsukaima/blob/main/LICENSE.txt) 5 | [![CI](https://github.com/shirayu/tsukaima/actions/workflows/ci.yml/badge.svg)](https://github.com/shirayu/tsukaima/actions/workflows/ci.yml) 6 | [![CodeQL](https://github.com/shirayu/tsukaima/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/shirayu/tsukaima/actions/workflows/codeql-analysis.yml) 7 | [![Typos](https://github.com/shirayu/tsukaima/actions/workflows/typos.yml/badge.svg)](https://github.com/shirayu/tsukaima/actions/workflows/typos.yml) 8 | 9 | Tsukaima is a tool to call local large language models (LLMs) using the existing OpenAI ChatGPT clients. 10 | Currently, the following models are supported. 11 | 12 | - [rinna LLM](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-ppo) 13 | - [line-corporation/japanese-large-lm-3.6b-instruction-sft](https://huggingface.co/line-corporation/japanese-large-lm-3.6b-instruction-sft) 14 | - [elyza/ELYZA-japanese-Llama-2-7b-instruct](https://huggingface.co/elyza/ELYZA-japanese-Llama-2-7b-instruct) 15 | 16 | ## How to use 17 | 18 | ```console 19 | $ python3 -m venv myvenv 20 | $ source myvenv/bin/activate 21 | (myvenv) $ pip install -U git+https://github.com/shirayu/tsukaima.git 22 | (myvenv) $ wget https://raw.githubusercontent.com/shirayu/tsukaima/main/examples_config/rinna.json -O rinna.json 23 | (myvenv) $ tsukaima --host 0.0.0.0 --port 6006 --config ./rinna.json 24 | ``` 25 | 26 | Set API endpoint to the address (Eg: ``http://0.0.0.0:6006/v1/chat/completions``) to use ChatGPT clients such as [BetterChatGPT](https://github.com/ztjhz/BetterChatGPT). 27 | 28 | Screenshot 29 | 30 | Check [other config examples](https://github.com/shirayu/tsukaima/tree/main/examples_config). 31 | 32 | ## Specification 33 | 34 | - Messages whose `role` is `system` will be ignored 35 | 36 | ## Setting file format 37 | 38 | Please read [tsukaima.schema.schema](https://github.com/shirayu/tsukaima/blob/main/tsukaima/schema/schema.py) 39 | 40 | ## Tips 41 | 42 | - You may need install [NCCL](https://developer.nvidia.com/nccl/nccl-download) 43 | - ``sudo apt install libnccl-dev libnccl2`` 44 | 45 | ## Reference 46 | 47 | - 48 | - 49 | - 50 | - 51 | - 52 | -------------------------------------------------------------------------------- /examples_config/elyza.json: -------------------------------------------------------------------------------- 1 | { 2 | "models": [ 3 | { 4 | "forced_parameters": { 5 | "max_new_tokens": 1024, 6 | "repetition_penalty": 1.2 7 | }, 8 | "model_kwargs": { 9 | "device_map": "auto", 10 | "load_in_8bit": true 11 | }, 12 | "names": [ 13 | "gpt-3.5-turbo" 14 | ], 15 | "path": "elyza/ELYZA-japanese-Llama-2-7b-instruct" , 16 | "tokenizer_kwargs": {} 17 | } 18 | ], 19 | "version": 2 20 | } 21 | -------------------------------------------------------------------------------- /examples_config/line.json: -------------------------------------------------------------------------------- 1 | { 2 | "models": [ 3 | { 4 | "forced_parameters": { 5 | "max_new_tokens": 256, 6 | "repetition_penalty": 1.1, 7 | "temperature": 0.7 8 | }, 9 | "model_kwargs": { 10 | "device_map": "auto", 11 | "load_in_8bit": true 12 | }, 13 | "names": [ 14 | "gpt-3.5-turbo" 15 | ], 16 | "path": "line-corporation/japanese-large-lm-3.6b-instruction-sft", 17 | "tokenizer_kwargs": {} 18 | } 19 | ], 20 | "version": 2 21 | } 22 | -------------------------------------------------------------------------------- /examples_config/rinna.json: -------------------------------------------------------------------------------- 1 | { 2 | "models": [ 3 | { 4 | "forced_parameters": { 5 | "max_new_tokens": 256, 6 | "repetition_penalty": 1.1, 7 | "temperature": 0.7 8 | }, 9 | "model_kwargs": { 10 | "device_map": "auto", 11 | "load_in_8bit": true 12 | }, 13 | "names": [ 14 | "gpt-3.5-turbo" 15 | ], 16 | "path": "rinna/japanese-gpt-neox-3.6b-instruction-ppo", 17 | "tokenizer_kwargs": {} 18 | } 19 | ], 20 | "version": 2 21 | } 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "", 3 | "description": "", 4 | "devDependencies": { 5 | "markdownlint-cli": "^0.37.0", 6 | "pyright": "^1.1.344" 7 | }, 8 | "engines": { 9 | "npm": "Use pnpm instead of npm!" 10 | }, 11 | "license": "", 12 | "main": "", 13 | "name": "pyright-exec", 14 | "scripts": { 15 | "preinstall": "npx only-allow pnpm", 16 | "test": ":" 17 | }, 18 | "version": "1.0.0" 19 | } 20 | -------------------------------------------------------------------------------- /pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | devDependencies: 8 | markdownlint-cli: 9 | specifier: ^0.37.0 10 | version: 0.37.0 11 | pyright: 12 | specifier: ^1.1.344 13 | version: 1.1.344 14 | 15 | packages: 16 | 17 | /@isaacs/cliui@8.0.2: 18 | resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} 19 | engines: {node: '>=12'} 20 | dependencies: 21 | string-width: 5.1.2 22 | string-width-cjs: /string-width@4.2.3 23 | strip-ansi: 7.1.0 24 | strip-ansi-cjs: /strip-ansi@6.0.1 25 | wrap-ansi: 8.1.0 26 | wrap-ansi-cjs: /wrap-ansi@7.0.0 27 | dev: true 28 | 29 | /@pkgjs/parseargs@0.11.0: 30 | resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} 31 | engines: {node: '>=14'} 32 | requiresBuild: true 33 | dev: true 34 | optional: true 35 | 36 | /ansi-regex@5.0.1: 37 | resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} 38 | engines: {node: '>=8'} 39 | dev: true 40 | 41 | /ansi-regex@6.0.1: 42 | resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} 43 | engines: {node: '>=12'} 44 | dev: true 45 | 46 | /ansi-styles@4.3.0: 47 | resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} 48 | engines: {node: '>=8'} 49 | dependencies: 50 | color-convert: 2.0.1 51 | dev: true 52 | 53 | /ansi-styles@6.2.1: 54 | resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} 55 | engines: {node: '>=12'} 56 | dev: true 57 | 58 | /argparse@2.0.1: 59 | resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} 60 | dev: true 61 | 62 | /balanced-match@1.0.2: 63 | resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} 64 | dev: true 65 | 66 | /brace-expansion@2.0.1: 67 | resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} 68 | dependencies: 69 | balanced-match: 1.0.2 70 | dev: true 71 | 72 | /color-convert@2.0.1: 73 | resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} 74 | engines: {node: '>=7.0.0'} 75 | dependencies: 76 | color-name: 1.1.4 77 | dev: true 78 | 79 | /color-name@1.1.4: 80 | resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} 81 | dev: true 82 | 83 | /commander@11.0.0: 84 | resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==} 85 | engines: {node: '>=16'} 86 | dev: true 87 | 88 | /cross-spawn@7.0.3: 89 | resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} 90 | engines: {node: '>= 8'} 91 | dependencies: 92 | path-key: 3.1.1 93 | shebang-command: 2.0.0 94 | which: 2.0.2 95 | dev: true 96 | 97 | /deep-extend@0.6.0: 98 | resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} 99 | engines: {node: '>=4.0.0'} 100 | dev: true 101 | 102 | /eastasianwidth@0.2.0: 103 | resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} 104 | dev: true 105 | 106 | /emoji-regex@8.0.0: 107 | resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} 108 | dev: true 109 | 110 | /emoji-regex@9.2.2: 111 | resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} 112 | dev: true 113 | 114 | /entities@3.0.1: 115 | resolution: {integrity: sha512-WiyBqoomrwMdFG1e0kqvASYfnlb0lp8M5o5Fw2OFq1hNZxxcNk8Ik0Xm7LxzBhuidnZB/UtBqVCgUz3kBOP51Q==} 116 | engines: {node: '>=0.12'} 117 | dev: true 118 | 119 | /foreground-child@3.1.1: 120 | resolution: {integrity: sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==} 121 | engines: {node: '>=14'} 122 | dependencies: 123 | cross-spawn: 7.0.3 124 | signal-exit: 4.1.0 125 | dev: true 126 | 127 | /fsevents@2.3.3: 128 | resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} 129 | engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} 130 | os: [darwin] 131 | requiresBuild: true 132 | dev: true 133 | optional: true 134 | 135 | /get-stdin@9.0.0: 136 | resolution: {integrity: sha512-dVKBjfWisLAicarI2Sf+JuBE/DghV4UzNAVe9yhEJuzeREd3JhOTE9cUaJTeSa77fsbQUK3pcOpJfM59+VKZaA==} 137 | engines: {node: '>=12'} 138 | dev: true 139 | 140 | /glob@10.3.10: 141 | resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==} 142 | engines: {node: '>=16 || 14 >=14.17'} 143 | hasBin: true 144 | dependencies: 145 | foreground-child: 3.1.1 146 | jackspeak: 2.3.6 147 | minimatch: 9.0.3 148 | minipass: 7.0.4 149 | path-scurry: 1.10.1 150 | dev: true 151 | 152 | /ignore@5.2.4: 153 | resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} 154 | engines: {node: '>= 4'} 155 | dev: true 156 | 157 | /ini@4.1.1: 158 | resolution: {integrity: sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==} 159 | engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} 160 | dev: true 161 | 162 | /is-fullwidth-code-point@3.0.0: 163 | resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} 164 | engines: {node: '>=8'} 165 | dev: true 166 | 167 | /isexe@2.0.0: 168 | resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} 169 | dev: true 170 | 171 | /jackspeak@2.3.6: 172 | resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==} 173 | engines: {node: '>=14'} 174 | dependencies: 175 | '@isaacs/cliui': 8.0.2 176 | optionalDependencies: 177 | '@pkgjs/parseargs': 0.11.0 178 | dev: true 179 | 180 | /js-yaml@4.1.0: 181 | resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} 182 | hasBin: true 183 | dependencies: 184 | argparse: 2.0.1 185 | dev: true 186 | 187 | /jsonc-parser@3.2.0: 188 | resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} 189 | dev: true 190 | 191 | /linkify-it@4.0.1: 192 | resolution: {integrity: sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw==} 193 | dependencies: 194 | uc.micro: 1.0.6 195 | dev: true 196 | 197 | /lru-cache@10.1.0: 198 | resolution: {integrity: sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==} 199 | engines: {node: 14 || >=16.14} 200 | dev: true 201 | 202 | /markdown-it@13.0.1: 203 | resolution: {integrity: sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==} 204 | hasBin: true 205 | dependencies: 206 | argparse: 2.0.1 207 | entities: 3.0.1 208 | linkify-it: 4.0.1 209 | mdurl: 1.0.1 210 | uc.micro: 1.0.6 211 | dev: true 212 | 213 | /markdownlint-cli@0.37.0: 214 | resolution: {integrity: sha512-hNKAc0bWBBuVhJbSWbUhRzavstiB4o1jh3JeSpwC4/dt6eJ54lRfYHRxVdzVp4qGWBKbeE6Pg490PFEfrKjqSg==} 215 | engines: {node: '>=16'} 216 | hasBin: true 217 | dependencies: 218 | commander: 11.0.0 219 | get-stdin: 9.0.0 220 | glob: 10.3.10 221 | ignore: 5.2.4 222 | js-yaml: 4.1.0 223 | jsonc-parser: 3.2.0 224 | markdownlint: 0.31.1 225 | minimatch: 9.0.3 226 | run-con: 1.3.2 227 | dev: true 228 | 229 | /markdownlint-micromark@0.1.7: 230 | resolution: {integrity: sha512-BbRPTC72fl5vlSKv37v/xIENSRDYL/7X/XoFzZ740FGEbs9vZerLrIkFRY0rv7slQKxDczToYuMmqQFN61fi4Q==} 231 | engines: {node: '>=16'} 232 | dev: true 233 | 234 | /markdownlint@0.31.1: 235 | resolution: {integrity: sha512-CKMR2hgcIBrYlIUccDCOvi966PZ0kJExDrUi1R+oF9PvqQmCrTqjOsgIvf2403OmJ+CWomuzDoylr6KbuMyvHA==} 236 | engines: {node: '>=16'} 237 | dependencies: 238 | markdown-it: 13.0.1 239 | markdownlint-micromark: 0.1.7 240 | dev: true 241 | 242 | /mdurl@1.0.1: 243 | resolution: {integrity: sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==} 244 | dev: true 245 | 246 | /minimatch@9.0.3: 247 | resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} 248 | engines: {node: '>=16 || 14 >=14.17'} 249 | dependencies: 250 | brace-expansion: 2.0.1 251 | dev: true 252 | 253 | /minimist@1.2.8: 254 | resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} 255 | dev: true 256 | 257 | /minipass@7.0.4: 258 | resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} 259 | engines: {node: '>=16 || 14 >=14.17'} 260 | dev: true 261 | 262 | /path-key@3.1.1: 263 | resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} 264 | engines: {node: '>=8'} 265 | dev: true 266 | 267 | /path-scurry@1.10.1: 268 | resolution: {integrity: sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==} 269 | engines: {node: '>=16 || 14 >=14.17'} 270 | dependencies: 271 | lru-cache: 10.1.0 272 | minipass: 7.0.4 273 | dev: true 274 | 275 | /pyright@1.1.344: 276 | resolution: {integrity: sha512-K0nhCxUqoACGgyZO1VfWSx5NkT5VTe0VKblLu09RMPmrzdblZi8DbfU6Hy9OXMSe2sBbAEtK685QRVi05V98tA==} 277 | engines: {node: '>=12.0.0'} 278 | hasBin: true 279 | optionalDependencies: 280 | fsevents: 2.3.3 281 | dev: true 282 | 283 | /run-con@1.3.2: 284 | resolution: {integrity: sha512-CcfE+mYiTcKEzg0IqS08+efdnH0oJ3zV0wSUFBNrMHMuxCtXvBCLzCJHatwuXDcu/RlhjTziTo/a1ruQik6/Yg==} 285 | hasBin: true 286 | dependencies: 287 | deep-extend: 0.6.0 288 | ini: 4.1.1 289 | minimist: 1.2.8 290 | strip-json-comments: 3.1.1 291 | dev: true 292 | 293 | /shebang-command@2.0.0: 294 | resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} 295 | engines: {node: '>=8'} 296 | dependencies: 297 | shebang-regex: 3.0.0 298 | dev: true 299 | 300 | /shebang-regex@3.0.0: 301 | resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} 302 | engines: {node: '>=8'} 303 | dev: true 304 | 305 | /signal-exit@4.1.0: 306 | resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} 307 | engines: {node: '>=14'} 308 | dev: true 309 | 310 | /string-width@4.2.3: 311 | resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} 312 | engines: {node: '>=8'} 313 | dependencies: 314 | emoji-regex: 8.0.0 315 | is-fullwidth-code-point: 3.0.0 316 | strip-ansi: 6.0.1 317 | dev: true 318 | 319 | /string-width@5.1.2: 320 | resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} 321 | engines: {node: '>=12'} 322 | dependencies: 323 | eastasianwidth: 0.2.0 324 | emoji-regex: 9.2.2 325 | strip-ansi: 7.1.0 326 | dev: true 327 | 328 | /strip-ansi@6.0.1: 329 | resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} 330 | engines: {node: '>=8'} 331 | dependencies: 332 | ansi-regex: 5.0.1 333 | dev: true 334 | 335 | /strip-ansi@7.1.0: 336 | resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} 337 | engines: {node: '>=12'} 338 | dependencies: 339 | ansi-regex: 6.0.1 340 | dev: true 341 | 342 | /strip-json-comments@3.1.1: 343 | resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} 344 | engines: {node: '>=8'} 345 | dev: true 346 | 347 | /uc.micro@1.0.6: 348 | resolution: {integrity: sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==} 349 | dev: true 350 | 351 | /which@2.0.2: 352 | resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} 353 | engines: {node: '>= 8'} 354 | hasBin: true 355 | dependencies: 356 | isexe: 2.0.0 357 | dev: true 358 | 359 | /wrap-ansi@7.0.0: 360 | resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} 361 | engines: {node: '>=10'} 362 | dependencies: 363 | ansi-styles: 4.3.0 364 | string-width: 4.2.3 365 | strip-ansi: 6.0.1 366 | dev: true 367 | 368 | /wrap-ansi@8.1.0: 369 | resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} 370 | engines: {node: '>=12'} 371 | dependencies: 372 | ansi-styles: 6.2.1 373 | string-width: 5.1.2 374 | strip-ansi: 7.1.0 375 | dev: true 376 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "tsukaima" 3 | version = "1.2.0" 4 | description = "" 5 | authors = ["Yuta Hayashibe "] 6 | readme = "README.md" 7 | packages = [{include = "tsukaima"}] 8 | 9 | [tool.poetry.dependencies] 10 | python = ">=3.11,<3.12" 11 | transformers = ">=4.30.1" 12 | torch = ">=2.1.0" 13 | sentencepiece = "^0.1.99" 14 | accelerate = "^0.23.0" 15 | bitsandbytes = ">=0.39.0" 16 | scipy = "^1.10.1" 17 | pydantic = "^2.0.0" 18 | fastapi = ">=0.100.0b2" 19 | uvicorn = "^0.22.0" 20 | shortuuid = "^1.0.11" 21 | protobuf = "^4.24.2" 22 | 23 | 24 | [tool.poetry.scripts] 25 | tsukaima = "tsukaima.serve:main" 26 | 27 | [tool.poetry.group.dev.dependencies] 28 | ruff = "^0.1.13" 29 | 30 | [build-system] 31 | requires = ["poetry-core"] 32 | build-backend = "poetry.core.masonry.api" 33 | 34 | [tool.pyright] 35 | pythonVersion = "3.11" 36 | typeCheckingMode = "basic" 37 | exclude = ["**/third", ".venv", "**/node_modules", "**/__pycache__",] 38 | reportPrivateImportUsage = "information" 39 | reportUnusedVariable="warning" 40 | 41 | [tool.ruff] 42 | line-length = 120 43 | target-version = "py311" 44 | 45 | [tool.ruff.lint] 46 | select = ["E", "F", "W", "I", "B", "UP"] 47 | ignore = [] 48 | fixable = ["ALL"] 49 | -------------------------------------------------------------------------------- /tests/check_null.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | 5 | 6 | def main() -> None: 7 | data = sys.stdin.read() 8 | if len(data) != 0: 9 | sys.exit(1) 10 | 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /tsukaima/model.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from collections.abc import Iterator 3 | from threading import Thread 4 | from typing import Final 5 | 6 | from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer 7 | 8 | from tsukaima.schema.openai import ChatCompletionRequest, ChatMessage 9 | from tsukaima.schema.schema import Config, ConfigModel 10 | 11 | 12 | class Model: 13 | supported_config_version: Final[int] = 2 14 | 15 | @staticmethod 16 | def get_rinna_prompt( 17 | *, 18 | messages: list[ChatMessage], 19 | ) -> str: 20 | rinna_speaker_name_system: Final[str] = "システム" 21 | prompt: str = "" 22 | for uttr in messages: 23 | if uttr.role == "system": 24 | continue 25 | my_role: str = { 26 | "user": "ユーザー", 27 | "assistant": rinna_speaker_name_system, 28 | }[uttr.role] 29 | prompt += f"{my_role}: {uttr.content}" 30 | prompt += f"{rinna_speaker_name_system}: " 31 | return prompt 32 | 33 | @staticmethod 34 | def get_line_prompt( 35 | *, 36 | messages: list[ChatMessage], 37 | ) -> str: 38 | line_speaker_name_system: Final[str] = "システム" 39 | prompt: str = "" 40 | for uttr in messages: 41 | if uttr.role == "system": 42 | continue 43 | my_role: str = { 44 | "user": "ユーザー", 45 | "assistant": line_speaker_name_system, 46 | }[uttr.role] 47 | prompt += f"{my_role}: {uttr.content}\n" 48 | prompt += f"{line_speaker_name_system}: " 49 | return prompt 50 | 51 | @staticmethod 52 | def get_elyza_prompt( 53 | *, 54 | messages: list[ChatMessage], 55 | ) -> str: 56 | prev_role: str = "system" 57 | user_contents: list[str] = [] 58 | assistant_contents: list[str] = [] 59 | 60 | for uttr in messages: 61 | if uttr.role == "system": 62 | pass 63 | elif uttr.role == "user": 64 | if prev_role == "user": 65 | user_contents[-1] += f"\n{uttr.content}" 66 | elif prev_role in {"assistant", "system"}: 67 | user_contents.append(uttr.content) 68 | else: 69 | raise NotImplementedError(f"Unsupported prev_role: {prev_role}") 70 | 71 | elif uttr.role == "assistant": 72 | if prev_role in {"user", "system"}: 73 | assistant_contents.append(uttr.content) 74 | elif prev_role == "assistant": 75 | assistant_contents[-1] += f"\n{uttr.content}" 76 | else: 77 | raise NotImplementedError(f"Unsupported prev_role: {prev_role}") 78 | 79 | else: 80 | raise KeyError(uttr.role) 81 | prev_role = uttr.role 82 | 83 | bos_token: Final[str] = "" 84 | eos_token: Final[str] = "" 85 | default_system_prompt: Final[str] = "あなたは誠実で優秀な日本人のアシスタントです。" 86 | prompt: str = f"{bos_token}[INST] <>\n{default_system_prompt}\n<>\n\n" 87 | assert len(user_contents) == len(assistant_contents) + 1 88 | for user_input, assistant_resp in zip(user_contents, assistant_contents, strict=False): 89 | prompt += f"{user_input} [/INST] {assistant_resp.strip()} {eos_token}{bos_token}[INST] " 90 | 91 | prompt += f"{user_contents[-1]} [/INST]" 92 | return prompt 93 | 94 | @staticmethod 95 | def get_prompt( 96 | *, 97 | model_name: str, 98 | messages: list[ChatMessage], 99 | ) -> str: 100 | if model_name.startswith("rinna/"): 101 | return Model.get_rinna_prompt( 102 | messages=messages, 103 | ) 104 | elif model_name.startswith("line-corporation/"): 105 | return Model.get_line_prompt( 106 | messages=messages, 107 | ) 108 | elif model_name.startswith("elyza/"): 109 | return Model.get_elyza_prompt( 110 | messages=messages, 111 | ) 112 | 113 | raise KeyError(f"Unsupported model: {model_name}") 114 | 115 | def __init__(self, *, config: Config): 116 | assert config.version == Model.supported_config_version, f"Unsupported config version: {config.version}" 117 | 118 | self.name2model = {} 119 | self.name2tokenizer = {} 120 | self.name2config_model = {} 121 | 122 | for config_model in config.models: 123 | if not config_model.enabled: 124 | continue 125 | tokenizer = AutoTokenizer.from_pretrained( 126 | config_model.path, 127 | use_fast=False, 128 | **config_model.tokenizer_kwargs, 129 | ) 130 | model = AutoModelForCausalLM.from_pretrained( 131 | config_model.path, 132 | **config_model.model_kwargs, 133 | ) 134 | for _alt_name in config_model.names: 135 | self.name2model[_alt_name] = model 136 | self.name2tokenizer[_alt_name] = tokenizer 137 | self.name2config_model[_alt_name] = config_model 138 | 139 | def generate( 140 | self, 141 | *, 142 | request: ChatCompletionRequest, 143 | ) -> Iterator[str]: 144 | model_name: str = request.model 145 | tokenizer = self.name2tokenizer[model_name] 146 | model = self.name2model[model_name] 147 | config_model: ConfigModel = self.name2config_model[model_name] 148 | 149 | messages = [] 150 | assert isinstance(request.messages, list) 151 | for _msg in request.messages: 152 | messages.append(ChatMessage.parse_obj(_msg)) 153 | prompt: str = Model.get_prompt( 154 | model_name=config_model.path, 155 | messages=messages, 156 | ) 157 | 158 | token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt") 159 | streamer = TextIteratorStreamer(tokenizer, skip_prompt=True) 160 | 161 | generation_args = [token_ids.to(model.device)] 162 | generation_kwargs = dict( 163 | streamer=streamer, 164 | do_sample=True, 165 | max_new_tokens=config_model.forced_parameters.get( 166 | "max_new_tokens", 167 | 256, # FIXME 168 | ), 169 | temperature=config_model.forced_parameters.get("temperature", request.temperature), 170 | pad_token_id=tokenizer.pad_token_id, 171 | bos_token_id=tokenizer.bos_token_id, 172 | eos_token_id=tokenizer.eos_token_id, 173 | repetition_penalty=config_model.forced_parameters.get("repetition_penalty", request.frequency_penalty), 174 | ) 175 | 176 | thread = Thread( 177 | target=model.generate, 178 | args=generation_args, 179 | kwargs=generation_kwargs, 180 | ) 181 | thread.start() 182 | 183 | for next_text in streamer: 184 | if not next_text: 185 | continue 186 | t: str = next_text.replace("", "\n") 187 | t = t.rstrip("") # TODO: make this more general 188 | yield t 189 | -------------------------------------------------------------------------------- /tsukaima/schema/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shirayu/tsukaima/2d06d84cdbdeac9069c779d2aa1ee562a2dbdd09/tsukaima/schema/__init__.py -------------------------------------------------------------------------------- /tsukaima/schema/openai.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # This code comes from fastchat/protocol/openai_api_protocol.py licensed under Apache-2.0 license. 4 | # https://github.com/lm-sys/FastChat 5 | 6 | import time 7 | from typing import Literal 8 | 9 | import shortuuid 10 | from pydantic import BaseModel, Field 11 | 12 | 13 | class ErrorResponse(BaseModel): 14 | object: str = "error" 15 | message: str 16 | code: int 17 | 18 | 19 | class ChatCompletionRequest(BaseModel): 20 | model: str 21 | messages: str | list[dict[str, str]] 22 | temperature: float | None = 0.7 23 | top_p: float | None = 1.0 24 | n: int | None = 1 25 | max_tokens: int | None = None 26 | stop: str | list[str] | None = None 27 | stream: bool | None = False 28 | presence_penalty: float | None = 0.0 29 | frequency_penalty: float | None = 0.0 30 | user: str | None = None 31 | 32 | 33 | class ChatMessage(BaseModel): 34 | role: str 35 | content: str 36 | 37 | 38 | class ChatCompletionResponseChoice(BaseModel): 39 | index: int 40 | message: ChatMessage 41 | finish_reason: Literal["stop", "length"] | None 42 | 43 | 44 | class UsageInfo(BaseModel): 45 | prompt_tokens: int = 0 46 | total_tokens: int = 0 47 | completion_tokens: int | None = 0 48 | 49 | 50 | class ChatCompletionResponse(BaseModel): 51 | id: str = Field(default_factory=lambda: f"chatcmpl-{shortuuid.random()}") 52 | object: str = "chat.completion" 53 | created: int = Field(default_factory=lambda: int(time.time())) 54 | model: str 55 | choices: list[ChatCompletionResponseChoice] 56 | usage: UsageInfo 57 | 58 | 59 | class DeltaMessage(BaseModel): 60 | role: str | None = None 61 | content: str | None = None 62 | 63 | 64 | class ChatCompletionResponseStreamChoice(BaseModel): 65 | index: int 66 | delta: DeltaMessage 67 | finish_reason: Literal["stop", "length"] | None 68 | 69 | 70 | class ChatCompletionStreamResponse(BaseModel): 71 | id: str = Field(default_factory=lambda: f"chatcmpl-{shortuuid.random()}") 72 | object: str = "chat.completion.chunk" 73 | created: int = Field(default_factory=lambda: int(time.time())) 74 | model: str 75 | choices: list[ChatCompletionResponseStreamChoice] 76 | -------------------------------------------------------------------------------- /tsukaima/schema/schema.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from typing import Any 3 | 4 | from pydantic import BaseModel 5 | 6 | 7 | class ConfigModel(BaseModel): 8 | path: str 9 | names: list[str] 10 | forced_parameters: dict[str, Any] 11 | model_kwargs: dict[str, Any] 12 | tokenizer_kwargs: dict[str, Any] 13 | enabled: bool = True 14 | 15 | 16 | class Config(BaseModel): 17 | version: int 18 | models: list[ConfigModel] 19 | -------------------------------------------------------------------------------- /tsukaima/serve.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import argparse 3 | import json 4 | from pathlib import Path 5 | 6 | import uvicorn 7 | from fastapi import FastAPI, Request 8 | from fastapi.middleware.cors import CORSMiddleware 9 | from fastapi.responses import StreamingResponse 10 | 11 | from tsukaima.model import Model 12 | from tsukaima.schema.openai import ( 13 | ChatCompletionRequest, 14 | ChatCompletionResponse, 15 | ChatCompletionResponseChoice, 16 | ChatMessage, 17 | UsageInfo, 18 | ) 19 | from tsukaima.schema.schema import Config 20 | from tsukaima.streamer import chat_completion_stream_generator 21 | 22 | 23 | def get_app(config: Config): 24 | model = Model(config=config) 25 | 26 | app = FastAPI( 27 | title="Tsukaima", 28 | ) 29 | 30 | @app.post("/v1/chat/completions") 31 | async def chat_completions( 32 | req: ChatCompletionRequest, 33 | request: Request, 34 | ): 35 | if req.stream: 36 | generator = chat_completion_stream_generator( 37 | model=model, 38 | request=req, 39 | raw_request=request, 40 | ) 41 | return StreamingResponse(generator, media_type="text/event-stream") 42 | 43 | choices = [] 44 | 45 | full_text: str = "".join( 46 | [ 47 | text 48 | for text in model.generate( 49 | request=req, 50 | ) 51 | ] 52 | ) 53 | usage = UsageInfo() 54 | choices.append( 55 | ChatCompletionResponseChoice( 56 | index=0, 57 | message=ChatMessage(role="assistant", content=full_text), 58 | finish_reason="stop", 59 | ) 60 | ) 61 | return ChatCompletionResponse( 62 | model=req.model, 63 | choices=choices, 64 | usage=usage, 65 | ) 66 | 67 | return app 68 | 69 | 70 | def get_opts() -> argparse.Namespace: 71 | parser = argparse.ArgumentParser() 72 | parser.add_argument("--host", default="0.0.0.0") 73 | parser.add_argument("--port", default=6006, type=int) 74 | parser.add_argument("--config", type=Path, required=True) 75 | parser.add_argument("--root_path", default="") 76 | 77 | parser.add_argument("--allow-credentials", action="store_true", help="allow credentials") 78 | parser.add_argument("--allowed-origins", type=json.loads, default=["*"], help="allowed origins") 79 | parser.add_argument("--allowed-methods", type=json.loads, default=["*"], help="allowed methods") 80 | parser.add_argument("--allowed-headers", type=json.loads, default=["*"], help="allowed headers") 81 | return parser.parse_args() 82 | 83 | 84 | def main(): 85 | opts = get_opts() 86 | 87 | config: Config = Config.parse_file(opts.config) 88 | app = get_app(config) 89 | 90 | app.add_middleware( 91 | CORSMiddleware, 92 | allow_origins=opts.allowed_origins, 93 | allow_credentials=opts.allow_credentials, 94 | allow_methods=opts.allowed_methods, 95 | allow_headers=opts.allowed_headers, 96 | ) 97 | 98 | uvicorn.run( 99 | app, # type: ignore 100 | host=opts.host, 101 | port=opts.port, 102 | root_path=opts.root_path, 103 | ) 104 | 105 | 106 | if __name__ == "__main__": 107 | main() 108 | -------------------------------------------------------------------------------- /tsukaima/streamer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # This code comes from fastchat/serve/openai_api_server.py licensed under Apache-2.0 license. 4 | # https://github.com/lm-sys/FastChat 5 | 6 | import json 7 | from collections.abc import AsyncGenerator, Iterator 8 | from typing import Any 9 | 10 | import shortuuid 11 | from fastapi import Request 12 | 13 | from tsukaima.model import Model 14 | from tsukaima.schema.openai import ( 15 | ChatCompletionRequest, 16 | ChatCompletionResponseStreamChoice, 17 | ChatCompletionStreamResponse, 18 | DeltaMessage, 19 | ) 20 | 21 | 22 | def chat_completion_stream( 23 | *, 24 | model: Model, 25 | request: ChatCompletionRequest, 26 | ) -> Iterator[dict[str, Any]]: 27 | full_text: str = "" 28 | for text in model.generate( 29 | request=request, 30 | ): 31 | full_text += text 32 | yield { 33 | "error_code": 0, 34 | "text": full_text, 35 | } 36 | 37 | 38 | async def chat_completion_stream_generator( 39 | *, 40 | model: Model, 41 | request: ChatCompletionRequest, 42 | raw_request: Request, 43 | ) -> AsyncGenerator[str, Any]: 44 | id = f"chatcmpl-{shortuuid.random()}" 45 | finish_stream_events = [] 46 | for i in range(1): 47 | # First chunk with role 48 | choice_data = ChatCompletionResponseStreamChoice( 49 | index=i, 50 | delta=DeltaMessage(role="assistant"), 51 | finish_reason=None, 52 | ) 53 | chunk = ChatCompletionStreamResponse( 54 | id=id, 55 | choices=[choice_data], 56 | model=request.model, 57 | ) 58 | yield f"data: {chunk.json(exclude_unset=True)}\n\n" 59 | 60 | previous_text = "" 61 | for content in chat_completion_stream( 62 | model=model, 63 | request=request, 64 | ): 65 | if content["error_code"] != 0 or await raw_request.is_disconnected(): 66 | yield f"data: {json.dumps(content)}\n\n" 67 | yield "data: [DONE]\n\n" 68 | return 69 | decoded_unicode = content["text"].replace("\ufffd", "") 70 | delta_text = decoded_unicode[len(previous_text) :] 71 | previous_text = decoded_unicode 72 | 73 | if len(delta_text) == 0: 74 | delta_text = None 75 | choice_data = ChatCompletionResponseStreamChoice( 76 | index=i, 77 | delta=DeltaMessage(content=delta_text), 78 | finish_reason=content.get("finish_reason", None), 79 | ) 80 | chunk = ChatCompletionStreamResponse(id=id, choices=[choice_data], model=request.model) 81 | if delta_text is None: 82 | if content.get("finish_reason", None) is not None: 83 | finish_stream_events.append(chunk) 84 | continue 85 | yield f"data: {chunk.json(exclude_unset=True)}\n\n" 86 | # There is not "content" field in the last delta message, so exclude_none to exclude field "content". 87 | for finish_chunk in finish_stream_events: 88 | yield f"data: {finish_chunk.json(exclude_none=True)}\n\n" 89 | yield "data: [DONE]\n\n" 90 | --------------------------------------------------------------------------------