Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions python/dify_plugin/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class DifyPluginEnv(BaseSettings):

DIFY_PLUGIN_DAEMON_URL: str = Field(default="http://localhost:5002", description="backwards invocation address")

HTTPX_TIMEOUT: int = Field(default=5, description="HTTPX timeout in seconds")

model_config = SettingsConfigDict(
# read from dotenv format config file
env_file=".env",
Expand Down
5 changes: 4 additions & 1 deletion python/dify_plugin/file/file.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import httpx
from pydantic import BaseModel

from dify_plugin.config.config import DifyPluginEnv
from dify_plugin.file.constants import DIFY_FILE_IDENTITY
from dify_plugin.file.entities import FileType

_plugin_config = DifyPluginEnv()
Comment thread
Stream29 marked this conversation as resolved.


class File(BaseModel):
dify_model_identity: str = DIFY_FILE_IDENTITY
Expand All @@ -30,7 +33,7 @@ def blob(self) -> bytes:
"""
if self._blob is None:
try:
response = httpx.get(self.url)
response = httpx.get(self.url, timeout=_plugin_config.HTTPX_TIMEOUT)
response.raise_for_status()
self._blob = response.content
except httpx.UnsupportedProtocol as e:
Expand Down
1 change: 1 addition & 0 deletions python/dify_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def _execute_request(
endpoint_id=endpoint_id,
context=context,
max_invocation_timeout=self.config.MAX_INVOCATION_TIMEOUT,
httpx_timeout=self.config.HTTPX_TIMEOUT,
Comment thread
Stream29 marked this conversation as resolved.
)
response = self.dispatch(session, data)
if response:
Expand Down
4 changes: 4 additions & 0 deletions python/examples/jina/models/rerank/rerank.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import httpx

from dify_plugin import RerankModel
from dify_plugin.config.config import DifyPluginEnv
from dify_plugin.entities import I18nObject
from dify_plugin.entities.model import (
AIModelEntity,
Expand All @@ -22,6 +23,8 @@
InvokeServerUnavailableError,
)

_plugin_config = DifyPluginEnv()
Comment thread
Stream29 marked this conversation as resolved.


class JinaRerankModel(RerankModel):
"""
Expand Down Expand Up @@ -66,6 +69,7 @@ def _invoke(
"top_n": top_n,
},
headers={"Authorization": f"Bearer {credentials.get('api_key')}"},
timeout=_plugin_config.HTTPX_TIMEOUT,
)
response.raise_for_status()
results = response.json()
Expand Down
Loading