|
|
|
|
@ -4,7 +4,7 @@ import uuid
|
|
|
|
|
from collections.abc import Generator, Mapping
|
|
|
|
|
from typing import Any, Literal, Union, overload
|
|
|
|
|
|
|
|
|
|
from flask import Flask, current_app
|
|
|
|
|
from flask import Flask, copy_current_request_context, current_app
|
|
|
|
|
from pydantic import ValidationError
|
|
|
|
|
|
|
|
|
|
from configs import dify_config
|
|
|
|
|
@ -151,17 +151,18 @@ class CompletionAppGenerator(MessageBasedAppGenerator):
|
|
|
|
|
message_id=message.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# new thread
|
|
|
|
|
worker_thread = threading.Thread(
|
|
|
|
|
target=self._generate_worker,
|
|
|
|
|
kwargs={
|
|
|
|
|
"flask_app": current_app._get_current_object(), # type: ignore
|
|
|
|
|
"application_generate_entity": application_generate_entity,
|
|
|
|
|
"queue_manager": queue_manager,
|
|
|
|
|
"message_id": message.id,
|
|
|
|
|
},
|
|
|
|
|
# new thread with request context
|
|
|
|
|
@copy_current_request_context
|
|
|
|
|
def worker_with_context():
|
|
|
|
|
return self._generate_worker(
|
|
|
|
|
flask_app=current_app._get_current_object(), # type: ignore
|
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
|
queue_manager=queue_manager,
|
|
|
|
|
message_id=message.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
worker_thread = threading.Thread(target=worker_with_context)
|
|
|
|
|
|
|
|
|
|
worker_thread.start()
|
|
|
|
|
|
|
|
|
|
# return response or stream generator
|
|
|
|
|
@ -313,17 +314,18 @@ class CompletionAppGenerator(MessageBasedAppGenerator):
|
|
|
|
|
message_id=message.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# new thread
|
|
|
|
|
worker_thread = threading.Thread(
|
|
|
|
|
target=self._generate_worker,
|
|
|
|
|
kwargs={
|
|
|
|
|
"flask_app": current_app._get_current_object(), # type: ignore
|
|
|
|
|
"application_generate_entity": application_generate_entity,
|
|
|
|
|
"queue_manager": queue_manager,
|
|
|
|
|
"message_id": message.id,
|
|
|
|
|
},
|
|
|
|
|
# new thread with request context
|
|
|
|
|
@copy_current_request_context
|
|
|
|
|
def worker_with_context():
|
|
|
|
|
return self._generate_worker(
|
|
|
|
|
flask_app=current_app._get_current_object(), # type: ignore
|
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
|
queue_manager=queue_manager,
|
|
|
|
|
message_id=message.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
worker_thread = threading.Thread(target=worker_with_context)
|
|
|
|
|
|
|
|
|
|
worker_thread.start()
|
|
|
|
|
|
|
|
|
|
# return response or stream generator
|
|
|
|
|
|