vkumartr commited on
Commit
75d34db
·
verified ·
1 Parent(s): bbfb943

Hide openAI

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -142,32 +142,32 @@ Use the correct currency and amounts for each invoice field.
142
  For each line item, provide the Description, Tax Percentage, Tax Amount, and Amount.
143
  If certain values are missing or not applicable, leave them empty or set them as null where necessary.
144
  This JSON format will be used to store and manage invoices in a structured and uniform way. Please ensure only return JSON format. No extra content should not provide."""
145
- try:
146
- response = openai.ChatCompletion.create(
147
- model="gpt-4o-mini",
148
- messages=[
149
- {"role": "system", "content": system_prompt},
150
- {"role": "user", "content": f"{text}"}
151
- ],
152
- temperature=0.5,
153
- max_tokens=16384
154
- )
155
- content = response.choices[0].message.content.strip()
156
- print("Before content:", content)
157
- cleaned_content = re.sub(r'^.*```json\n', '', content) # Remove '```json\n' at the beginning
158
- cleaned_content = re.sub(r'\n```$', '', cleaned_content) # Remove '\n```' at the end
159
-
160
- # Step 2: Parse the cleaned content as JSON
161
- try:
162
- parsed_content = json.loads(cleaned_content)
163
- return parsed_content
164
- except json.JSONDecodeError as e:
165
- print("Error parsing JSON:", e)
166
- # Optionally, print the cleaned content to debug
167
- print("Cleaned content:", cleaned_content)
168
- return None
169
- except Exception as e:
170
- return f"Error in summarization: {str(e)}"
171
 
172
  # Dependency to check API Key
173
  def verify_api_key(api_key: str = Header(...)):
 
142
  For each line item, provide the Description, Tax Percentage, Tax Amount, and Amount.
143
  If certain values are missing or not applicable, leave them empty or set them as null where necessary.
144
  This JSON format will be used to store and manage invoices in a structured and uniform way. Please ensure only return JSON format. No extra content should not provide."""
145
+ # try:
146
+ # response = openai.ChatCompletion.create(
147
+ # model="gpt-4o-mini",
148
+ # messages=[
149
+ # {"role": "system", "content": system_prompt},
150
+ # {"role": "user", "content": f"{text}"}
151
+ # ],
152
+ # temperature=0.5,
153
+ # max_tokens=16384
154
+ # )
155
+ # content = response.choices[0].message.content.strip()
156
+ # print("Before content:", content)
157
+ # cleaned_content = re.sub(r'^.*```json\n', '', content) # Remove '```json\n' at the beginning
158
+ # cleaned_content = re.sub(r'\n```$', '', cleaned_content) # Remove '\n```' at the end
159
+
160
+ # # Step 2: Parse the cleaned content as JSON
161
+ # try:
162
+ # parsed_content = json.loads(cleaned_content)
163
+ # return parsed_content
164
+ # except json.JSONDecodeError as e:
165
+ # print("Error parsing JSON:", e)
166
+ # # Optionally, print the cleaned content to debug
167
+ # print("Cleaned content:", cleaned_content)
168
+ # return None
169
+ # except Exception as e:
170
+ # return f"Error in summarization: {str(e)}"
171
 
172
  # Dependency to check API Key
173
  def verify_api_key(api_key: str = Header(...)):