yashmakan commited on
Commit
57eb2e6
1 Parent(s): 73f1c56

Update services/utils.py

Browse files
Files changed (1) hide show
  1. services/utils.py +10 -7
services/utils.py CHANGED
@@ -21,12 +21,12 @@ import json
21
  api_key=os.getenv('OPENAI_API_KEY')
22
 
23
  class Candidate(BaseModel):
24
- 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.")
25
- 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 mark value as null.")
26
- 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.")
27
- no_of_items: str = Field(description="Number of items in the order.If the information is not present mark the value as null.")
28
- 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.")
29
- Date: str = Field(description="Date of purchase. Make sure the date format is in dd-MM-yyyy.If the information is not present mark the value as null.")
30
 
31
 
32
  # async def initialize_openai():
@@ -41,7 +41,10 @@ def strcuture_document_data(raw_text:str)->dict:
41
  # model_name = "text-davinci-003"
42
  temperature = 0.0
43
  model = OpenAI(model_name=model_name, temperature=temperature, max_tokens=800)
44
- doc_query = "Strictly Return only a json which contains important entities from the given receipt."+"\n"+"Receipt Data : \n" + raw_text
 
 
 
45
  parser = PydanticOutputParser(pydantic_object=Candidate)
46
 
47
  prompt = PromptTemplate(
 
21
  api_key=os.getenv('OPENAI_API_KEY')
22
 
23
  class Candidate(BaseModel):
24
+ brand: str = Field(description="Please identify and provide the primary brand name listed on the receipt. If multiple brand names are present, determine and specify the most prominent or relevant brand associated with the primary transaction on the receipt. If the brand name is not explicitly mentioned, include any contextual details or indirect indicators that might help in accurately identifying the brand. In cases where the brand name is absent or ambiguous, clearly state 'null' as the response.")
25
+ total_cost: str = Field(description="Identify and provide the 'Total Order Value' listed on the receipt. Please specify the exact section where this value is noted, typically labeled as 'Total', 'Total Amount', or similar variations such as 'Grand Total'. Include any other labeling variations that might represent the total order value. If the total order value is not present or cannot be determined, explicitly state 'null' as the response.")
26
+ location: str = Field(description="Please provide the city and state where the purchase was made, as indicated on the receipt. For travel-related receipts, extract the location from which the booking was initiated, focusing on the booking origin or departure city/state, rather than the destination. Look for specific details such as the departure airport code, departure city, or the booking location mentioned in the itinerary or booking confirmation section. These details typically indicate the purchase's origin. If the purchase location is not explicitly stated or if the information is ambiguous, provide any relevant clues or context from the receipt that might assist in accurately identifying the location. If no such information is available, or if it remains unclear, clearly mark the response as 'null'")
27
+ no_of_items: str = Field(description="Specify the total number of items listed in the order as reflected in the receipt or document. If the total count of items is not explicitly mentioned or if it cannot be determined from the provided document, please assign and return the value 'null'.")
28
+ purchase_category: str = Field(description="Identify and specify the purchase category. Choose from the following predefined categories: fashion, home, travel, food, groceries, hotels, spa, insurance, or others. If the purchase category is not explicitly stated on the receipt or document, or if it cannot be accurately determined based on the available information, assign and return the value 'null'.")
29
+ Date: str = Field(description="Specify the date of purchase in the format dd-MM-yyyy. If the date of purchase is not explicitly provided on the receipt or document, or if it cannot be accurately determined, assign the value 'null'. Ensure the date is formatted correctly as day, month, and year in two digits each.")
30
 
31
 
32
  # async def initialize_openai():
 
41
  # model_name = "text-davinci-003"
42
  temperature = 0.0
43
  model = OpenAI(model_name=model_name, temperature=temperature, max_tokens=800)
44
+ doc_query = (
45
+ "Extract and return a JSON object containing only the key entities from the provided receipt. "
46
+ "\nReceipt Data:\n" + raw_text
47
+ )
48
  parser = PydanticOutputParser(pydantic_object=Candidate)
49
 
50
  prompt = PromptTemplate(