mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
Merge branch 'fix/refresh-token' into deploy/dev
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
This commit is contained in:
commit
d932e6ab81
|
@ -21,7 +21,7 @@ class EnterpriseWorkspace(Resource):
|
||||||
if account is None:
|
if account is None:
|
||||||
return {"message": "owner account not found."}, 404
|
return {"message": "owner account not found."}, 404
|
||||||
|
|
||||||
tenant = TenantService.create_tenant(args["name"])
|
tenant = TenantService.create_tenant(args["name"], is_from_dashboard=True)
|
||||||
TenantService.create_tenant_member(tenant, account, role="owner")
|
TenantService.create_tenant_member(tenant, account, role="owner")
|
||||||
|
|
||||||
tenant_was_created.send(tenant)
|
tenant_was_created.send(tenant)
|
||||||
|
|
|
@ -53,6 +53,9 @@ model_credential_schema:
|
||||||
type: select
|
type: select
|
||||||
required: true
|
required: true
|
||||||
options:
|
options:
|
||||||
|
- label:
|
||||||
|
en_US: 2024-10-01-preview
|
||||||
|
value: 2024-10-01-preview
|
||||||
- label:
|
- label:
|
||||||
en_US: 2024-09-01-preview
|
en_US: 2024-09-01-preview
|
||||||
value: 2024-09-01-preview
|
value: 2024-09-01-preview
|
||||||
|
|
|
@ -45,9 +45,7 @@ class AzureOpenAILargeLanguageModel(_CommonAzureOpenAI, LargeLanguageModel):
|
||||||
stream: bool = True,
|
stream: bool = True,
|
||||||
user: Optional[str] = None,
|
user: Optional[str] = None,
|
||||||
) -> Union[LLMResult, Generator]:
|
) -> Union[LLMResult, Generator]:
|
||||||
base_model_name = credentials.get("base_model_name")
|
base_model_name = self._get_base_model_name(credentials)
|
||||||
if not base_model_name:
|
|
||||||
raise ValueError("Base Model Name is required")
|
|
||||||
ai_model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
ai_model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
||||||
|
|
||||||
if ai_model_entity and ai_model_entity.entity.model_properties.get(ModelPropertyKey.MODE) == LLMMode.CHAT.value:
|
if ai_model_entity and ai_model_entity.entity.model_properties.get(ModelPropertyKey.MODE) == LLMMode.CHAT.value:
|
||||||
|
@ -81,9 +79,7 @@ class AzureOpenAILargeLanguageModel(_CommonAzureOpenAI, LargeLanguageModel):
|
||||||
prompt_messages: list[PromptMessage],
|
prompt_messages: list[PromptMessage],
|
||||||
tools: Optional[list[PromptMessageTool]] = None,
|
tools: Optional[list[PromptMessageTool]] = None,
|
||||||
) -> int:
|
) -> int:
|
||||||
base_model_name = credentials.get("base_model_name")
|
base_model_name = self._get_base_model_name(credentials)
|
||||||
if not base_model_name:
|
|
||||||
raise ValueError("Base Model Name is required")
|
|
||||||
model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
||||||
if not model_entity:
|
if not model_entity:
|
||||||
raise ValueError(f"Base Model Name {base_model_name} is invalid")
|
raise ValueError(f"Base Model Name {base_model_name} is invalid")
|
||||||
|
@ -108,9 +104,7 @@ class AzureOpenAILargeLanguageModel(_CommonAzureOpenAI, LargeLanguageModel):
|
||||||
if "base_model_name" not in credentials:
|
if "base_model_name" not in credentials:
|
||||||
raise CredentialsValidateFailedError("Base Model Name is required")
|
raise CredentialsValidateFailedError("Base Model Name is required")
|
||||||
|
|
||||||
base_model_name = credentials.get("base_model_name")
|
base_model_name = self._get_base_model_name(credentials)
|
||||||
if not base_model_name:
|
|
||||||
raise CredentialsValidateFailedError("Base Model Name is required")
|
|
||||||
ai_model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
ai_model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
||||||
|
|
||||||
if not ai_model_entity:
|
if not ai_model_entity:
|
||||||
|
@ -149,9 +143,7 @@ class AzureOpenAILargeLanguageModel(_CommonAzureOpenAI, LargeLanguageModel):
|
||||||
raise CredentialsValidateFailedError(str(ex))
|
raise CredentialsValidateFailedError(str(ex))
|
||||||
|
|
||||||
def get_customizable_model_schema(self, model: str, credentials: dict) -> Optional[AIModelEntity]:
|
def get_customizable_model_schema(self, model: str, credentials: dict) -> Optional[AIModelEntity]:
|
||||||
base_model_name = credentials.get("base_model_name")
|
base_model_name = self._get_base_model_name(credentials)
|
||||||
if not base_model_name:
|
|
||||||
raise ValueError("Base Model Name is required")
|
|
||||||
ai_model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
ai_model_entity = self._get_ai_model_entity(base_model_name=base_model_name, model=model)
|
||||||
return ai_model_entity.entity if ai_model_entity else None
|
return ai_model_entity.entity if ai_model_entity else None
|
||||||
|
|
||||||
|
@ -308,11 +300,6 @@ class AzureOpenAILargeLanguageModel(_CommonAzureOpenAI, LargeLanguageModel):
|
||||||
|
|
||||||
if tools:
|
if tools:
|
||||||
extra_model_kwargs["tools"] = [helper.dump_model(PromptMessageFunction(function=tool)) for tool in tools]
|
extra_model_kwargs["tools"] = [helper.dump_model(PromptMessageFunction(function=tool)) for tool in tools]
|
||||||
# extra_model_kwargs['functions'] = [{
|
|
||||||
# "name": tool.name,
|
|
||||||
# "description": tool.description,
|
|
||||||
# "parameters": tool.parameters
|
|
||||||
# } for tool in tools]
|
|
||||||
|
|
||||||
if stop:
|
if stop:
|
||||||
extra_model_kwargs["stop"] = stop
|
extra_model_kwargs["stop"] = stop
|
||||||
|
@ -769,3 +756,9 @@ class AzureOpenAILargeLanguageModel(_CommonAzureOpenAI, LargeLanguageModel):
|
||||||
ai_model_entity_copy.entity.label.en_US = model
|
ai_model_entity_copy.entity.label.en_US = model
|
||||||
ai_model_entity_copy.entity.label.zh_Hans = model
|
ai_model_entity_copy.entity.label.zh_Hans = model
|
||||||
return ai_model_entity_copy
|
return ai_model_entity_copy
|
||||||
|
|
||||||
|
def _get_base_model_name(self, credentials: dict) -> str:
|
||||||
|
base_model_name = credentials.get("base_model_name")
|
||||||
|
if not base_model_name:
|
||||||
|
raise ValueError("Base Model Name is required")
|
||||||
|
return base_model_name
|
||||||
|
|
|
@ -204,7 +204,7 @@ class ToolParameter(BaseModel):
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
raise ValueError(f"The tool parameter value {value} is not in correct type of {parameter_type}.")
|
raise ValueError(f"The tool parameter value {value} is not in correct type.")
|
||||||
|
|
||||||
class ToolParameterForm(Enum):
|
class ToolParameterForm(Enum):
|
||||||
SCHEMA = "schema" # should be set while adding tool
|
SCHEMA = "schema" # should be set while adding tool
|
||||||
|
|
|
@ -5,9 +5,12 @@ import requests
|
||||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||||
from core.tools.tool.builtin_tool import BuiltinTool
|
from core.tools.tool.builtin_tool import BuiltinTool
|
||||||
|
|
||||||
SDURL = {
|
SILICONFLOW_API_URL = "https://api.siliconflow.cn/v1/image/generations"
|
||||||
"sd_3": "https://api.siliconflow.cn/v1/stabilityai/stable-diffusion-3-medium/text-to-image",
|
|
||||||
"sd_xl": "https://api.siliconflow.cn/v1/stabilityai/stable-diffusion-xl-base-1.0/text-to-image",
|
SD_MODELS = {
|
||||||
|
"sd_3": "stabilityai/stable-diffusion-3-medium",
|
||||||
|
"sd_xl": "stabilityai/stable-diffusion-xl-base-1.0",
|
||||||
|
"sd_3.5_large": "stabilityai/stable-diffusion-3-5-large",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,9 +25,10 @@ class StableDiffusionTool(BuiltinTool):
|
||||||
}
|
}
|
||||||
|
|
||||||
model = tool_parameters.get("model", "sd_3")
|
model = tool_parameters.get("model", "sd_3")
|
||||||
url = SDURL.get(model)
|
sd_model = SD_MODELS.get(model)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
|
"model": sd_model,
|
||||||
"prompt": tool_parameters.get("prompt"),
|
"prompt": tool_parameters.get("prompt"),
|
||||||
"negative_prompt": tool_parameters.get("negative_prompt", ""),
|
"negative_prompt": tool_parameters.get("negative_prompt", ""),
|
||||||
"image_size": tool_parameters.get("image_size", "1024x1024"),
|
"image_size": tool_parameters.get("image_size", "1024x1024"),
|
||||||
|
@ -34,7 +38,7 @@ class StableDiffusionTool(BuiltinTool):
|
||||||
"num_inference_steps": tool_parameters.get("num_inference_steps", 20),
|
"num_inference_steps": tool_parameters.get("num_inference_steps", 20),
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(url, json=payload, headers=headers)
|
response = requests.post(SILICONFLOW_API_URL, json=payload, headers=headers)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return self.create_text_message(f"Got Error Response:{response.text}")
|
return self.create_text_message(f"Got Error Response:{response.text}")
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ parameters:
|
||||||
- value: sd_xl
|
- value: sd_xl
|
||||||
label:
|
label:
|
||||||
en_US: Stable Diffusion XL
|
en_US: Stable Diffusion XL
|
||||||
|
- value: sd_3.5_large
|
||||||
|
label:
|
||||||
|
en_US: Stable Diffusion 3.5 Large
|
||||||
default: sd_3
|
default: sd_3
|
||||||
label:
|
label:
|
||||||
en_US: Choose Image Model
|
en_US: Choose Image Model
|
||||||
|
|
|
@ -486,9 +486,13 @@ def _get_login_cache_key(*, account_id: str, token: str):
|
||||||
|
|
||||||
class TenantService:
|
class TenantService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_tenant(name: str, is_setup: Optional[bool] = False) -> Tenant:
|
def create_tenant(name: str, is_setup: Optional[bool] = False, is_from_dashboard: Optional[bool] = False) -> Tenant:
|
||||||
"""Create tenant"""
|
"""Create tenant"""
|
||||||
if not FeatureService.get_system_features().is_allow_create_workspace and not is_setup:
|
if (
|
||||||
|
not FeatureService.get_system_features().is_allow_create_workspace
|
||||||
|
and not is_setup
|
||||||
|
and not is_from_dashboard
|
||||||
|
):
|
||||||
from controllers.console.error import NotAllowedCreateWorkspace
|
from controllers.console.error import NotAllowedCreateWorkspace
|
||||||
|
|
||||||
raise NotAllowedCreateWorkspace()
|
raise NotAllowedCreateWorkspace()
|
||||||
|
|
|
@ -41,6 +41,7 @@ const useRefreshToken = () => {
|
||||||
return new Error('No access token or refresh token found')
|
return new Error('No access token or refresh token found')
|
||||||
}
|
}
|
||||||
if (localStorage?.getItem('is_refreshing') === '1') {
|
if (localStorage?.getItem('is_refreshing') === '1') {
|
||||||
|
clearTimeout(timer.current)
|
||||||
timer.current = setTimeout(() => {
|
timer.current = setTimeout(() => {
|
||||||
getNewAccessToken()
|
getNewAccessToken()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
@ -61,12 +62,14 @@ const useRefreshToken = () => {
|
||||||
localStorage?.setItem('console_token', access_token)
|
localStorage?.setItem('console_token', access_token)
|
||||||
localStorage?.setItem('refresh_token', refresh_token)
|
localStorage?.setItem('refresh_token', refresh_token)
|
||||||
const newTokenExpireTime = getExpireTime(access_token)
|
const newTokenExpireTime = getExpireTime(access_token)
|
||||||
|
clearTimeout(timer.current)
|
||||||
timer.current = setTimeout(() => {
|
timer.current = setTimeout(() => {
|
||||||
getNewAccessToken()
|
getNewAccessToken()
|
||||||
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const newTokenExpireTime = getExpireTime(currentAccessToken)
|
const newTokenExpireTime = getExpireTime(currentAccessToken)
|
||||||
|
clearTimeout(timer.current)
|
||||||
timer.current = setTimeout(() => {
|
timer.current = setTimeout(() => {
|
||||||
getNewAccessToken()
|
getNewAccessToken()
|
||||||
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
||||||
|
@ -74,8 +77,15 @@ const useRefreshToken = () => {
|
||||||
return null
|
return null
|
||||||
}, [getExpireTime, getCurrentTimeStamp, handleError])
|
}, [getExpireTime, getCurrentTimeStamp, handleError])
|
||||||
|
|
||||||
|
const handleVisibilityChange = useCallback(() => {
|
||||||
|
if (document.visibilityState === 'visible')
|
||||||
|
getNewAccessToken()
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
window.addEventListener('visibilitychange', handleVisibilityChange)
|
||||||
return () => {
|
return () => {
|
||||||
|
window.removeEventListener('visibilitychange', handleVisibilityChange)
|
||||||
clearTimeout(timer.current)
|
clearTimeout(timer.current)
|
||||||
localStorage?.removeItem('is_refreshing')
|
localStorage?.removeItem('is_refreshing')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user