Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/dify_plugin/interfaces/model/openai_compatible/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def validate_credentials(self, model: str, credentials: dict) -> None:
"""
try:
headers = {"Content-Type": "application/json"}
extra_headers = credentials.get("extra_headers")
if extra_headers is not None:
headers = {
**headers,
**extra_headers,
}
Comment on lines +176 to +181

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the current implementation is correct, it can be made more concise and idiomatic by using dict.update(). This approach modifies the headers dictionary in-place, which is slightly more efficient as it avoids creating a new dictionary object.

For consistency, you might consider applying the same refactoring to the _generate method where a similar pattern exists (lines 415-420).

            extra_headers = credentials.get("extra_headers")
            if extra_headers:
                headers.update(extra_headers)


api_key = credentials.get("api_key")
if api_key:
Expand Down