2323 validate_params_for_summary ,
2424)
2525from select_ai .db import cursor
26- from select_ai .errors import ProfileExistsError , ProfileNotFoundError
26+ from select_ai .errors import (
27+ ProfileAttributesEmptyError ,
28+ ProfileExistsError ,
29+ ProfileNotFoundError ,
30+ )
2731from select_ai .feedback import FeedbackOperation , FeedbackType
2832from select_ai .provider import Provider
2933from select_ai .sql import (
@@ -56,34 +60,22 @@ def _init_profile(self) -> None:
5660 profile_exists = False
5761 try :
5862 saved_attributes = self ._get_attributes (
63+ profile_name = self .profile_name ,
64+ raise_on_empty = True ,
65+ )
66+ saved_description = self ._get_profile_description (
5967 profile_name = self .profile_name
6068 )
6169 profile_exists = True
62- if not self .replace and not self .merge :
63- if (
64- self .attributes is not None
65- or self .description is not None
66- ):
67- if self .raise_error_if_exists :
68- raise ProfileExistsError (self .profile_name )
69-
70- if self .description is None and not self .replace :
71- self .description = self ._get_profile_description (
72- profile_name = self .profile_name
73- )
70+ self ._raise_error_if_profile_exists ()
71+ except ProfileAttributesEmptyError :
72+ if self .raise_error_on_empty_attributes :
73+ raise
7474 except ProfileNotFoundError :
7575 if self .attributes is None and self .description is None :
7676 raise
7777 else :
78- if self .attributes is None :
79- self .attributes = saved_attributes
80- if self .merge :
81- self .replace = True
82- if self .attributes is not None :
83- self .attributes = dataclass_replace (
84- saved_attributes ,
85- ** self .attributes .dict (exclude_null = True ),
86- )
78+ self ._merge_attributes (saved_attributes , saved_description )
8779 if self .replace or not profile_exists :
8880 self .create (replace = self .replace )
8981 else : # profile name is None
@@ -112,12 +104,15 @@ def _get_profile_description(profile_name) -> Union[str, None]:
112104 raise ProfileNotFoundError (profile_name )
113105
114106 @staticmethod
115- def _get_attributes (profile_name ) -> ProfileAttributes :
107+ def _get_attributes (
108+ profile_name , raise_on_empty : bool = False
109+ ) -> Union [ProfileAttributes , None ]:
116110 """Get AI profile attributes from the Database
117111
118112 :param str profile_name: Name of the profile
113+ :param bool raise_on_empty: Raise an error if attributes are empty
119114 :return: select_ai.ProfileAttributes
120- :raises: ProfileNotFoundError
115+ :raises: select_ai.errors.ProfileAttributesEmptyError
121116 """
122117 with cursor () as cr :
123118 cr .execute (
@@ -128,7 +123,11 @@ def _get_attributes(profile_name) -> ProfileAttributes:
128123 if attributes :
129124 return ProfileAttributes .create (** dict (attributes ))
130125 else :
131- raise ProfileNotFoundError (profile_name = profile_name )
126+ if raise_on_empty :
127+ raise ProfileAttributesEmptyError (
128+ profile_name = profile_name
129+ )
130+ return None
132131
133132 def get_attributes (self ) -> ProfileAttributes :
134133 """Get AI profile attributes from the Database
@@ -278,7 +277,6 @@ def _save_feedback(
278277 operation = operation ,
279278 )
280279 params ["profile_name" ] = self .profile_name
281- print (params )
282280 with cursor () as cr :
283281 cr .callproc ("DBMS_CLOUD_AI.FEEDBACK" , keyword_parameters = params )
284282
@@ -363,7 +361,9 @@ def list(
363361 for row in cr .fetchall ():
364362 profile_name = row [0 ]
365363 yield cls (
366- profile_name = profile_name , raise_error_if_exists = False
364+ profile_name = profile_name ,
365+ raise_error_if_exists = False ,
366+ raise_error_on_empty_attributes = False ,
367367 )
368368
369369 def generate (
@@ -513,7 +513,6 @@ def summarize(
513513 params = params ,
514514 )
515515 parameters ["profile_name" ] = self .profile_name
516- print (parameters )
517516 with cursor () as cr :
518517 data = cr .callfunc (
519518 "DBMS_CLOUD_AI.SUMMARIZE" ,
0 commit comments