manabb commited on
Commit
2ad9e33
·
verified ·
1 Parent(s): 177b3ba

Update manabCQgenetaion.py

Browse files
Files changed (1) hide show
  1. manabCQgenetaion.py +67 -45
manabCQgenetaion.py CHANGED
@@ -37,54 +37,63 @@ def compliance_import_OEM(manabfile: str, client):
37
  doc_text = "\n\n".join(doc.page_content for doc in docs) # Flatten to string[cite:5]
38
 
39
  #==================
 
40
  SYSTEM_PROMPT = """
41
- You are a strict procurement compliance auditor with dual responsibilities:
42
 
43
- 1. **EXTRACTION**: Extract specific fields from vendor documents with zero hallucination
44
- 2. **COMPLIANCE**: Perform strict point-by-point compliance checking against manual rules
45
 
46
- MANDATORY INSTRUCTIONS (APPLY TO BOTH TASKS):
47
- 1. Do NOT assume anything beyond explicitly written text
48
- 2. Do NOT interpret or infer missing information
49
- 3. Missing information = null (extraction) OR NON-COMPLIANT (rules)
50
- 4. Partial matches = NON-COMPLIANT
51
- 5. Only explicit written evidence is valid
52
- 6. Quote exact sentences from document as evidence
53
 
54
- OUTPUT ONLY valid JSON. No explanations, commentary, or additional text.
55
 
56
- EXACT JSON SCHEMA:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  {
58
- "extraction": {{
59
- "Value of the offer": "string or null",
60
- "Dispatch point": "string or null",
61
- "mode of dispatch": "string or null",
62
- "Weight and dimension of item": "string or null",
63
- "Incoterm": "string or null",
64
- "Packing & forwarding": "string or null",
65
- "Cost of transportation/delivery from Ex work to the nearest port": "string or null",
66
- "Charges outside India": "string or null",
67
- "Third party Inspection or TPI": "string or null",
68
- "Currency of quoted price": "string or null",
69
- "Charges within India": "string or null",
70
- "Payment terms": "string or null",
71
- "Delivery period": "string or null",
72
- "OFFER VALIDITY": "string or null",
73
- "PRICE REDUCTION CLAUSE FOR DELAYED DELIVERY (LD)": "string or null",
74
- "GUARANTEE / WARRANTEE": "string or null",
75
- "interchangeability certificate": "string or null",
76
- "test report / inspection report": "string or null",
77
- "Certificate of origin": "string or null",
78
- }},
79
- "compliance_check": [
80
- {{
81
- "rule_heading": "Exact heading from manual",
82
- "status": "COMPLIANT or NON-COMPLIANT",
83
- "as_per_vendor": "Exact quoted sentence OR Not found in document"
84
- }}
85
- ]
86
  }
87
- """
 
 
88
  USER_PROMPT= f"""
89
  Document content (complete extracted text from vendor offer):
90
  {doc_text[:16000]}
@@ -110,15 +119,24 @@ def compliance_import_OEM(manabfile: str, client):
110
  max_tokens=3000,
111
  response_format={"type": "json_object"}
112
  )
113
-
114
- result = json.loads(response.choices[0].message.content)
 
 
115
 
116
  data=result
117
 
 
118
  extraction_df = pd.DataFrame(list(data['extraction'].items()), columns=['Field', 'Value'])
119
  compliance_df = pd.DataFrame(data['compliance_check'])
120
 
121
  # Generate HTML tables with Bootstrap styling
 
 
 
 
 
 
122
  extraction_html = extraction_df.to_html(
123
  index=False,
124
  escape=False,
@@ -131,7 +149,7 @@ def compliance_import_OEM(manabfile: str, client):
131
  classes='table table-striped table-bordered table-hover',
132
  table_id='compliance-table'
133
  )
134
- finalHtml = extraction_html+" "+compliance_html
135
  # Print DataFrames (for verification)
136
  #print("Extraction DataFrame:")
137
  #print(extraction_df)
@@ -141,5 +159,9 @@ def compliance_import_OEM(manabfile: str, client):
141
  #print(extraction_html)
142
  #print("\nCompliance HTML table:")
143
  #print(compliance_html)
 
 
 
 
144
 
145
- return finalHtml
 
37
  doc_text = "\n\n".join(doc.page_content for doc in docs) # Flatten to string[cite:5]
38
 
39
  #==================
40
+ #modified prompt with items value
41
  SYSTEM_PROMPT = """
42
+ You are a strict procurement compliance auditor with dual responsibilities:
43
 
44
+ 1. **EXTRACTION**: Extract specific fields from vendor documents with zero hallucination
45
+ 2. **COMPLIANCE**: Perform strict point-by-point compliance checking against manual rules
46
 
47
+ MANDATORY INSTRUCTIONS (APPLY TO BOTH TASKS):
48
+ 1. Do NOT assume anything beyond explicitly written text
49
+ 2. Do NOT interpret or infer missing information
50
+ 3. Missing information = null (extraction) OR NON-COMPLIANT (rules)
51
+ 4. Partial matches = NON-COMPLIANT
52
+ 5. Only explicit written evidence is valid
53
+ 6. Quote exact sentences from document as evidence
54
 
55
+ OUTPUT ONLY valid JSON. No explanations, commentary, or additional text.
56
 
57
+ EXACT JSON SCHEMA:
58
+ {
59
+ "extraction": {
60
+ "items": [
61
+ {
62
+ "item_description": "string or null",
63
+ "rate": "string or null",
64
+ "qty": "string or null",
65
+ "value": "string or null"
66
+ }
67
+ ],
68
+ "Value of the offer": "string or null",
69
+ "Dispatch point": "string or null",
70
+ "mode of dispatch": "string or null",
71
+ "Weight and dimension of item": "string or null",
72
+ "Incoterm": "string or null",
73
+ "Packing & forwarding": "string or null",
74
+ "Cost of transportation/delivery from Ex work to the nearest port": "string or null",
75
+ "Charges outside India": "string or null",
76
+ "Third party Inspection or TPI": "string or null",
77
+ "Currency of quoted price": "string or null",
78
+ "Charges within India": "string or null",
79
+ "Payment terms": "string or null",
80
+ "Delivery period": "string or null",
81
+ "OFFER VALIDITY": "string or null",
82
+ "PRICE REDUCTION CLAUSE FOR DELAYED DELIVERY (LD)": "string or null",
83
+ "GUARANTEE / WARRANTEE": "string or null",
84
+ "interchangeability certificate": "string or null",
85
+ "test report / inspection report": "string or null",
86
+ "Certificate of origin": "string or null"
87
+ },
88
+ "compliance_check": [
89
  {
90
+ "rule_heading": "Exact heading from manual",
91
+ "status": "COMPLIANT or NON-COMPLIANT",
92
+ "as_per_vendor": "Exact quoted sentence OR Not found in document"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
+ ]
95
+ }
96
+ """
97
  USER_PROMPT= f"""
98
  Document content (complete extracted text from vendor offer):
99
  {doc_text[:16000]}
 
119
  max_tokens=3000,
120
  response_format={"type": "json_object"}
121
  )
122
+ input_tokens = response.usage.prompt_tokens
123
+ output_tokens = response.usage.completion_tokens
124
+ total_tokens = response.usage.total_tokens
125
+ result_dic = json.loads(response.choices[0].message.content)
126
 
127
  data=result
128
 
129
+ extracted_item_value_df=pd.DataFrame(data['extraction']['items'])
130
  extraction_df = pd.DataFrame(list(data['extraction'].items()), columns=['Field', 'Value'])
131
  compliance_df = pd.DataFrame(data['compliance_check'])
132
 
133
  # Generate HTML tables with Bootstrap styling
134
+ extraction_item_value_html = extracted_item_value_df.to_html(
135
+ index=False,
136
+ escape=False,
137
+ classes='table table-striped table-bordered table-hover',
138
+ table_id='extraction-table'
139
+ )
140
  extraction_html = extraction_df.to_html(
141
  index=False,
142
  escape=False,
 
149
  classes='table table-striped table-bordered table-hover',
150
  table_id='compliance-table'
151
  )
152
+ finalHtml = extraction_item_value_html + " " + extraction_html+" "+compliance_html
153
  # Print DataFrames (for verification)
154
  #print("Extraction DataFrame:")
155
  #print(extraction_df)
 
159
  #print(extraction_html)
160
  #print("\nCompliance HTML table:")
161
  #print(compliance_html)
162
+ #usage
163
+ #print(result_dic["extraction"]["Value of the offer"])
164
+ #print (result_dic["extraction"]["Dispatch point"])
165
+ #print(result_dic["compliance_check"][0]['rule_heading'])
166
 
167
+ return finalHtml,input_tokens,output_tokens,total_tokens,result_dic