Omkar008 commited on
Commit
b52a3d1
1 Parent(s): 1729933

Update services/utils.py

Browse files
Files changed (1) hide show
  1. services/utils.py +7 -7
services/utils.py CHANGED
@@ -19,12 +19,12 @@ from langchain_openai import OpenAI
19
  api_key=os.getenv('OPENAI_API_KEY')
20
 
21
  class Candidate(BaseModel):
22
- brand: str = Field(description="Please provide the name of the brand from which the receipt is. If there are multiple brand names present, please specify the most prominent or relevant brand associated with the receipt. If the brand name is not explicitly stated, provide any context or details that might help identify it accurately. If the information is not present or unclear, mark the value as Unknown Brand.")
23
- total_cost: str = Field(description="For example, you can specify the total order value section on the receipt, such as ‘Total’ or ‘Amount Due’, and describe where it's typically located (e.g., bottom right corner). Additionally, mention any common variations in labeling that might indicate the total order value, such as ‘Grand Total’,’Total Amount’, or ‘Balance Due’.")
24
- location: str = Field(description="Please provide the city and state where the purchase was made. If the receipt is related to travel, extract the location from where the booking was made, not the destination. Look for details such as the booking origin or departure city/state. If the purchase location is not explicitly stated, provide any relevant clues or context from the receipt to help identify it accurately. If the information is not present or unclear, mark the value as Unknown Location.For travel receipts, consider extracting details such as the departure airport code, departure city, or booking location mentioned in the itinerary or booking confirmation section. This location typically indicates where the purchase was initiated.")
25
- no_of_items: str = Field(description="Number of items in the order.If the information is not present mark the value as 0.")
26
- purchase_category: str = Field(description="The purchase category among fashion, home, travel, food, groceries, hotels, spa, insurance and others.If the information is not present mark the value as Unknown Category.")
27
- Date: str = Field(description="Date of purchase.If the information is not present mark the value as Unknown Date. Make sure the date format is in dd-MM-yyyy.")
28
 
29
 
30
  # async def initialize_openai():
@@ -39,7 +39,7 @@ def strcuture_document_data(raw_text:str)->dict:
39
  # model_name = "text-davinci-003"
40
  temperature = 0.0
41
  model = OpenAI(model_name=model_name, temperature=temperature, max_tokens=800)
42
- doc_query = "Return only a json which contains important entities from the given receipt.Also json should contain only these keys - brand,total_cost,location,no_of_items,purchase_category,Date. Make sure the date format is dd-MM-yyyy in the json. Response: " + raw_text
43
  parser = PydanticOutputParser(pydantic_object=Candidate)
44
 
45
  prompt = PromptTemplate(
 
19
  api_key=os.getenv('OPENAI_API_KEY')
20
 
21
  class Candidate(BaseModel):
22
+ brand: str = Field(description="Please provide the name of the brand from which the receipt is. If there are multiple brand names present, please specify the most prominent or relevant brand associated with the receipt. If the brand name is not explicitly stated, provide any context or details that might help identify it accurately. If the information is not present or unclear, strictly mark the value as 'null'.")
23
+ total_cost: str = Field(description="Fetch Total order value of the receipt.you can specify the total order value section on the receipt, such as ‘Total’ or ‘Total Amount’. Additionally, mention any common variations in labeling that might indicate the total order value, such as ‘Grand Total’,’Total Amount’.If you cannot find total order value then default value 'null'.")
24
+ location: str = Field(description="Please provide the city and state where the purchase was made. If the receipt is related to travel, extract the location from where the booking was made, not the destination. Look for details such as the booking origin or departure city/state. If the purchase location is not explicitly stated, provide any relevant clues or context from the receipt to help identify it accurately. If the information is not present or unclear, mark the value as 'null'.For travel receipts, consider extracting details such as the departure airport code, departure city, or booking location mentioned in the itinerary or booking confirmation section. This location typically indicates where the purchase was initiated.")
25
+ no_of_items: str = Field(description="Number of items in the order.If the information is not present mark the value as 'null'.")
26
+ purchase_category: str = Field(description="The purchase category among fashion, home, travel, food, groceries, hotels, spa, insurance and others.If the information is not present mark the value as 'null'.")
27
+ Date: str = Field(description="Date of purchase.If the information is not present mark the value as 'null'. Make sure the date format is in dd-MM-yyyy.")
28
 
29
 
30
  # async def initialize_openai():
 
39
  # model_name = "text-davinci-003"
40
  temperature = 0.0
41
  model = OpenAI(model_name=model_name, temperature=temperature, max_tokens=800)
42
+ doc_query = "Return only a json which contains important entities from the given receipt.Also json should strictly contain only these keys - brand,total_cost,location,no_of_items,purchase_category,Date."+"Always generate a json brand,total_cost,location,no_of_items,purchase_category,Date , even if these keys have value null."+"\n"+"Receipt Data : \n" + raw_text
43
  parser = PydanticOutputParser(pydantic_object=Candidate)
44
 
45
  prompt = PromptTemplate(