|
7 | 7 |
|
8 | 8 | import json |
9 | 9 | from contextlib import contextmanager |
10 | | -from dataclasses import replace as dataclass_replace |
11 | 10 | from typing import Generator, Mapping, Optional, Tuple, Union |
12 | 11 |
|
13 | 12 | import oracledb |
|
25 | 24 | from select_ai.db import cursor |
26 | 25 | from select_ai.errors import ( |
27 | 26 | ProfileAttributesEmptyError, |
28 | | - ProfileExistsError, |
29 | 27 | ProfileNotFoundError, |
30 | 28 | ) |
31 | 29 | from select_ai.feedback import FeedbackOperation, FeedbackType |
@@ -59,14 +57,14 @@ def _init_profile(self) -> None: |
59 | 57 | if self.profile_name: |
60 | 58 | profile_exists = False |
61 | 59 | try: |
62 | | - saved_attributes = self._get_attributes( |
63 | | - profile_name=self.profile_name, |
64 | | - raise_on_empty=True, |
65 | | - ) |
66 | 60 | saved_description = self._get_profile_description( |
67 | 61 | profile_name=self.profile_name |
68 | 62 | ) |
69 | 63 | profile_exists = True |
| 64 | + saved_attributes = self._get_attributes( |
| 65 | + profile_name=self.profile_name, |
| 66 | + raise_on_empty=True, |
| 67 | + ) |
70 | 68 | self._raise_error_if_profile_exists() |
71 | 69 | except ProfileAttributesEmptyError: |
72 | 70 | if self.raise_error_on_empty_attributes: |
@@ -551,6 +549,34 @@ def generate_synthetic_data( |
551 | 549 | keyword_parameters=keyword_parameters, |
552 | 550 | ) |
553 | 551 |
|
| 552 | + def translate( |
| 553 | + self, text: str, source_language: str, target_language: str |
| 554 | + ) -> Union[str, None]: |
| 555 | + """ |
| 556 | + Translate a text using a source language and a target language |
| 557 | +
|
| 558 | + :param str text: Text to translate |
| 559 | + :param str source_language: Source language |
| 560 | + :param str target_language: Target language |
| 561 | + :return: str |
| 562 | + """ |
| 563 | + parameters = { |
| 564 | + "profile_name": self.profile_name, |
| 565 | + "text": text, |
| 566 | + "source_language": source_language, |
| 567 | + "target_language": target_language, |
| 568 | + } |
| 569 | + with cursor() as cr: |
| 570 | + data = cr.callfunc( |
| 571 | + "DBMS_CLOUD_AI.TRANSLATE", |
| 572 | + oracledb.DB_TYPE_CLOB, |
| 573 | + keyword_parameters=parameters, |
| 574 | + ) |
| 575 | + if data is not None: |
| 576 | + result = data.read() |
| 577 | + return result |
| 578 | + return None |
| 579 | + |
554 | 580 |
|
555 | 581 | class Session: |
556 | 582 | """Session lets you persist request parameters across DBMS_CLOUD_AI |
|
0 commit comments