Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests for validating the changes?
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?
Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
BREAKING CHANGE: Significant changes that may affect compatibility
build: Changes that affect the build system or external dependencies
ci: Changes to our continuous integration processes or workflows
chore: Refactor, cleanup, or other non-functional code changes
docs: Documentation update or addition
feat: Introduces a new feature or enhancement to the codebase
fix: Bug fix or error correction
i18n: Internationalization or localization changes
perf: Performance improvement
refactor: Code restructuring for better maintainability, readability, or scalability
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
test: Adding missing tests or correcting existing tests
WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
While using OpenWebUI a user normally wants to set the max tokens in order to control the length of the output. However, OpenWebUI has a bug since at the very least a month which resulted in this value not being set. The fix was to add it to the apply_params_to_form_data methode in the middleware.
Fixed
max_tokens wasn't being set for any requests
Additional Information
Please note, I wasn't able to test if parameters like max_completion_tokens work as intended, as I do not use the OpenAI API.
If someone with access to the OpenAI API would be able to check if the max_completion_tokens parameter is being used properly, that would be lovely. If it has the same issue, please let me know so I can add it in the method as well, or feel free to add it yourself.
Also, some room for discussion with the authors / contributes:
In this method which contained the bug, why are the form data values being set manually and only ollama is using all parameters?
defapply_params_to_form_data(form_data,model):params=form_data.pop("params",{})ifmodel.get("ollama"):form_data["options"]=params# <----- Note this line, which is only used when using ollamaif"format"inparams:form_data["format"]=params["format"]if"keep_alive"inparams:form_data["keep_alive"]=params["keep_alive"]else:if"seed"inparams:form_data["seed"]=params["seed"]if"stop"inparams:form_data["stop"]=params["stop"]if"temperature"inparams:form_data["temperature"]=params["temperature"]if"max_tokens"inparams:form_data["max_tokens"]=params["max_tokens"]if"top_p"inparams:form_data["top_p"]=params["top_p"]if"frequency_penalty"inparams:form_data["frequency_penalty"]=params["frequency_penalty"]if"reasoning_effort"inparams:form_data["reasoning_effort"]=params["reasoning_effort"]returnform_data
If that's not possible, this might happen again in the future as all new parameters have to added there one by one. So a better solution would probably be required.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/9082
**Author:** [@Alex1607](https://github.com/Alex1607)
**Created:** 1/29/2025
**Status:** ✅ Merged
**Merged:** 1/29/2025
**Merged by:** [@tjbck](https://github.com/tjbck)
**Base:** `dev` ← **Head:** `main`
---
### 📝 Commits (1)
- [`c2e742a`](https://github.com/open-webui/open-webui/commit/c2e742afe1f525841902d2b0360025974e54a4b6) Fix max_tokens not being set properly
### 📊 Changes
**1 file changed** (+3 additions, -0 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/utils/middleware.py` (+3 -0)
</details>
### 📄 Description
# Pull Request Checklist
### 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.
**Before submitting, make sure you've checked the following:**
- [x] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [x] **Description:** Provide a concise description of the changes made in this pull request.
- [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [x] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
- [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Have you written and run sufficient tests for validating the changes?
- [x] **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?
- [x] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following:
- **BREAKING CHANGE**: Significant changes that may affect compatibility
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our continuous integration processes or workflows
- **chore**: Refactor, cleanup, or other non-functional code changes
- **docs**: Documentation update or addition
- **feat**: Introduces a new feature or enhancement to the codebase
- **fix**: Bug fix or error correction
- **i18n**: Internationalization or localization changes
- **perf**: Performance improvement
- **refactor**: Code restructuring for better maintainability, readability, or scalability
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
- **test**: Adding missing tests or correcting existing tests
- **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
While using OpenWebUI a user normally wants to set the max tokens in order to control the length of the output. However, OpenWebUI has a bug since at the very least a month which resulted in this value not being set. The fix was to add it to the `apply_params_to_form_data` methode in the middleware.
### Fixed
- `max_tokens` wasn't being set for any requests
---
### Additional Information
Please note, I wasn't able to test if parameters like `max_completion_tokens` work as intended, as I do not use the OpenAI API.
If someone with access to the OpenAI API would be able to check if the `max_completion_tokens` parameter is being used properly, that would be lovely. If it has the same issue, please let me know so I can add it in the method as well, or feel free to add it yourself.
Also, some room for discussion with the authors / contributes:
In this method which contained the bug, why are the form data values being set manually and only ollama is using *all* parameters?
```python
def apply_params_to_form_data(form_data, model):
params = form_data.pop("params", {})
if model.get("ollama"):
form_data["options"] = params # <----- Note this line, which is only used when using ollama
if "format" in params:
form_data["format"] = params["format"]
if "keep_alive" in params:
form_data["keep_alive"] = params["keep_alive"]
else:
if "seed" in params:
form_data["seed"] = params["seed"]
if "stop" in params:
form_data["stop"] = params["stop"]
if "temperature" in params:
form_data["temperature"] = params["temperature"]
if "max_tokens" in params:
form_data["max_tokens"] = params["max_tokens"]
if "top_p" in params:
form_data["top_p"] = params["top_p"]
if "frequency_penalty" in params:
form_data["frequency_penalty"] = params["frequency_penalty"]
if "reasoning_effort" in params:
form_data["reasoning_effort"] = params["reasoning_effort"]
return form_data
```
Can't this method be shortened to:
```python
def apply_params_to_form_data(form_data, model):
params = form_data.pop("params", {})
form_data["options"] = params
if model.get("ollama"):
if "format" in params:
form_data["format"] = params["format"]
if "keep_alive" in params:
form_data["keep_alive"] = params["keep_alive"]
return form_data
```
If that's not possible, this might happen again in the future as all new parameters have to added there one by one. So a better solution would probably be required.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/9082
Author: @Alex1607
Created: 1/29/2025
Status: ✅ Merged
Merged: 1/29/2025
Merged by: @tjbck
Base:
dev← Head:main📝 Commits (1)
c2e742aFix max_tokens not being set properly📊 Changes
1 file changed (+3 additions, -0 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+3 -0)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
While using OpenWebUI a user normally wants to set the max tokens in order to control the length of the output. However, OpenWebUI has a bug since at the very least a month which resulted in this value not being set. The fix was to add it to the
apply_params_to_form_datamethode in the middleware.Fixed
max_tokenswasn't being set for any requestsAdditional Information
Please note, I wasn't able to test if parameters like
max_completion_tokenswork as intended, as I do not use the OpenAI API.If someone with access to the OpenAI API would be able to check if the
max_completion_tokensparameter is being used properly, that would be lovely. If it has the same issue, please let me know so I can add it in the method as well, or feel free to add it yourself.Also, some room for discussion with the authors / contributes:
In this method which contained the bug, why are the form data values being set manually and only ollama is using all parameters?
Can't this method be shortened to:
If that's not possible, this might happen again in the future as all new parameters have to added there one by one. So a better solution would probably be required.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.