-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DERCBOT-1037] Use of PromptTemplate
- Loading branch information
Showing
11 changed files
with
105 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...estrator-server/src/main/python/server/src/gen_ai_orchestrator/services/utils/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
37 changes: 37 additions & 0 deletions
37
...or-server/src/main/python/server/src/gen_ai_orchestrator/services/utils/prompt_utility.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
from jinja2 import Template, TemplateError | ||
|
||
from gen_ai_orchestrator.errors.exceptions.exceptions import ( | ||
GenAIPromptTemplateException, | ||
) | ||
from gen_ai_orchestrator.models.errors.errors_models import ErrorInfo | ||
from gen_ai_orchestrator.models.prompt.prompt_formatter import PromptFormatter | ||
from gen_ai_orchestrator.models.prompt.prompt_template import PromptTemplate | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def validate_prompt_template(prompt: PromptTemplate): | ||
""" | ||
Prompt template validation | ||
Args: | ||
prompt: The prompt template | ||
Returns: | ||
Nothing. | ||
Raises: | ||
GenAIPromptTemplateException: if template is incorrect | ||
""" | ||
if PromptFormatter.JINJA2 == prompt.formatter: | ||
try: | ||
Template(prompt.template).render(prompt.inputs) | ||
except TemplateError as exc: | ||
logger.error('Prompt completion - template validation failed!') | ||
logger.error(exc) | ||
raise GenAIPromptTemplateException( | ||
ErrorInfo( | ||
error=exc.__class__.__name__, | ||
cause=str(exc), | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.