AI Services¶
AIService Class¶
ai_services.AIService
¶
AIService handles interactions with multiple AI services (OpenAI, GCP, and Azure).
Attributes:
Name | Type | Description |
---|---|---|
technology |
str
|
The technology field from the config. |
domain |
str
|
The domain field from the config. |
segment |
str
|
The segment field from the config. |
anonymous_access |
bool
|
The anonymous access field from the config. |
debug_mode |
bool
|
Flag for enabling debug mode. |
gcp_project |
str
|
GCP project ID for Gemini API Vertex. |
gcp_location |
str
|
GCP location for Gemini API Vertex. |
gcp_model_id |
str
|
Model ID for Gemini API Vertex. |
azure_endpoint |
str
|
Azure OpenAI endpoint. |
azure_location |
str
|
Azure OpenAI location/region. |
Source code in src/ai_services.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
__init__(api_key=False, gcp_project=None, gcp_location=None, gcp_model_id=None, azure_endpoint=None, azure_location=None, debug_mode=False)
¶
Initialize AIService with API key for OpenAI, Azure, and GCP project details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
str
|
The API key for OpenAI or Azure. |
False
|
gcp_project
|
str
|
GCP project ID for Google AI. |
None
|
gcp_location
|
str
|
GCP location for Google AI. |
None
|
gcp_model_id
|
str
|
Model ID for Google AI. |
None
|
azure_endpoint
|
str
|
The Azure OpenAI API endpoint. |
None
|
azure_location
|
str
|
The Azure OpenAI API location/region. |
None
|
debug_mode
|
bool
|
If True, enables debug logging. |
False
|
Source code in src/ai_services.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
cleanup_and_parse_json(text)
¶
Clean up and parse a JSON string from text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text containing JSON. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
The parsed JSON object, or an empty dict if parsing fails. |
Source code in src/ai_services.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
generate_emails(segment, domain, email_num)
¶
Generate a sample email related to the given segment and domain.
This method uses the OpenAI API to generate a sample email, including the subject, body, and recipient address. The email content is saved to a file for later use.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segment
|
str
|
The segment or topic of the email. |
required |
domain
|
str
|
The domain to use for the email address. |
required |
email_num
|
int
|
The identifier number for the email. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The generated email content. |
Source code in src/ai_services.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
load_responses(response_type)
¶
Load responses from a saved file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response_type
|
str
|
The type of response (e.g., "smtp"). |
required |
Returns:
Type | Description |
---|---|
dict or str: The loaded response as a JSON dictionary if valid, otherwise returns the raw text as a string. |
Source code in src/ai_services.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
query_responses(prompt, response_type, use_openai=True)
¶
Query AI services (OpenAI or Google Gemini Vertex) for responses based on the provided prompt and response type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The prompt to send to the AI service. |
required |
response_type
|
str
|
The type of response expected (e.g., "email"). |
required |
use_openai
|
bool
|
Whether to use OpenAI (True) or Gemini Vertex (False). |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
The response text from the AI service. |
Source code in src/ai_services.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|