imio.omnia.assistant 1.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of imio.omnia.assistant might be problematic. Click here for more details.
- imio/omnia/assistant/__init__.py +6 -0
- imio/omnia/assistant/adapters.py +94 -0
- imio/omnia/assistant/browser/__init__.py +0 -0
- imio/omnia/assistant/browser/controlpanel.py +147 -0
- imio/omnia/assistant/browser/proxy.py +89 -0
- imio/omnia/assistant/browser/viewlets.py +25 -0
- imio/omnia/assistant/interfaces.py +20 -0
- imio/omnia/assistant/locales/__init__.py +0 -0
- imio/omnia/assistant/locales/update.py +74 -0
- imio/omnia/assistant/setuphandlers.py +35 -0
- imio/omnia/assistant/testing.py +46 -0
- imio/omnia/assistant/tests/__init__.py +0 -0
- imio/omnia/assistant/tests/test_controlpanel.py +76 -0
- imio/omnia/assistant/tests/test_proxy.py +651 -0
- imio/omnia/assistant/tests/test_robot.py +28 -0
- imio/omnia/assistant/tests/test_setup.py +88 -0
- imio/omnia/assistant/tests/test_viewlet.py +206 -0
- imio.omnia.assistant-1.0a1-py3.12-nspkg.pth +2 -0
- imio_omnia_assistant-1.0a1.dist-info/METADATA +334 -0
- imio_omnia_assistant-1.0a1.dist-info/RECORD +26 -0
- imio_omnia_assistant-1.0a1.dist-info/WHEEL +5 -0
- imio_omnia_assistant-1.0a1.dist-info/entry_points.txt +5 -0
- imio_omnia_assistant-1.0a1.dist-info/licenses/LICENSE.GPL +339 -0
- imio_omnia_assistant-1.0a1.dist-info/licenses/LICENSE.rst +15 -0
- imio_omnia_assistant-1.0a1.dist-info/namespace_packages.txt +2 -0
- imio_omnia_assistant-1.0a1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from plone import api
|
|
3
|
+
from zope.component import adapter
|
|
4
|
+
from zope.interface import Interface
|
|
5
|
+
from zope.interface import implementer
|
|
6
|
+
from zope.publisher.interfaces.browser import IBrowserRequest
|
|
7
|
+
|
|
8
|
+
from imio.omnia.assistant.interfaces import IOmniaAssistantAdapter
|
|
9
|
+
from imio.omnia.core.tokens import generate_token
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
_SETTINGS_PREFIX = (
|
|
13
|
+
"imio.omnia.assistant.browser.controlpanel.IOmniaAssistantSettings"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@adapter(Interface, IBrowserRequest)
|
|
18
|
+
@implementer(IOmniaAssistantAdapter)
|
|
19
|
+
class OmniaAssistantAdapter:
|
|
20
|
+
"""Default assistant configuration hook.
|
|
21
|
+
|
|
22
|
+
Product add-ons can register more specific multi-adapters to override
|
|
23
|
+
assistant availability, server-side prompt and frontend initialization
|
|
24
|
+
settings.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, context, request):
|
|
28
|
+
self.context = context
|
|
29
|
+
self.request = request
|
|
30
|
+
|
|
31
|
+
def _get_registry_record(self, key, default=None):
|
|
32
|
+
try:
|
|
33
|
+
return api.portal.get_registry_record(key)
|
|
34
|
+
except (KeyError, api.exc.InvalidParameterError):
|
|
35
|
+
return default
|
|
36
|
+
|
|
37
|
+
def is_available(self):
|
|
38
|
+
return self._get_registry_record(f"{_SETTINGS_PREFIX}.enabled", True)
|
|
39
|
+
|
|
40
|
+
def get_system_prompt(self):
|
|
41
|
+
return self._get_registry_record(f"{_SETTINGS_PREFIX}.base_prompt", "")
|
|
42
|
+
|
|
43
|
+
def _get_registry_config(self):
|
|
44
|
+
config = {
|
|
45
|
+
"model": self._get_registry_record(f"{_SETTINGS_PREFIX}.model", ""),
|
|
46
|
+
"include_page_content": self._get_registry_record(
|
|
47
|
+
f"{_SETTINGS_PREFIX}.include_page_content", True
|
|
48
|
+
),
|
|
49
|
+
"page_content_selector": self._get_registry_record(
|
|
50
|
+
f"{_SETTINGS_PREFIX}.page_content_selector", "#content"
|
|
51
|
+
),
|
|
52
|
+
"page_content_clean": self._get_registry_record(
|
|
53
|
+
f"{_SETTINGS_PREFIX}.page_content_clean", False
|
|
54
|
+
),
|
|
55
|
+
"max_context_chars": self._get_registry_record(
|
|
56
|
+
f"{_SETTINGS_PREFIX}.max_context_chars", 20000
|
|
57
|
+
),
|
|
58
|
+
"max_messages_per_session": self._get_registry_record(
|
|
59
|
+
f"{_SETTINGS_PREFIX}.max_messages_per_session", 0
|
|
60
|
+
),
|
|
61
|
+
"mode": self._get_registry_record(f"{_SETTINGS_PREFIX}.mode", "floating"),
|
|
62
|
+
"initial_width": self._get_registry_record(
|
|
63
|
+
f"{_SETTINGS_PREFIX}.initial_width", 380
|
|
64
|
+
),
|
|
65
|
+
"initial_height": self._get_registry_record(
|
|
66
|
+
f"{_SETTINGS_PREFIX}.initial_height", 520
|
|
67
|
+
),
|
|
68
|
+
}
|
|
69
|
+
disclaimer = self._get_registry_record(f"{_SETTINGS_PREFIX}.disclaimer")
|
|
70
|
+
if disclaimer:
|
|
71
|
+
config["disclaimer"] = disclaimer
|
|
72
|
+
return config
|
|
73
|
+
|
|
74
|
+
def _merge_config(self, config, overrides):
|
|
75
|
+
if not overrides:
|
|
76
|
+
return config
|
|
77
|
+
merged = dict(config)
|
|
78
|
+
merged.update(overrides)
|
|
79
|
+
return merged
|
|
80
|
+
|
|
81
|
+
def _get_config_overrides(self):
|
|
82
|
+
return {}
|
|
83
|
+
|
|
84
|
+
def get_config(self):
|
|
85
|
+
if not self.is_available():
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
config = self._get_registry_config()
|
|
89
|
+
config = self._merge_config(config, self._get_config_overrides())
|
|
90
|
+
config["api_service_url"] = (
|
|
91
|
+
f"{self.context.absolute_url()}/@@omnia-assistant-api"
|
|
92
|
+
)
|
|
93
|
+
config["api_key"] = generate_token(api.portal.get().absolute_url())
|
|
94
|
+
return config
|
|
File without changes
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
from imio.omnia.assistant import _
|
|
5
|
+
from imio.omnia.core.browser.controlpanel import OmniaCoreControlPanelFormWrapper
|
|
6
|
+
from imio.omnia.core.interfaces import IOmniaOpenAIService
|
|
7
|
+
from plone import api
|
|
8
|
+
from plone.app.registry.browser.controlpanel import RegistryEditForm
|
|
9
|
+
from plone.z3cform import layout
|
|
10
|
+
from zope import schema
|
|
11
|
+
from zope.component import getMultiAdapter
|
|
12
|
+
from zope.globalrequest import getRequest
|
|
13
|
+
from zope.interface import Interface
|
|
14
|
+
from zope.interface import implementer
|
|
15
|
+
from zope.schema.interfaces import IVocabularyFactory
|
|
16
|
+
from zope.schema.vocabulary import SimpleTerm
|
|
17
|
+
from zope.schema.vocabulary import SimpleVocabulary
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
_MODEL_REGISTRY_KEY = (
|
|
22
|
+
"imio.omnia.assistant.browser.controlpanel.IOmniaAssistantSettings.model"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@implementer(IVocabularyFactory)
|
|
27
|
+
class OmniaModelsVocabularyFactory:
|
|
28
|
+
"""Vocabulary of available models from the OpenAI-compatible API."""
|
|
29
|
+
|
|
30
|
+
def __call__(self, context):
|
|
31
|
+
terms = []
|
|
32
|
+
try:
|
|
33
|
+
portal = api.portal.get()
|
|
34
|
+
request = getRequest()
|
|
35
|
+
service = getMultiAdapter((portal, request), IOmniaOpenAIService)
|
|
36
|
+
result = service.list_models()
|
|
37
|
+
for model_data in result.get("data", []):
|
|
38
|
+
model_id = model_data["id"]
|
|
39
|
+
terms.append(SimpleTerm(value=model_id, token=model_id, title=model_id))
|
|
40
|
+
except Exception:
|
|
41
|
+
logger.error("Could not fetch models from OpenAI API", exc_info=True)
|
|
42
|
+
|
|
43
|
+
if not terms:
|
|
44
|
+
# Fallback: keep the currently saved value so the form still renders.
|
|
45
|
+
try:
|
|
46
|
+
current = api.portal.get_registry_record(
|
|
47
|
+
_MODEL_REGISTRY_KEY, default=None
|
|
48
|
+
)
|
|
49
|
+
if current:
|
|
50
|
+
terms = [SimpleTerm(value=current, token=current, title=current)]
|
|
51
|
+
except Exception:
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
return SimpleVocabulary(terms)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class IOmniaAssistantSettings(Interface):
|
|
58
|
+
enabled = schema.Bool(
|
|
59
|
+
title=_("Enabled"),
|
|
60
|
+
description=_("Enable or disable the AI assistant globally."),
|
|
61
|
+
required=False,
|
|
62
|
+
default=True,
|
|
63
|
+
)
|
|
64
|
+
model = schema.Choice(
|
|
65
|
+
title=_("Model"),
|
|
66
|
+
description=_("Model for the OpenAI-compatible API."),
|
|
67
|
+
vocabulary="imio.omnia.assistant.models",
|
|
68
|
+
required=True,
|
|
69
|
+
)
|
|
70
|
+
base_prompt = schema.Text(
|
|
71
|
+
title=_("System prompt"),
|
|
72
|
+
description=_("System prompt sent with every conversation."),
|
|
73
|
+
required=False,
|
|
74
|
+
)
|
|
75
|
+
include_page_content = schema.Bool(
|
|
76
|
+
title=_("Include page content"),
|
|
77
|
+
description=_("Include current page content as context for the AI."),
|
|
78
|
+
required=False,
|
|
79
|
+
default=True,
|
|
80
|
+
)
|
|
81
|
+
page_content_selector = schema.TextLine(
|
|
82
|
+
title=_("Page content CSS selector"),
|
|
83
|
+
description=_("CSS selector to extract page content from."),
|
|
84
|
+
required=False,
|
|
85
|
+
default="#content",
|
|
86
|
+
)
|
|
87
|
+
page_content_clean = schema.Bool(
|
|
88
|
+
title=_("Use plain text"),
|
|
89
|
+
description=_(
|
|
90
|
+
"Use innerText instead of innerHTML for page content extraction."
|
|
91
|
+
),
|
|
92
|
+
required=False,
|
|
93
|
+
default=False,
|
|
94
|
+
)
|
|
95
|
+
max_context_chars = schema.Int(
|
|
96
|
+
title=_("Max context characters"),
|
|
97
|
+
description=_("Maximum characters of page content to include as context."),
|
|
98
|
+
required=False,
|
|
99
|
+
default=20000,
|
|
100
|
+
)
|
|
101
|
+
max_messages_per_session = schema.Int(
|
|
102
|
+
title=_("Max messages per conversation"),
|
|
103
|
+
description=_(
|
|
104
|
+
"Maximum number of user messages allowed in a single conversation. "
|
|
105
|
+
"Set to 0 for no limit."
|
|
106
|
+
),
|
|
107
|
+
required=False,
|
|
108
|
+
default=0,
|
|
109
|
+
min=0,
|
|
110
|
+
)
|
|
111
|
+
mode = schema.Choice(
|
|
112
|
+
title=_("Display mode"),
|
|
113
|
+
description=_("Panel display mode: floating (draggable) or fixed."),
|
|
114
|
+
values=["floating", "fixed"],
|
|
115
|
+
required=False,
|
|
116
|
+
default="floating",
|
|
117
|
+
)
|
|
118
|
+
initial_width = schema.Int(
|
|
119
|
+
title=_("Panel width"),
|
|
120
|
+
description=_("Initial panel width in pixels."),
|
|
121
|
+
required=False,
|
|
122
|
+
default=380,
|
|
123
|
+
)
|
|
124
|
+
initial_height = schema.Int(
|
|
125
|
+
title=_("Panel height"),
|
|
126
|
+
description=_("Initial panel height in pixels."),
|
|
127
|
+
required=False,
|
|
128
|
+
default=520,
|
|
129
|
+
)
|
|
130
|
+
disclaimer = schema.Text(
|
|
131
|
+
title=_("Disclaimer"),
|
|
132
|
+
description=_(
|
|
133
|
+
"Disclaimer text shown at the bottom of the chat panel. "
|
|
134
|
+
"Leave empty for the default French disclaimer."
|
|
135
|
+
),
|
|
136
|
+
required=False,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class OmniaAssistantControlPanelForm(RegistryEditForm):
|
|
141
|
+
label = _("AI Assistant settings")
|
|
142
|
+
schema = IOmniaAssistantSettings
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
OmniaAssistantControlPanelView = layout.wrap_form(
|
|
146
|
+
OmniaAssistantControlPanelForm, OmniaCoreControlPanelFormWrapper
|
|
147
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from plone import api
|
|
4
|
+
from zope.component import getMultiAdapter
|
|
5
|
+
|
|
6
|
+
from imio.omnia.assistant.interfaces import IOmniaAssistantAdapter
|
|
7
|
+
from imio.omnia.core.browser.proxy import OmniaOpenAIProxyView
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
_SETTINGS_PREFIX = (
|
|
11
|
+
"imio.omnia.assistant.browser.controlpanel.IOmniaAssistantSettings"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class OmniaAssistantOpenAIProxyView(OmniaOpenAIProxyView):
|
|
16
|
+
"""Assistant-specific OpenAI proxy with server-side prompt injection."""
|
|
17
|
+
|
|
18
|
+
def _get_registry_record(self, key, default=None):
|
|
19
|
+
try:
|
|
20
|
+
return api.portal.get_registry_record(key)
|
|
21
|
+
except (KeyError, api.exc.InvalidParameterError):
|
|
22
|
+
return default
|
|
23
|
+
|
|
24
|
+
def _get_assistant_adapter(self):
|
|
25
|
+
return getMultiAdapter((self.context, self.request), IOmniaAssistantAdapter)
|
|
26
|
+
|
|
27
|
+
def _is_proxy_enabled(self):
|
|
28
|
+
return self._get_assistant_adapter().is_available()
|
|
29
|
+
|
|
30
|
+
def _get_base_prompt(self):
|
|
31
|
+
return self._get_assistant_adapter().get_system_prompt()
|
|
32
|
+
|
|
33
|
+
def _get_max_messages_per_session(self):
|
|
34
|
+
return (
|
|
35
|
+
self._get_registry_record(
|
|
36
|
+
f"{_SETTINGS_PREFIX}.max_messages_per_session", 0
|
|
37
|
+
)
|
|
38
|
+
or 0
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def _validate_message_limit(self, body):
|
|
42
|
+
max_messages = self._get_max_messages_per_session()
|
|
43
|
+
if max_messages <= 0:
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
messages = body.get("messages", [])
|
|
47
|
+
user_messages_count = sum(
|
|
48
|
+
1
|
|
49
|
+
for message in messages
|
|
50
|
+
if isinstance(message, dict) and message.get("role") == "user"
|
|
51
|
+
)
|
|
52
|
+
if user_messages_count <= max_messages:
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
return self._json_error(
|
|
56
|
+
400,
|
|
57
|
+
"Maximum messages per conversation exceeded. "
|
|
58
|
+
"Start a new conversation.",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def _inject_base_prompt(self, body):
|
|
62
|
+
base_prompt = self._get_base_prompt()
|
|
63
|
+
if not base_prompt:
|
|
64
|
+
return body
|
|
65
|
+
|
|
66
|
+
messages = body.get("messages", [])
|
|
67
|
+
if not isinstance(messages, list):
|
|
68
|
+
messages = []
|
|
69
|
+
|
|
70
|
+
first_message = messages[0] if messages else None
|
|
71
|
+
if (
|
|
72
|
+
isinstance(first_message, dict)
|
|
73
|
+
and first_message.get("role") == "system"
|
|
74
|
+
and first_message.get("content") == base_prompt
|
|
75
|
+
):
|
|
76
|
+
return body
|
|
77
|
+
|
|
78
|
+
updated_body = dict(body)
|
|
79
|
+
updated_body["messages"] = [
|
|
80
|
+
{"role": "system", "content": base_prompt},
|
|
81
|
+
*messages,
|
|
82
|
+
]
|
|
83
|
+
return updated_body
|
|
84
|
+
|
|
85
|
+
def _prepare_request_body(self, body):
|
|
86
|
+
limit_error = self._validate_message_limit(body)
|
|
87
|
+
if limit_error is not None:
|
|
88
|
+
return body, limit_error
|
|
89
|
+
return self._inject_base_prompt(body), None
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from plone.app.layout.viewlets.common import ViewletBase
|
|
5
|
+
from zope.component import getMultiAdapter
|
|
6
|
+
|
|
7
|
+
from imio.omnia.assistant.interfaces import IOmniaAssistantAdapter
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class OmniaAssistantConfigViewlet(ViewletBase):
|
|
11
|
+
"""Inject window.omnia_assistant_settings from Plone registry into the page."""
|
|
12
|
+
|
|
13
|
+
def available(self):
|
|
14
|
+
adapter = getMultiAdapter(
|
|
15
|
+
(self.context, self.request), IOmniaAssistantAdapter
|
|
16
|
+
)
|
|
17
|
+
return adapter.is_available()
|
|
18
|
+
|
|
19
|
+
def config_json(self):
|
|
20
|
+
if not self.available():
|
|
21
|
+
return None
|
|
22
|
+
adapter = getMultiAdapter(
|
|
23
|
+
(self.context, self.request), IOmniaAssistantAdapter
|
|
24
|
+
)
|
|
25
|
+
return json.dumps(adapter.get_config())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from zope.interface import Interface
|
|
3
|
+
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class IImioOmniaAssistantLayer(IDefaultBrowserLayer):
|
|
7
|
+
"""Marker interface that defines a browser layer."""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class IOmniaAssistantAdapter(Interface):
|
|
11
|
+
"""Expose assistant availability, prompt and frontend overrides."""
|
|
12
|
+
|
|
13
|
+
def is_available():
|
|
14
|
+
"""Return True when the assistant should be exposed and callable."""
|
|
15
|
+
|
|
16
|
+
def get_system_prompt():
|
|
17
|
+
"""Return the server-side system prompt prepended to conversations."""
|
|
18
|
+
|
|
19
|
+
def get_config():
|
|
20
|
+
"""Return frontend runtime config overrides as a dict."""
|
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import pkg_resources
|
|
5
|
+
import subprocess
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
domain = 'imio.omnia.assistant'
|
|
9
|
+
os.chdir(pkg_resources.resource_filename(domain, ''))
|
|
10
|
+
os.chdir('../../../')
|
|
11
|
+
target_path = 'src/imio/omnia/assistant/'
|
|
12
|
+
locale_path = target_path + 'locales/'
|
|
13
|
+
i18ndude = './bin/i18ndude'
|
|
14
|
+
|
|
15
|
+
# ignore node_modules files resulting in errors
|
|
16
|
+
excludes = '"*.html *json-schema*.xml"'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def locale_folder_setup():
|
|
20
|
+
os.chdir(locale_path)
|
|
21
|
+
languages = [d for d in os.listdir('.') if os.path.isdir(d)]
|
|
22
|
+
for lang in languages:
|
|
23
|
+
folder = os.listdir(lang)
|
|
24
|
+
if 'LC_MESSAGES' in folder:
|
|
25
|
+
continue
|
|
26
|
+
else:
|
|
27
|
+
lc_messages_path = lang + '/LC_MESSAGES/'
|
|
28
|
+
os.mkdir(lc_messages_path)
|
|
29
|
+
cmd = 'msginit --locale={0} --input={1}.pot --output={2}/LC_MESSAGES/{3}.po'.format( # NOQA: E501
|
|
30
|
+
lang,
|
|
31
|
+
domain,
|
|
32
|
+
lang,
|
|
33
|
+
domain,
|
|
34
|
+
)
|
|
35
|
+
subprocess.call(
|
|
36
|
+
cmd,
|
|
37
|
+
shell=True,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
os.chdir('../../../../')
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _rebuild():
|
|
44
|
+
cmd = '{i18ndude} rebuild-pot --pot {locale_path}/{domain}.pot --exclude {excludes} --create {domain} {target_path}'.format( # NOQA: E501
|
|
45
|
+
i18ndude=i18ndude,
|
|
46
|
+
locale_path=locale_path,
|
|
47
|
+
domain=domain,
|
|
48
|
+
target_path=target_path,
|
|
49
|
+
excludes=excludes,
|
|
50
|
+
)
|
|
51
|
+
subprocess.call(
|
|
52
|
+
cmd,
|
|
53
|
+
shell=True,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _sync():
|
|
58
|
+
cmd = '{0} sync --pot {1}/{2}.pot {3}*/LC_MESSAGES/{4}.po'.format(
|
|
59
|
+
i18ndude,
|
|
60
|
+
locale_path,
|
|
61
|
+
domain,
|
|
62
|
+
locale_path,
|
|
63
|
+
domain,
|
|
64
|
+
)
|
|
65
|
+
subprocess.call(
|
|
66
|
+
cmd,
|
|
67
|
+
shell=True,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def update_locale():
|
|
72
|
+
locale_folder_setup()
|
|
73
|
+
_sync()
|
|
74
|
+
_rebuild()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from Products.CMFPlone.interfaces import INonInstallable
|
|
3
|
+
from zope.interface import implementer
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@implementer(INonInstallable)
|
|
7
|
+
class HiddenProfiles(object):
|
|
8
|
+
|
|
9
|
+
def getNonInstallableProfiles(self):
|
|
10
|
+
"""Hide uninstall profile from site-creation and quickinstaller."""
|
|
11
|
+
return [
|
|
12
|
+
"imio.omnia.assistant:uninstall",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
def getNonInstallableProducts(self):
|
|
16
|
+
"""Hide the upgrades package from site-creation and quickinstaller."""
|
|
17
|
+
return ["imio.omnia.assistant.upgrades"]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def post_install(context):
|
|
21
|
+
"""Post install script"""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def uninstall(context):
|
|
25
|
+
"""Uninstall script"""
|
|
26
|
+
from plone.registry.interfaces import IRegistry
|
|
27
|
+
from zope.component import getUtility
|
|
28
|
+
|
|
29
|
+
registry = getUtility(IRegistry)
|
|
30
|
+
|
|
31
|
+
# Disable assistant bundles
|
|
32
|
+
for bundle_name in ("omnia-assistant-preact", "omnia-assistant"):
|
|
33
|
+
key = f"plone.bundles/{bundle_name}.enabled"
|
|
34
|
+
if key in registry.records:
|
|
35
|
+
registry[key] = False
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
|
|
3
|
+
from plone.app.testing import applyProfile
|
|
4
|
+
from plone.app.testing import FunctionalTesting
|
|
5
|
+
from plone.app.testing import IntegrationTesting
|
|
6
|
+
from plone.app.testing import PloneSandboxLayer
|
|
7
|
+
from plone.testing import z2
|
|
8
|
+
|
|
9
|
+
import imio.omnia.assistant
|
|
10
|
+
from imio.omnia.core.testing import IMIO_OMNIA_CORE_FIXTURE
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ImioOmniaAssistantLayer(PloneSandboxLayer):
|
|
14
|
+
|
|
15
|
+
defaultBases = (IMIO_OMNIA_CORE_FIXTURE,)
|
|
16
|
+
|
|
17
|
+
def setUpZope(self, app, configurationContext):
|
|
18
|
+
self.loadZCML(package=imio.omnia.assistant)
|
|
19
|
+
|
|
20
|
+
def setUpPloneSite(self, portal):
|
|
21
|
+
applyProfile(portal, "imio.omnia.assistant:default")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
IMIO_OMNIA_ASSISTANT_FIXTURE = ImioOmniaAssistantLayer()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
IMIO_OMNIA_ASSISTANT_INTEGRATION_TESTING = IntegrationTesting(
|
|
28
|
+
bases=(IMIO_OMNIA_ASSISTANT_FIXTURE,),
|
|
29
|
+
name="ImioOmniaAssistantLayer:IntegrationTesting",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
IMIO_OMNIA_ASSISTANT_FUNCTIONAL_TESTING = FunctionalTesting(
|
|
34
|
+
bases=(IMIO_OMNIA_ASSISTANT_FIXTURE,),
|
|
35
|
+
name="ImioOmniaAssistantLayer:FunctionalTesting",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
IMIO_OMNIA_ASSISTANT_ACCEPTANCE_TESTING = FunctionalTesting(
|
|
40
|
+
bases=(
|
|
41
|
+
IMIO_OMNIA_ASSISTANT_FIXTURE,
|
|
42
|
+
REMOTE_LIBRARY_BUNDLE_FIXTURE,
|
|
43
|
+
z2.ZSERVER_FIXTURE,
|
|
44
|
+
),
|
|
45
|
+
name="ImioOmniaAssistantLayer:AcceptanceTesting",
|
|
46
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Tests for assistant control-panel helpers."""
|
|
3
|
+
import unittest
|
|
4
|
+
from unittest.mock import MagicMock
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
|
|
7
|
+
from imio.omnia.assistant.browser.controlpanel import (
|
|
8
|
+
OmniaModelsVocabularyFactory,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestOmniaModelsVocabularyFactory(unittest.TestCase):
|
|
13
|
+
def test_returns_models_from_service(self):
|
|
14
|
+
service = MagicMock()
|
|
15
|
+
service.list_models.return_value = {
|
|
16
|
+
"data": [{"id": "gpt-4.1-mini"}, {"id": "gpt-4.1"}]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
with patch(
|
|
20
|
+
"imio.omnia.assistant.browser.controlpanel.api.portal.get",
|
|
21
|
+
return_value=object(),
|
|
22
|
+
), patch(
|
|
23
|
+
"imio.omnia.assistant.browser.controlpanel.getRequest",
|
|
24
|
+
return_value=object(),
|
|
25
|
+
), patch(
|
|
26
|
+
"imio.omnia.assistant.browser.controlpanel.getMultiAdapter",
|
|
27
|
+
return_value=service,
|
|
28
|
+
):
|
|
29
|
+
vocabulary = OmniaModelsVocabularyFactory()(None)
|
|
30
|
+
|
|
31
|
+
self.assertEqual(
|
|
32
|
+
[term.value for term in vocabulary],
|
|
33
|
+
["gpt-4.1-mini", "gpt-4.1"],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def test_falls_back_to_current_registry_value_when_service_fails(self):
|
|
37
|
+
with patch(
|
|
38
|
+
"imio.omnia.assistant.browser.controlpanel.api.portal.get",
|
|
39
|
+
return_value=object(),
|
|
40
|
+
), patch(
|
|
41
|
+
"imio.omnia.assistant.browser.controlpanel.getRequest",
|
|
42
|
+
return_value=object(),
|
|
43
|
+
), patch(
|
|
44
|
+
"imio.omnia.assistant.browser.controlpanel.getMultiAdapter",
|
|
45
|
+
side_effect=RuntimeError("boom"),
|
|
46
|
+
), patch(
|
|
47
|
+
"imio.omnia.assistant.browser.controlpanel.api.portal.get_registry_record",
|
|
48
|
+
return_value="saved-model",
|
|
49
|
+
), patch(
|
|
50
|
+
"imio.omnia.assistant.browser.controlpanel.logger.error"
|
|
51
|
+
) as mock_error:
|
|
52
|
+
vocabulary = OmniaModelsVocabularyFactory()(None)
|
|
53
|
+
|
|
54
|
+
self.assertEqual([term.value for term in vocabulary], ["saved-model"])
|
|
55
|
+
mock_error.assert_called_once()
|
|
56
|
+
|
|
57
|
+
def test_returns_empty_vocabulary_when_no_models_are_available(self):
|
|
58
|
+
service = MagicMock()
|
|
59
|
+
service.list_models.return_value = {"data": []}
|
|
60
|
+
|
|
61
|
+
with patch(
|
|
62
|
+
"imio.omnia.assistant.browser.controlpanel.api.portal.get",
|
|
63
|
+
return_value=object(),
|
|
64
|
+
), patch(
|
|
65
|
+
"imio.omnia.assistant.browser.controlpanel.getRequest",
|
|
66
|
+
return_value=object(),
|
|
67
|
+
), patch(
|
|
68
|
+
"imio.omnia.assistant.browser.controlpanel.getMultiAdapter",
|
|
69
|
+
return_value=service,
|
|
70
|
+
), patch(
|
|
71
|
+
"imio.omnia.assistant.browser.controlpanel.api.portal.get_registry_record",
|
|
72
|
+
return_value=None,
|
|
73
|
+
):
|
|
74
|
+
vocabulary = OmniaModelsVocabularyFactory()(None)
|
|
75
|
+
|
|
76
|
+
self.assertEqual(list(vocabulary), [])
|