Skip to content

Commit 1a1a92a

Browse files
committed
cetificates issues handled for PVC | correct error propagation for failed requests and jobs
1 parent f688818 commit 1a1a92a

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ sample_200x100.csv
8484
Raw_Web_Visit_sample.csv
8585
Raw_Web_Visit_Sample.csv
8686
Raw_Web_Visit_Sample.csv
87+
app/test_models.py
88+
credit_card_example.json

app/core/model_handlers.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,18 @@ def _handle_openai_request(self, prompt: str):
316316
pool=5.0
317317
)
318318

319+
# Configure httpx client with certificate verification for private cloud
320+
if os.path.exists("/etc/ssl/certs/ca-certificates.crt"):
321+
http_client = httpx.Client(
322+
verify="/etc/ssl/certs/ca-certificates.crt",
323+
timeout=timeout_config
324+
)
325+
else:
326+
http_client = httpx.Client(timeout=timeout_config)
327+
319328
client = OpenAI(
320329
api_key=os.getenv('OPENAI_API_KEY'),
321-
timeout=timeout_config
330+
http_client=http_client
322331
)
323332
completion = client.chat.completions.create(
324333
model=self.model_id,
@@ -380,10 +389,19 @@ def _handle_caii_request(self, prompt: str):
380389
pool=5.0
381390
)
382391

392+
# Configure httpx client with certificate verification for private cloud
393+
if os.path.exists("/etc/ssl/certs/ca-certificates.crt"):
394+
http_client = httpx.Client(
395+
verify="/etc/ssl/certs/ca-certificates.crt",
396+
timeout=timeout_config
397+
)
398+
else:
399+
http_client = httpx.Client(timeout=timeout_config)
400+
383401
client_ca = OpenAI(
384402
base_url=caii_endpoint,
385403
api_key=API_KEY,
386-
timeout=timeout_config # Use the comprehensive timeout configuration
404+
http_client=http_client
387405
)
388406

389407
completion = client_ca.chat.completions.create(

app/services/synthesis_service.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,19 +1007,24 @@ async def generate_freeform(self, request: SynthesisRequest, job_name=None, is_d
10071007
json.dump(final_output, indent=2, fp=f)
10081008
self.logger.info(f"Saved {len(final_output)} results to {file_path}")
10091009

1010-
# Check if we have any critical model errors across all topics
1011-
has_critical_model_error = any(
1012-
topic_errors and any("ModelHandlerError" in error for error in topic_errors)
1013-
for _, _, topic_errors, _ in completed_topics
1014-
)
1010+
# Find the first critical model error message
1011+
first_critical_error = None
1012+
for _, _, topic_errors, _ in completed_topics:
1013+
if topic_errors:
1014+
for error in topic_errors:
1015+
if "ModelHandlerError" in error:
1016+
first_critical_error = error
1017+
break
1018+
if first_critical_error:
1019+
break
10151020

10161021
# After saving (or if no data), check for critical errors
1017-
if has_critical_model_error:
1022+
if first_critical_error:
10181023
if final_output:
10191024
self.logger.info(f"Saved {len(final_output)} results before failing due to model errors")
10201025
else:
10211026
self.logger.info("No results to save before failing due to model errors")
1022-
raise APIError("Critical model errors encountered during generation")
1027+
raise APIError(first_critical_error)
10231028

10241029
# Handle custom prompt, examples and schema
10251030
custom_prompt_str = PromptHandler.get_default_custom_prompt(request.use_case, request.custom_prompt)

0 commit comments

Comments
 (0)