33
44import json
55
6- from openai .types .chat .parsed_chat_completion import ParsedChatCompletion
7-
86from libs .application .application_context import AppContext
97from libs .azure_helper .model .content_understanding import AnalyzedResult
108from libs .pipeline .entities .pipeline_file import ArtifactType , PipelineLogEntry
@@ -44,19 +42,17 @@ async def execute(self, context: MessageContext) -> StepResult:
4442 ** json .loads (output_file_json_string_from_extract )
4543 )
4644
47- # Get the result from Map step handler - OpenAI
45+ # Get the result from Map step handler - Azure AI Foundry
4846 output_file_json_string_from_map = self .download_output_file_to_json_string (
4947 processed_by = "map" ,
5048 artifact_type = ArtifactType .SchemaMappedData ,
5149 )
5250
53- # Deserialize the result to ParsedChatCompletion (Azure OpenAI)
54- gpt_result = ParsedChatCompletion (
55- ** json .loads (output_file_json_string_from_map )
56- )
51+ # Deserialize the result from Azure AI Foundry SDK response
52+ gpt_result = json .loads (output_file_json_string_from_map )
5753
58- # Mapped Result by GPT
59- parsed_message_from_gpt = gpt_result . choices [0 ]. message . parsed
54+ # Mapped Result from Azure AI Foundry
55+ parsed_message_from_gpt = gpt_result [ " choices" ] [0 ][ " message" ][ " parsed" ]
6056
6157 # Convert the parsed message to a dictionary
6258 gpt_evaluate_confidence_dict = parsed_message_from_gpt
@@ -69,7 +65,7 @@ async def execute(self, context: MessageContext) -> StepResult:
6965
7066 # Evaluate Confidence Score - GPT
7167 gpt_confidence_score = gpt_confidence (
72- gpt_evaluate_confidence_dict , gpt_result . choices [0 ]
68+ gpt_evaluate_confidence_dict , gpt_result [ " choices" ] [0 ]
7369 )
7470
7571 # Merge the confidence scores - Content Understanding and GPT results.
@@ -89,8 +85,8 @@ async def execute(self, context: MessageContext) -> StepResult:
8985 extracted_result = gpt_evaluate_confidence_dict ,
9086 confidence = merged_confidence_score ,
9187 comparison_result = result_data ,
92- prompt_tokens = gpt_result . usage . prompt_tokens ,
93- completion_tokens = gpt_result . usage . completion_tokens ,
88+ prompt_tokens = gpt_result [ " usage" ][ " prompt_tokens" ] ,
89+ completion_tokens = gpt_result [ " usage" ][ " completion_tokens" ] ,
9490 execution_time = 0 ,
9591 )
9692
0 commit comments