Spaces:
Sleeping
Sleeping
multiple outputs (map and data)
Browse files- llm_api.py +30 -2
llm_api.py
CHANGED
|
@@ -74,7 +74,6 @@ google_api_key = os.getenv("GOOGLE_API_KEY")
|
|
| 74 |
if not google_api_key:
|
| 75 |
raise ValueError("GOOGLE_API_KEY not set. Please check your environment variables.")
|
| 76 |
|
| 77 |
-
#TODO: make a format of the address in the prompt to the lm (street, building, city) and phone numbers
|
| 78 |
def llm_parser(docs, model="gemini-2.0-flash-001"):
|
| 79 |
llm = ChatGoogleGenerativeAI(model=model, temperature=0)
|
| 80 |
parser = PydanticOutputParser(pydantic_object=InsuredDetails)
|
|
@@ -82,9 +81,38 @@ def llm_parser(docs, model="gemini-2.0-flash-001"):
|
|
| 82 |
prompt = PromptTemplate(
|
| 83 |
template="""
|
| 84 |
Extract the insured business details from the following documents.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
{format_instructions}
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
Text:
|
| 89 |
{input_text}
|
| 90 |
""",
|
|
|
|
| 74 |
if not google_api_key:
|
| 75 |
raise ValueError("GOOGLE_API_KEY not set. Please check your environment variables.")
|
| 76 |
|
|
|
|
| 77 |
def llm_parser(docs, model="gemini-2.0-flash-001"):
|
| 78 |
llm = ChatGoogleGenerativeAI(model=model, temperature=0)
|
| 79 |
parser = PydanticOutputParser(pydantic_object=InsuredDetails)
|
|
|
|
| 81 |
prompt = PromptTemplate(
|
| 82 |
template="""
|
| 83 |
Extract the insured business details from the following documents.
|
| 84 |
+
Make sure to extract the full address. If the address is spread across multiple lines
|
| 85 |
+
(e.g., "building number" and "street name" separately),
|
| 86 |
+
combine them to form a full address in the format: street name, building number, city.
|
| 87 |
+
The contact phone number format should be: 05xxxxxxxx (ten digits).
|
| 88 |
|
| 89 |
{format_instructions}
|
| 90 |
+
|
| 91 |
+
### Examples:
|
| 92 |
+
|
| 93 |
+
Text:
|
| 94 |
+
讻转讜讘转 诪讘讜讟讞: 9, 讟讘专讬讛
|
| 95 |
+
讛注专讜转 诇讻转讜讘转 讛诪讘讜讟讞: 转诪专 9
|
| 96 |
+
|
| 97 |
+
Output:
|
| 98 |
+
business_name: null
|
| 99 |
+
business_address: 转诪专 9, 讟讘专讬讛
|
| 100 |
+
contact_name: null
|
| 101 |
+
contact_phone: null
|
| 102 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 103 |
+
|
| 104 |
+
Text:
|
| 105 |
+
Acme Corp is based at 123 Main St, Springfield. The contact person is Jane Doe, 055-123-4567.
|
| 106 |
+
|
| 107 |
+
Output:
|
| 108 |
+
business_name: Acme Corp
|
| 109 |
+
business_address: 123 Main St, Springfield
|
| 110 |
+
contact_name: Jane Doe
|
| 111 |
+
contact_phone: 0551234567
|
| 112 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 113 |
+
|
| 114 |
+
### Now extract the details for the following document:
|
| 115 |
+
|
| 116 |
Text:
|
| 117 |
{input_text}
|
| 118 |
""",
|