Spaces:
Running
Running
arvind6599
commited on
Commit
·
053ea77
1
Parent(s):
5ce1ae0
Updated the description
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ SCOPES = [
|
|
11 |
"https://www.googleapis.com/auth/drive"
|
12 |
]
|
13 |
|
|
|
|
|
|
|
14 |
# Initialize the OpenAI client with the API key from environment variables.
|
15 |
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
16 |
|
@@ -153,11 +156,12 @@ def submit_prompt(email, name, system_prompt_1, system_prompt_2, system_prompt_3
|
|
153 |
expected = item["expected"]
|
154 |
try:
|
155 |
response = client.chat.completions.create(
|
156 |
-
model=
|
157 |
messages=[
|
158 |
{"role": "system", "content": system_prompt_1},
|
159 |
{"role": "user", "content": question}
|
160 |
-
]
|
|
|
161 |
)
|
162 |
output_1 = response.choices[0].message.content.strip()
|
163 |
except Exception as e:
|
@@ -179,11 +183,12 @@ def submit_prompt(email, name, system_prompt_1, system_prompt_2, system_prompt_3
|
|
179 |
for doc in docs:
|
180 |
try:
|
181 |
response = client.chat.completions.create(
|
182 |
-
model=
|
183 |
messages=[
|
184 |
{"role": "system", "content": system_prompt_2},
|
185 |
{"role": "user", "content": f"Target company context: \n{output1} \n\n Paragraph:\n {doc}"}
|
186 |
-
]
|
|
|
187 |
)
|
188 |
output2 += "\n" + response.choices[0].message.content.strip()
|
189 |
except Exception as e:
|
@@ -194,11 +199,12 @@ def submit_prompt(email, name, system_prompt_1, system_prompt_2, system_prompt_3
|
|
194 |
output2 = output2.strip()
|
195 |
try:
|
196 |
response = client.chat.completions.create(
|
197 |
-
model=
|
198 |
messages=[
|
199 |
{"role": "system", "content": system_prompt_3},
|
200 |
{"role": "user", "content": f"Extracted information: \n{output2}"}
|
201 |
-
]
|
|
|
202 |
)
|
203 |
answer = response.choices[0].message.content.strip()
|
204 |
except Exception as e:
|
@@ -328,34 +334,30 @@ def build_interface():
|
|
328 |
"""
|
329 |
with gr.Blocks() as demo:
|
330 |
gr.Markdown("""
|
331 |
-
# Applicant Task: Target Company & Law Firm Identification
|
332 |
-
|
333 |
-
---
|
334 |
|
335 |
-
|
336 |
|
337 |
-
|
338 |
-
|
339 |
-
This task involves processing a user query to determine the relevance to the intended task, followed by analyzing textual data to extract information about law firms representing parties (Buyer, Seller, and Third Parties) and verifying the presence of a target company.
|
340 |
|
341 |
-
The system is designed to sequentially leverage three LLM functions:
|
342 |
|
343 |
-
### Step 1: LLM1
|
344 |
-
- Determines if the user's query mentions any target company.
|
345 |
-
- If no target company is found, LLM1 responds with a message wrapped in `<user_message></user_message>` XML tags to inform the user that the query is irrelevant to this task.
|
346 |
-
- If the query contains a target company, LLM1 moves forward with a formatted acknowledgment of the identified target company.
|
347 |
|
348 |
-
### Step 2: LLM2
|
349 |
-
- Examines four separate paragraphs independently.
|
350 |
-
- For each paragraph, extracts:
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
- Each paragraph's results are formatted and concatenated for the next step.
|
356 |
|
357 |
-
### Step 3: LLM3
|
358 |
-
- Compiles the information from all analyzed paragraphs and outputs a structured JSON object:
|
359 |
|
360 |
```json
|
361 |
{
|
@@ -366,6 +368,13 @@ The system is designed to sequentially leverage three LLM functions:
|
|
366 |
}
|
367 |
```
|
368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
The goal is to identify the representative law firms of involved parties and determine if the target company is mentioned, ensuring the results are structured and accurate.
|
370 |
|
371 |
---
|
|
|
11 |
"https://www.googleapis.com/auth/drive"
|
12 |
]
|
13 |
|
14 |
+
MODEL_NAME = "gpt-4o-mini" # Ensure this matches your deployed model.
|
15 |
+
TEMPERATURE = 0.2
|
16 |
+
|
17 |
# Initialize the OpenAI client with the API key from environment variables.
|
18 |
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
19 |
|
|
|
156 |
expected = item["expected"]
|
157 |
try:
|
158 |
response = client.chat.completions.create(
|
159 |
+
model=MODEL_NAME, # Ensure this model identifier matches your deployed model.
|
160 |
messages=[
|
161 |
{"role": "system", "content": system_prompt_1},
|
162 |
{"role": "user", "content": question}
|
163 |
+
],
|
164 |
+
temperature=TEMPERATURE
|
165 |
)
|
166 |
output_1 = response.choices[0].message.content.strip()
|
167 |
except Exception as e:
|
|
|
183 |
for doc in docs:
|
184 |
try:
|
185 |
response = client.chat.completions.create(
|
186 |
+
model=MODEL_NAME,
|
187 |
messages=[
|
188 |
{"role": "system", "content": system_prompt_2},
|
189 |
{"role": "user", "content": f"Target company context: \n{output1} \n\n Paragraph:\n {doc}"}
|
190 |
+
],
|
191 |
+
temperature=TEMPERATURE
|
192 |
)
|
193 |
output2 += "\n" + response.choices[0].message.content.strip()
|
194 |
except Exception as e:
|
|
|
199 |
output2 = output2.strip()
|
200 |
try:
|
201 |
response = client.chat.completions.create(
|
202 |
+
model=MODEL_NAME,
|
203 |
messages=[
|
204 |
{"role": "system", "content": system_prompt_3},
|
205 |
{"role": "user", "content": f"Extracted information: \n{output2}"}
|
206 |
+
],
|
207 |
+
temperature=TEMPERATURE,
|
208 |
)
|
209 |
answer = response.choices[0].message.content.strip()
|
210 |
except Exception as e:
|
|
|
334 |
"""
|
335 |
with gr.Blocks() as demo:
|
336 |
gr.Markdown("""
|
337 |
+
# Applicant Task: Target Company & Law Firm Identification
|
|
|
|
|
338 |
|
339 |
+
---
|
340 |
|
341 |
+
This task involves processing a user query to determine the relevance to the intended task, followed by analyzing textual data to extract information about law firms representing parties (Buyer, Seller, and Third Parties) and verifying the presence of a target company. You can refer to the following legal document: [SEC Agreement Example](https://www.sec.gov/Archives/edgar/data/28452/000119312505012401/dex101.html)
|
|
|
|
|
342 |
|
343 |
+
The system is designed to sequentially leverage three LLM functions:
|
344 |
|
345 |
+
### Step 1: LLM1
|
346 |
+
- Determines if the user's query mentions any target company.
|
347 |
+
- If no target company is found, LLM1 responds with a message wrapped in `<user_message></user_message>` XML tags to inform the user that the query is irrelevant to this task.
|
348 |
+
- If the query contains a target company, LLM1 moves forward with a formatted acknowledgment of the identified target company.
|
349 |
|
350 |
+
### Step 2: LLM2
|
351 |
+
- Examines four separate paragraphs independently.
|
352 |
+
- For each paragraph, extracts:
|
353 |
+
- Buyer's representative law firm
|
354 |
+
- Seller's representative law firm
|
355 |
+
- Any third-party law firm present
|
356 |
+
- Whether the target company is mentioned in the paragraph
|
357 |
+
- Each paragraph's results are formatted and concatenated for the next step.
|
358 |
|
359 |
+
### Step 3: LLM3
|
360 |
+
- Compiles the information from all analyzed paragraphs and outputs a structured JSON object:
|
361 |
|
362 |
```json
|
363 |
{
|
|
|
368 |
}
|
369 |
```
|
370 |
|
371 |
+
| Field | Default Value if Missing | Type |
|
372 |
+
| ---------------------- | ------------------------ | --------- |
|
373 |
+
| `buyer_firm` | `"null"` | `string` |
|
374 |
+
| `seller_firm` | `"null"` | `string` |
|
375 |
+
| `third_party` | `"null"` | `string` |
|
376 |
+
| `contains_target_firm` | `false` | `boolean` |
|
377 |
+
|
378 |
The goal is to identify the representative law firms of involved parties and determine if the target company is mentioned, ensuring the results are structured and accurate.
|
379 |
|
380 |
---
|