feat: backwards invoke app

This commit is contained in:
Yeuoly
2024-08-29 20:17:17 +08:00
parent 113ff27d07
commit 41ed2e0cc2
7 changed files with 187 additions and 13 deletions

View File

@ -1,5 +1,4 @@
import time
from collections.abc import Generator
from flask_restful import Resource, reqparse
@ -30,15 +29,10 @@ class PluginInvokeLLMApi(Resource):
def post(self, user_id: str, tenant_model: Tenant, payload: RequestInvokeLLM):
def generator():
response = PluginModelBackwardsInvocation.invoke_llm(user_id, tenant_model, payload)
if isinstance(response, Generator):
for chunk in response:
yield chunk.model_dump_json().encode() + b'\n\n'
else:
yield response.model_dump_json().encode() + b'\n\n'
return PluginModelBackwardsInvocation.convert_to_event_stream(response)
return compact_generate_response(generator())
class PluginInvokeTextEmbeddingApi(Resource):
@setup_required
@plugin_inner_api_only