mirror of
https://github.com/langgenius/dify.git
synced 2026-01-08 07:14:14 +00:00
feat: invoke app
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
|
||||
from flask_restful import Resource, reqparse
|
||||
from flask_restful import Resource
|
||||
|
||||
from controllers.console.setup import setup_required
|
||||
from controllers.inner_api import api
|
||||
@@ -117,16 +117,13 @@ class PluginInvokeAppApi(Resource):
|
||||
@get_tenant
|
||||
@plugin_data(payload_type=RequestInvokeApp)
|
||||
def post(self, user_id: str, tenant_model: Tenant, payload: RequestInvokeApp):
|
||||
parser = reqparse.RequestParser()
|
||||
args = parser.parse_args()
|
||||
|
||||
response = PluginAppBackwardsInvocation.invoke_app(
|
||||
app_id=payload.app_id,
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_model.id,
|
||||
conversation_id=payload.conversation_id,
|
||||
query=payload.query,
|
||||
stream=payload.stream,
|
||||
stream=payload.response_mode == 'streaming',
|
||||
inputs=payload.inputs,
|
||||
files=payload.files
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ class BaseBackwardsInvocation:
|
||||
for chunk in response:
|
||||
if isinstance(chunk, BaseModel):
|
||||
yield chunk.model_dump_json().encode() + b'\n\n'
|
||||
if isinstance(chunk, str):
|
||||
elif isinstance(chunk, str):
|
||||
yield f"event: {chunk}\n\n".encode()
|
||||
else:
|
||||
yield json.dumps(chunk).encode() + b'\n\n'
|
||||
|
||||
@@ -105,4 +105,4 @@ class RequestInvokeApp(BaseModel):
|
||||
conversation_id: Optional[str] = None
|
||||
user: Optional[str] = None
|
||||
files: list[dict] = Field(default_factory=list)
|
||||
stream: bool = Field(default=False)
|
||||
|
||||
Reference in New Issue
Block a user