mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-10 07:09:03 +08:00
fix wrong syntax of type definitions (#1678)
This commit is contained in:
parent
8fbc374f31
commit
d3a2c0ed34
@ -161,7 +161,7 @@ class ChatMessageApi(Resource):
|
|||||||
raise InternalServerError()
|
raise InternalServerError()
|
||||||
|
|
||||||
|
|
||||||
def compact_response(response: Union[dict | Generator]) -> Response:
|
def compact_response(response: Union[dict, Generator]) -> Response:
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
|
@ -249,7 +249,7 @@ class MessageMoreLikeThisApi(Resource):
|
|||||||
raise InternalServerError()
|
raise InternalServerError()
|
||||||
|
|
||||||
|
|
||||||
def compact_response(response: Union[dict | Generator]) -> Response:
|
def compact_response(response: Union[dict, Generator]) -> Response:
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
|
@ -154,7 +154,7 @@ class ChatStopApi(InstalledAppResource):
|
|||||||
return {'result': 'success'}, 200
|
return {'result': 'success'}, 200
|
||||||
|
|
||||||
|
|
||||||
def compact_response(response: Union[dict | Generator]) -> Response:
|
def compact_response(response: Union[dict, Generator]) -> Response:
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
|
@ -105,7 +105,7 @@ class MessageMoreLikeThisApi(InstalledAppResource):
|
|||||||
raise InternalServerError()
|
raise InternalServerError()
|
||||||
|
|
||||||
|
|
||||||
def compact_response(response: Union[dict | Generator]) -> Response:
|
def compact_response(response: Union[dict, Generator]) -> Response:
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
|
@ -104,7 +104,7 @@ class UniversalChatStopApi(UniversalChatResource):
|
|||||||
return {'result': 'success'}, 200
|
return {'result': 'success'}, 200
|
||||||
|
|
||||||
|
|
||||||
def compact_response(response: Union[dict | Generator]) -> Response:
|
def compact_response(response: Union[dict, Generator]) -> Response:
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
|
@ -150,7 +150,7 @@ class ChatStopApi(AppApiResource):
|
|||||||
return {'result': 'success'}, 200
|
return {'result': 'success'}, 200
|
||||||
|
|
||||||
|
|
||||||
def compact_response(response: Union[dict | Generator]) -> Response:
|
def compact_response(response: Union[dict, Generator]) -> Response:
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
|
@ -139,7 +139,7 @@ class MessageMoreLikeThisApi(WebApiResource):
|
|||||||
raise InternalServerError()
|
raise InternalServerError()
|
||||||
|
|
||||||
|
|
||||||
def compact_response(response: Union[dict | Generator]) -> Response:
|
def compact_response(response: Union[dict, Generator]) -> Response:
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
return Response(response=json.dumps(response), status=200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
|
@ -59,7 +59,7 @@ class AgentExecutor:
|
|||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
self.agent = self._init_agent()
|
self.agent = self._init_agent()
|
||||||
|
|
||||||
def _init_agent(self) -> Union[BaseSingleActionAgent | BaseMultiActionAgent]:
|
def _init_agent(self) -> Union[BaseSingleActionAgent, BaseMultiActionAgent]:
|
||||||
if self.configuration.strategy == PlanningStrategy.REACT:
|
if self.configuration.strategy == PlanningStrategy.REACT:
|
||||||
agent = AutoSummarizingStructuredChatAgent.from_llm_and_tools(
|
agent = AutoSummarizingStructuredChatAgent.from_llm_and_tools(
|
||||||
model_instance=self.configuration.model_instance,
|
model_instance=self.configuration.model_instance,
|
||||||
|
@ -321,7 +321,7 @@ class ConversationMessageTask:
|
|||||||
|
|
||||||
|
|
||||||
class PubHandler:
|
class PubHandler:
|
||||||
def __init__(self, user: Union[Account | EndUser], task_id: str,
|
def __init__(self, user: Union[Account, EndUser], task_id: str,
|
||||||
message: Message, conversation: Conversation,
|
message: Message, conversation: Conversation,
|
||||||
chain_pub: bool = False, agent_thought_pub: bool = False):
|
chain_pub: bool = False, agent_thought_pub: bool = False):
|
||||||
self._channel = PubHandler.generate_channel_name(user, task_id)
|
self._channel = PubHandler.generate_channel_name(user, task_id)
|
||||||
@ -334,7 +334,7 @@ class PubHandler:
|
|||||||
self._agent_thought_pub = agent_thought_pub
|
self._agent_thought_pub = agent_thought_pub
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_channel_name(cls, user: Union[Account | EndUser], task_id: str):
|
def generate_channel_name(cls, user: Union[Account, EndUser], task_id: str):
|
||||||
if not user:
|
if not user:
|
||||||
raise ValueError("user is required")
|
raise ValueError("user is required")
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ class PubHandler:
|
|||||||
return "generate_result:{}-{}".format(user_str, task_id)
|
return "generate_result:{}-{}".format(user_str, task_id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_stopped_cache_key(cls, user: Union[Account | EndUser], task_id: str):
|
def generate_stopped_cache_key(cls, user: Union[Account, EndUser], task_id: str):
|
||||||
user_str = 'account-' + str(user.id) if isinstance(user, Account) else 'end-user-' + str(user.id)
|
user_str = 'account-' + str(user.id) if isinstance(user, Account) else 'end-user-' + str(user.id)
|
||||||
return "generate_result_stopped:{}-{}".format(user_str, task_id)
|
return "generate_result_stopped:{}-{}".format(user_str, task_id)
|
||||||
|
|
||||||
@ -454,7 +454,7 @@ class PubHandler:
|
|||||||
redis_client.publish(self._channel, json.dumps(content))
|
redis_client.publish(self._channel, json.dumps(content))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pub_error(cls, user: Union[Account | EndUser], task_id: str, e):
|
def pub_error(cls, user: Union[Account, EndUser], task_id: str, e):
|
||||||
content = {
|
content = {
|
||||||
'error': type(e).__name__,
|
'error': type(e).__name__,
|
||||||
'description': e.description if getattr(e, 'description', None) is not None else str(e)
|
'description': e.description if getattr(e, 'description', None) is not None else str(e)
|
||||||
@ -467,7 +467,7 @@ class PubHandler:
|
|||||||
return redis_client.get(self._stopped_cache_key) is not None
|
return redis_client.get(self._stopped_cache_key) is not None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ping(cls, user: Union[Account | EndUser], task_id: str):
|
def ping(cls, user: Union[Account, EndUser], task_id: str):
|
||||||
content = {
|
content = {
|
||||||
'event': 'ping'
|
'event': 'ping'
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ class PubHandler:
|
|||||||
redis_client.publish(channel, json.dumps(content))
|
redis_client.publish(channel, json.dumps(content))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def stop(cls, user: Union[Account | EndUser], task_id: str):
|
def stop(cls, user: Union[Account, EndUser], task_id: str):
|
||||||
stopped_cache_key = cls.generate_stopped_cache_key(user, task_id)
|
stopped_cache_key = cls.generate_stopped_cache_key(user, task_id)
|
||||||
redis_client.setex(stopped_cache_key, 600, 1)
|
redis_client.setex(stopped_cache_key, 600, 1)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from services.errors.message import MessageNotExistsError
|
|||||||
|
|
||||||
class ConversationService:
|
class ConversationService:
|
||||||
@classmethod
|
@classmethod
|
||||||
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account | EndUser]],
|
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account, EndUser]],
|
||||||
last_id: Optional[str], limit: int,
|
last_id: Optional[str], limit: int,
|
||||||
include_ids: Optional[list] = None, exclude_ids: Optional[list] = None,
|
include_ids: Optional[list] = None, exclude_ids: Optional[list] = None,
|
||||||
exclude_debug_conversation: bool = False) -> InfiniteScrollPagination:
|
exclude_debug_conversation: bool = False) -> InfiniteScrollPagination:
|
||||||
@ -69,7 +69,7 @@ class ConversationService:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def rename(cls, app_model: App, conversation_id: str,
|
def rename(cls, app_model: App, conversation_id: str,
|
||||||
user: Optional[Union[Account | EndUser]], name: str, auto_generate: bool):
|
user: Optional[Union[Account, EndUser]], name: str, auto_generate: bool):
|
||||||
conversation = cls.get_conversation(app_model, conversation_id, user)
|
conversation = cls.get_conversation(app_model, conversation_id, user)
|
||||||
|
|
||||||
if auto_generate:
|
if auto_generate:
|
||||||
@ -104,7 +104,7 @@ class ConversationService:
|
|||||||
return conversation
|
return conversation
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_conversation(cls, app_model: App, conversation_id: str, user: Optional[Union[Account | EndUser]]):
|
def get_conversation(cls, app_model: App, conversation_id: str, user: Optional[Union[Account, EndUser]]):
|
||||||
conversation = db.session.query(Conversation) \
|
conversation = db.session.query(Conversation) \
|
||||||
.filter(
|
.filter(
|
||||||
Conversation.id == conversation_id,
|
Conversation.id == conversation_id,
|
||||||
@ -121,7 +121,7 @@ class ConversationService:
|
|||||||
return conversation
|
return conversation
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, app_model: App, conversation_id: str, user: Optional[Union[Account | EndUser]]):
|
def delete(cls, app_model: App, conversation_id: str, user: Optional[Union[Account, EndUser]]):
|
||||||
conversation = cls.get_conversation(app_model, conversation_id, user)
|
conversation = cls.get_conversation(app_model, conversation_id, user)
|
||||||
|
|
||||||
conversation.is_deleted = True
|
conversation.is_deleted = True
|
||||||
|
@ -16,7 +16,7 @@ from services.errors.message import FirstMessageNotExistsError, MessageNotExists
|
|||||||
|
|
||||||
class MessageService:
|
class MessageService:
|
||||||
@classmethod
|
@classmethod
|
||||||
def pagination_by_first_id(cls, app_model: App, user: Optional[Union[Account | EndUser]],
|
def pagination_by_first_id(cls, app_model: App, user: Optional[Union[Account, EndUser]],
|
||||||
conversation_id: str, first_id: Optional[str], limit: int) -> InfiniteScrollPagination:
|
conversation_id: str, first_id: Optional[str], limit: int) -> InfiniteScrollPagination:
|
||||||
if not user:
|
if not user:
|
||||||
return InfiniteScrollPagination(data=[], limit=limit, has_more=False)
|
return InfiniteScrollPagination(data=[], limit=limit, has_more=False)
|
||||||
@ -68,7 +68,7 @@ class MessageService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account | EndUser]],
|
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account, EndUser]],
|
||||||
last_id: Optional[str], limit: int, conversation_id: Optional[str] = None,
|
last_id: Optional[str], limit: int, conversation_id: Optional[str] = None,
|
||||||
include_ids: Optional[list] = None) -> InfiniteScrollPagination:
|
include_ids: Optional[list] = None) -> InfiniteScrollPagination:
|
||||||
if not user:
|
if not user:
|
||||||
@ -119,7 +119,7 @@ class MessageService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_feedback(cls, app_model: App, message_id: str, user: Optional[Union[Account | EndUser]],
|
def create_feedback(cls, app_model: App, message_id: str, user: Optional[Union[Account, EndUser]],
|
||||||
rating: Optional[str]) -> MessageFeedback:
|
rating: Optional[str]) -> MessageFeedback:
|
||||||
if not user:
|
if not user:
|
||||||
raise ValueError('user cannot be None')
|
raise ValueError('user cannot be None')
|
||||||
@ -155,7 +155,7 @@ class MessageService:
|
|||||||
return feedback
|
return feedback
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_message(cls, app_model: App, user: Optional[Union[Account | EndUser]], message_id: str):
|
def get_message(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str):
|
||||||
message = db.session.query(Message).filter(
|
message = db.session.query(Message).filter(
|
||||||
Message.id == message_id,
|
Message.id == message_id,
|
||||||
Message.app_id == app_model.id,
|
Message.app_id == app_model.id,
|
||||||
@ -170,7 +170,7 @@ class MessageService:
|
|||||||
return message
|
return message
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_suggested_questions_after_answer(cls, app_model: App, user: Optional[Union[Account | EndUser]],
|
def get_suggested_questions_after_answer(cls, app_model: App, user: Optional[Union[Account, EndUser]],
|
||||||
message_id: str, check_enabled: bool = True) -> List[Message]:
|
message_id: str, check_enabled: bool = True) -> List[Message]:
|
||||||
if not user:
|
if not user:
|
||||||
raise ValueError('user cannot be None')
|
raise ValueError('user cannot be None')
|
||||||
|
@ -10,7 +10,7 @@ from services.message_service import MessageService
|
|||||||
|
|
||||||
class SavedMessageService:
|
class SavedMessageService:
|
||||||
@classmethod
|
@classmethod
|
||||||
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account | EndUser]],
|
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account, EndUser]],
|
||||||
last_id: Optional[str], limit: int) -> InfiniteScrollPagination:
|
last_id: Optional[str], limit: int) -> InfiniteScrollPagination:
|
||||||
saved_messages = db.session.query(SavedMessage).filter(
|
saved_messages = db.session.query(SavedMessage).filter(
|
||||||
SavedMessage.app_id == app_model.id,
|
SavedMessage.app_id == app_model.id,
|
||||||
@ -28,7 +28,7 @@ class SavedMessageService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def save(cls, app_model: App, user: Optional[Union[Account | EndUser]], message_id: str):
|
def save(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str):
|
||||||
saved_message = db.session.query(SavedMessage).filter(
|
saved_message = db.session.query(SavedMessage).filter(
|
||||||
SavedMessage.app_id == app_model.id,
|
SavedMessage.app_id == app_model.id,
|
||||||
SavedMessage.message_id == message_id,
|
SavedMessage.message_id == message_id,
|
||||||
@ -56,7 +56,7 @@ class SavedMessageService:
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, app_model: App, user: Optional[Union[Account | EndUser]], message_id: str):
|
def delete(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str):
|
||||||
saved_message = db.session.query(SavedMessage).filter(
|
saved_message = db.session.query(SavedMessage).filter(
|
||||||
SavedMessage.app_id == app_model.id,
|
SavedMessage.app_id == app_model.id,
|
||||||
SavedMessage.message_id == message_id,
|
SavedMessage.message_id == message_id,
|
||||||
|
@ -10,7 +10,7 @@ from services.conversation_service import ConversationService
|
|||||||
|
|
||||||
class WebConversationService:
|
class WebConversationService:
|
||||||
@classmethod
|
@classmethod
|
||||||
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account | EndUser]],
|
def pagination_by_last_id(cls, app_model: App, user: Optional[Union[Account, EndUser]],
|
||||||
last_id: Optional[str], limit: int, pinned: Optional[bool] = None,
|
last_id: Optional[str], limit: int, pinned: Optional[bool] = None,
|
||||||
exclude_debug_conversation: bool = False) -> InfiniteScrollPagination:
|
exclude_debug_conversation: bool = False) -> InfiniteScrollPagination:
|
||||||
include_ids = None
|
include_ids = None
|
||||||
@ -38,7 +38,7 @@ class WebConversationService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pin(cls, app_model: App, conversation_id: str, user: Optional[Union[Account | EndUser]]):
|
def pin(cls, app_model: App, conversation_id: str, user: Optional[Union[Account, EndUser]]):
|
||||||
pinned_conversation = db.session.query(PinnedConversation).filter(
|
pinned_conversation = db.session.query(PinnedConversation).filter(
|
||||||
PinnedConversation.app_id == app_model.id,
|
PinnedConversation.app_id == app_model.id,
|
||||||
PinnedConversation.conversation_id == conversation_id,
|
PinnedConversation.conversation_id == conversation_id,
|
||||||
@ -66,7 +66,7 @@ class WebConversationService:
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unpin(cls, app_model: App, conversation_id: str, user: Optional[Union[Account | EndUser]]):
|
def unpin(cls, app_model: App, conversation_id: str, user: Optional[Union[Account, EndUser]]):
|
||||||
pinned_conversation = db.session.query(PinnedConversation).filter(
|
pinned_conversation = db.session.query(PinnedConversation).filter(
|
||||||
PinnedConversation.app_id == app_model.id,
|
PinnedConversation.app_id == app_model.id,
|
||||||
PinnedConversation.conversation_id == conversation_id,
|
PinnedConversation.conversation_id == conversation_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user