mirror of
https://github.com/bringout/oca-ai.git
synced 2026-04-24 18:02:03 +02:00
Initial commit: OCA Ai packages (4 packages)
This commit is contained in:
commit
0adb4b78b1
170 changed files with 12385 additions and 0 deletions
|
|
@ -0,0 +1,48 @@
|
|||
# Copyright 2025 Dixmit
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
import json
|
||||
|
||||
from odoo import fields, http
|
||||
from odoo.http import request
|
||||
from odoo.tools import consteq
|
||||
from odoo.tools.translate import _
|
||||
|
||||
|
||||
class AIController(http.Controller):
|
||||
@http.route(
|
||||
[
|
||||
"/ai/response/<int:execution_id>/<string:token>",
|
||||
],
|
||||
type="http",
|
||||
auth="public",
|
||||
cors="*",
|
||||
csrf=False,
|
||||
)
|
||||
def ai_process_response(self, execution_id, token):
|
||||
execution = request.env["ai.bridge.execution"].sudo().browse(execution_id)
|
||||
if not execution.exists():
|
||||
return request.make_response(_("Execution not found."), status=404)
|
||||
if not consteq(execution._generate_token(), token):
|
||||
return request.make_response(
|
||||
_("Token is not allowed for this execution."), status=404
|
||||
)
|
||||
if (
|
||||
not execution.expiration_date
|
||||
or execution.expiration_date < fields.Datetime.now()
|
||||
):
|
||||
return request.make_response(_("Execution is expired."), status=404)
|
||||
return request.make_response(
|
||||
json.dumps(
|
||||
execution._process_response(
|
||||
json.loads(
|
||||
request.httprequest.get_data().decode(
|
||||
request.httprequest.charset
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
headers=[
|
||||
("Content-Type", "application/json"),
|
||||
],
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue