Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Nov 24, 2024
1 parent 096c0ad commit 3997068
Show file tree
Hide file tree
Showing 81 changed files with 271 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-poetry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
python-version:
description: Python version to use and the Poetry installed with
required: true
default: '3.10'
default: '3.11'
poetry-version:
description: Poetry version to set up
required: true
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/vdb-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

Expand Down
8 changes: 5 additions & 3 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import os
import sys

python_version = sys.version_info
if not ((3, 11) <= python_version < (3, 13)):
print(f"Python 3.11 or 3.12 is required, current version is {python_version.major}.{python_version.minor}")
raise SystemExit(1)

from configs import dify_config

if not dify_config.DEBUG:
Expand Down Expand Up @@ -30,9 +35,6 @@

# DO NOT REMOVE ABOVE

if sys.version_info[:2] == (3, 10):
print("Warning: Python 3.10 will not be supported in the next version.")


warnings.simplefilter("ignore", ResourceWarning)

Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/app/conversation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

import pytz
from flask_login import current_user
Expand Down Expand Up @@ -314,7 +314,7 @@ def _get_conversation(app_model, conversation_id):
raise NotFound("Conversation Not Exists.")

if not conversation.read_at:
conversation.read_at = datetime.now(timezone.utc).replace(tzinfo=None)
conversation.read_at = datetime.now(UTC).replace(tzinfo=None)
conversation.read_account_id = current_user.id
db.session.commit()

Expand Down
6 changes: 3 additions & 3 deletions api/controllers/console/app/site.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask_login import current_user
from flask_restful import Resource, marshal_with, reqparse
Expand Down Expand Up @@ -75,7 +75,7 @@ def post(self, app_model):
setattr(site, attr_name, value)

site.updated_by = current_user.id
site.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
site.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return site
Expand All @@ -99,7 +99,7 @@ def post(self, app_model):

site.code = Site.generate_code(16)
site.updated_by = current_user.id
site.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
site.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return site
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/auth/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def post(self):
account.timezone = args["timezone"]
account.interface_theme = "light"
account.status = AccountStatus.ACTIVE.value
account.initialized_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
account.initialized_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.commit()

token_pair = AccountService.login(account, ip_address=extract_remote_ip(request))
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/auth/oauth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Optional

import requests
Expand Down Expand Up @@ -106,7 +106,7 @@ def get(self, provider: str):

if account.status == AccountStatus.PENDING.value:
account.status = AccountStatus.ACTIVE.value
account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None)
account.initialized_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

try:
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/datasets/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def patch(self, binding_id, action):
if action == "enable":
if data_source_binding.disabled:
data_source_binding.disabled = False
data_source_binding.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
data_source_binding.updated_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.add(data_source_binding)
db.session.commit()
else:
Expand All @@ -92,7 +92,7 @@ def patch(self, binding_id, action):
if action == "disable":
if not data_source_binding.disabled:
data_source_binding.disabled = True
data_source_binding.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
data_source_binding.updated_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.add(data_source_binding)
db.session.commit()
else:
Expand Down
18 changes: 9 additions & 9 deletions api/controllers/console/datasets/datasets_document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from argparse import ArgumentTypeError
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask import request
from flask_login import current_user
Expand Down Expand Up @@ -665,7 +665,7 @@ def patch(self, dataset_id, document_id, action):
raise InvalidActionError("Document not in indexing state.")

document.paused_by = current_user.id
document.paused_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.paused_at = datetime.now(UTC).replace(tzinfo=None)
document.is_paused = True
db.session.commit()

Expand Down Expand Up @@ -745,7 +745,7 @@ def put(self, dataset_id, document_id):
document.doc_metadata[key] = value

document.doc_type = doc_type
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return {"result": "success", "message": "Document metadata updated."}, 200
Expand Down Expand Up @@ -787,7 +787,7 @@ def patch(self, dataset_id, document_id, action):
document.enabled = True
document.disabled_at = None
document.disabled_by = None
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

# Set cache to prevent indexing the same document multiple times
Expand All @@ -804,9 +804,9 @@ def patch(self, dataset_id, document_id, action):
raise InvalidActionError("Document already disabled.")

document.enabled = False
document.disabled_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.disabled_at = datetime.now(UTC).replace(tzinfo=None)
document.disabled_by = current_user.id
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

# Set cache to prevent indexing the same document multiple times
Expand All @@ -821,9 +821,9 @@ def patch(self, dataset_id, document_id, action):
raise InvalidActionError("Document already archived.")

document.archived = True
document.archived_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.archived_at = datetime.now(UTC).replace(tzinfo=None)
document.archived_by = current_user.id
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

if document.enabled:
Expand All @@ -840,7 +840,7 @@ def patch(self, dataset_id, document_id, action):
document.archived = False
document.archived_at = None
document.archived_by = None
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

# Set cache to prevent indexing the same document multiple times
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/datasets/datasets_segments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from datetime import datetime, timezone
from datetime import UTC, datetime

import pandas as pd
from flask import request
Expand Down Expand Up @@ -188,7 +188,7 @@ def patch(self, dataset_id, segment_id, action):
raise InvalidActionError("Segment is already disabled.")

segment.enabled = False
segment.disabled_at = datetime.now(timezone.utc).replace(tzinfo=None)
segment.disabled_at = datetime.now(UTC).replace(tzinfo=None)
segment.disabled_by = current_user.id
db.session.commit()

Expand Down
6 changes: 3 additions & 3 deletions api/controllers/console/explore/completion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask_login import current_user
from flask_restful import reqparse
Expand Down Expand Up @@ -46,7 +46,7 @@ def post(self, installed_app):
streaming = args["response_mode"] == "streaming"
args["auto_generate_name"] = False

installed_app.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)
installed_app.last_used_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

try:
Expand Down Expand Up @@ -106,7 +106,7 @@ def post(self, installed_app):

args["auto_generate_name"] = False

installed_app.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)
installed_app.last_used_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

try:
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/explore/installed_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask_login import current_user
from flask_restful import Resource, inputs, marshal_with, reqparse
Expand Down Expand Up @@ -81,7 +81,7 @@ def post(self):
tenant_id=current_tenant_id,
app_owner_tenant_id=app.tenant_id,
is_pinned=False,
last_used_at=datetime.now(timezone.utc).replace(tzinfo=None),
last_used_at=datetime.now(UTC).replace(tzinfo=None),
)
db.session.add(new_installed_app)
db.session.commit()
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/workspace/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def post(self):
raise InvalidInvitationCodeError()

invitation_code.status = "used"
invitation_code.used_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
invitation_code.used_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
invitation_code.used_by_tenant_id = account.current_tenant_id
invitation_code.used_by_account_id = account.id

account.interface_language = args["interface_language"]
account.timezone = args["timezone"]
account.interface_theme = "light"
account.status = "active"
account.initialized_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
account.initialized_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.commit()

return {"result": "success"}
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/service_api/wraps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable
from datetime import datetime, timezone
from datetime import UTC, datetime
from enum import Enum
from functools import wraps
from typing import Optional
Expand Down Expand Up @@ -198,7 +198,7 @@ def validate_and_get_api_token(scope=None):
if not api_token:
raise Unauthorized("Access token is invalid")

api_token.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)
api_token.last_used_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return api_token
Expand Down
4 changes: 2 additions & 2 deletions api/core/agent/base_agent_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import uuid
from collections.abc import Mapping, Sequence
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Optional, Union, cast

from core.agent.entities import AgentEntity, AgentToolEntity
Expand Down Expand Up @@ -412,7 +412,7 @@ def update_db_variables(self, tool_variables: ToolRuntimeVariablePool, db_variab
.first()
)

db_variables.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
db_variables.updated_at = datetime.now(UTC).replace(tzinfo=None)
db_variables.variables_str = json.dumps(jsonable_encoder(tool_variables.pool))
db.session.commit()
db.session.close()
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/app_config/entities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Sequence
from enum import Enum
from enum import Enum, StrEnum
from typing import Any, Optional

from pydantic import BaseModel, Field, field_validator
Expand Down Expand Up @@ -88,7 +88,7 @@ def value_of(cls, value: str):
advanced_completion_prompt_template: Optional[AdvancedCompletionPromptTemplateEntity] = None


class VariableEntityType(str, Enum):
class VariableEntityType(StrEnum):
TEXT_INPUT = "text-input"
SELECT = "select"
PARAGRAPH = "paragraph"
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/message_based_app_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
from collections.abc import Generator
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Optional, Union

from sqlalchemy import and_
Expand Down Expand Up @@ -200,7 +200,7 @@ def _init_generate_records(
db.session.commit()
db.session.refresh(conversation)
else:
conversation.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
conversation.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

message = Message(
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/entities/queue_entities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from enum import Enum
from enum import Enum, StrEnum
from typing import Any, Optional

from pydantic import BaseModel, field_validator
Expand All @@ -11,7 +11,7 @@
from core.workflow.nodes.base import BaseNodeData


class QueueEvent(str, Enum):
class QueueEvent(StrEnum):
"""
QueueEvent enum
"""
Expand Down
Loading

0 comments on commit 3997068

Please sign in to comment.