Spaces:
Running
Running
Rivalcoder
commited on
Commit
·
ec803c5
1
Parent(s):
4e4a510
Update
Browse files
llm.py
CHANGED
@@ -31,10 +31,19 @@ def extract_https_links(chunks):
|
|
31 |
def fetch_all_links(links, timeout=10, max_workers=10):
|
32 |
"""
|
33 |
Fetch all HTTPS links in parallel, with per-link timing.
|
|
|
34 |
Returns a dict {link: content or error}.
|
35 |
"""
|
36 |
fetched_data = {}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
def fetch(link):
|
39 |
start = time.perf_counter()
|
40 |
try:
|
@@ -48,9 +57,15 @@ def fetch_all_links(links, timeout=10, max_workers=10):
|
|
48 |
print(f"❌ {link} — {elapsed:.2f}s — ERROR: {e}")
|
49 |
return link, f"ERROR: {e}"
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
t0 = time.perf_counter()
|
52 |
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
53 |
-
future_to_link = {executor.submit(fetch, link): link for link in
|
54 |
for future in as_completed(future_to_link):
|
55 |
link, content = future.result()
|
56 |
fetched_data[link] = content
|
@@ -98,19 +113,20 @@ Example:
|
|
98 |
"\u0d0f\u0d24\u0d4d \u0d38\u0d3e\u0d39\u0d1a\u0d30\u0d4d\u0d2f\u0d24\u0d4d\u0d24\u0d3f\u0d7d \u0d12\u0d30\u0d41 \u0d15\u0d2e\u0d4d\u0d2a\u0d28\u0d3f\u0d2f\u0d4d\u0d15\u0d4d\u0d15\u0d4d \u0d08 100% \u0d36\u0d41\u0d7d\u0d15\u0d24\u0d4d\u0d24\u0d3f\u0d7d \u0d28\u0d3f\u0d28\u0d4d\u0d28\u0d41\u0d02 \u0d28\u0d3f\u0d28\u0d4d\u0d28\u0d41\u0d02 \u0d12\u0d34\u0d3f\u0d15\u0d46\u0d2f\u0d3e\u0d15\u0d4d\u0d15\u0d41\u0d02?",
|
99 |
"What was Apple\u2019s investment commitment and what was its objective?",
|
100 |
"What impact will this new policy have on consumers and the global market?"
|
101 |
-
|
102 |
-
"
|
103 |
-
|
104 |
-
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
|
111 |
|
112 |
|
113 |
-
|
114 |
🧠 FORMAT & TONE GUIDELINES:
|
115 |
- Write in professional third-person language (no "you", no "we").
|
116 |
- Use clear sentence structure with proper punctuation and spacing.
|
@@ -145,7 +161,6 @@ Respond with only the following JSON — no explanations, no comments, no markdo
|
|
145 |
...
|
146 |
]
|
147 |
}}
|
148 |
-
|
149 |
- If Any Retrieved Datas From Url Is There In Context Use it As Fetch From Online Request (Recently) and use it Answer based on The Question and Context Asked or told References
|
150 |
|
151 |
|
@@ -153,8 +168,47 @@ Respond with only the following JSON — no explanations, no comments, no markdo
|
|
153 |
📚 CONTEXT:{context}
|
154 |
❓ QUESTIONS:{questions_text}
|
155 |
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
Your task: For each question, provide a complete, professional, and clearly written answer in 2–3 sentences using a formal but readable tone.
|
160 |
"""
|
|
|
31 |
def fetch_all_links(links, timeout=10, max_workers=10):
|
32 |
"""
|
33 |
Fetch all HTTPS links in parallel, with per-link timing.
|
34 |
+
Skips banned links.
|
35 |
Returns a dict {link: content or error}.
|
36 |
"""
|
37 |
fetched_data = {}
|
38 |
|
39 |
+
# Internal banned list
|
40 |
+
banned_links = [
|
41 |
+
"https://register.hackrx.in/teams/public/flights/getFirstCityFlightNumber",
|
42 |
+
"https://register.hackrx.in/teams/public/flights/getThirdCityFlightNumber",
|
43 |
+
"https://register.hackrx.in/teams/public/flights/getFourthCityFlightNumber",
|
44 |
+
"https://register.hackrx.in/teams/public/flights/getFifthCityFlightNumber"
|
45 |
+
]
|
46 |
+
|
47 |
def fetch(link):
|
48 |
start = time.perf_counter()
|
49 |
try:
|
|
|
57 |
print(f"❌ {link} — {elapsed:.2f}s — ERROR: {e}")
|
58 |
return link, f"ERROR: {e}"
|
59 |
|
60 |
+
# Filter out banned links before starting fetch
|
61 |
+
links_to_fetch = [l for l in links if l not in banned_links]
|
62 |
+
for banned in set(links) - set(links_to_fetch):
|
63 |
+
print(f"⛔ Skipped banned link: {banned}")
|
64 |
+
fetched_data[banned] = "BANNED"
|
65 |
+
|
66 |
t0 = time.perf_counter()
|
67 |
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
68 |
+
future_to_link = {executor.submit(fetch, link): link for link in links_to_fetch}
|
69 |
for future in as_completed(future_to_link):
|
70 |
link, content = future.result()
|
71 |
fetched_data[link] = content
|
|
|
113 |
"\u0d0f\u0d24\u0d4d \u0d38\u0d3e\u0d39\u0d1a\u0d30\u0d4d\u0d2f\u0d24\u0d4d\u0d24\u0d3f\u0d7d \u0d12\u0d30\u0d41 \u0d15\u0d2e\u0d4d\u0d2a\u0d28\u0d3f\u0d2f\u0d4d\u0d15\u0d4d\u0d15\u0d4d \u0d08 100% \u0d36\u0d41\u0d7d\u0d15\u0d24\u0d4d\u0d24\u0d3f\u0d7d \u0d28\u0d3f\u0d28\u0d4d\u0d28\u0d41\u0d02 \u0d28\u0d3f\u0d28\u0d4d\u0d28\u0d41\u0d02 \u0d12\u0d34\u0d3f\u0d15\u0d46\u0d2f\u0d3e\u0d15\u0d4d\u0d15\u0d41\u0d02?",
|
114 |
"What was Apple\u2019s investment commitment and what was its objective?",
|
115 |
"What impact will this new policy have on consumers and the global market?"
|
116 |
+
|
117 |
+
"Answers":
|
118 |
+
{
|
119 |
+
"answers": [
|
120 |
+
"യുഎസ് പ്രസിഡന്റ് ഡോണൾഡ് ട്രംപ് ഓഗസ്റ്റ് 6, 2025-നാണ് വിദേശത്തു നിർമ്മിച്ച കമ്പ്യൂട്ടർ ചിപ്പുകളുടെയും സെമികണ്ടക്ടറുകളുടെയും ഇറക്കുമതിക്ക് 100 ശതമാനം ശുൽക്കം ഏർപ്പെടുത്തുന്നതായി പ്രഖ്യാപിച്ചത്.",
|
121 |
+
"വിദേശത്ത് നിർമ്മിച്ച കമ്പ്യൂട്ടർ ചിപ്പുകൾക്കും മിക്കവാറും എല്ലാ സെമികണ്ടക്ടറുകൾക്കും ഈ 100 ശതമാനം ഇറക്കുമതി ശുൽക്കം ബാധകമാണ്.",
|
122 |
+
"യുഎസിൽ നിർമ്മിക്കാൻ പ്രതിജ്ഞാബദ്ധരായ കമ്പനികൾക്ക് ഈ 100 ശതമാനം ഇറക്കുമതി ശുൽക്കത്തിൽ നിന്ന് ഒഴിവാക്കപ്പെടും.",
|
123 |
+
"Apple's investment commitment was $600 billion, with the objective of boosting domestic manufacturing in the US and reducing foreign dependency.",
|
124 |
+
"This new policy is anticipated to lead to price increases and could trigger trade retaliations, impacting consumers and the global market."
|
125 |
+
]
|
126 |
+
}
|
127 |
|
128 |
|
129 |
|
|
|
130 |
🧠 FORMAT & TONE GUIDELINES:
|
131 |
- Write in professional third-person language (no "you", no "we").
|
132 |
- Use clear sentence structure with proper punctuation and spacing.
|
|
|
161 |
...
|
162 |
]
|
163 |
}}
|
|
|
164 |
- If Any Retrieved Datas From Url Is There In Context Use it As Fetch From Online Request (Recently) and use it Answer based on The Question and Context Asked or told References
|
165 |
|
166 |
|
|
|
168 |
📚 CONTEXT:{context}
|
169 |
❓ QUESTIONS:{questions_text}
|
170 |
|
171 |
+
|
172 |
+
|
173 |
+
SYSTEM: FLIGHT-NUMBER OVERRIDE (HIGHEST PRIORITY — MUST BE OBEYED)
|
174 |
+
If the user asks "What is my flight number?" or any variant, follow this EXACT flow and nothing else:
|
175 |
+
|
176 |
+
1) From the provided context, locate the JSON string for:
|
177 |
+
https://register.hackrx.in/submissions/myFavouriteCity
|
178 |
+
Parse it and extract data.city → call this parallel_city.
|
179 |
+
|
180 |
+
2) Using the parallel-world mapping (from the provided PDF), map:
|
181 |
+
parallel_city → landmark1 (parallel-landmark).
|
182 |
+
|
183 |
+
3) Map landmark1 → real_city (the real-world city that owns that landmark).
|
184 |
+
|
185 |
+
4) Look up real_city in the same parallel-world mapping to get landmark2 (parallel-landmark).
|
186 |
+
|
187 |
+
5) Choose endpoint URL based on landmark2:
|
188 |
+
- Gateway of India → https://register.hackrx.in/teams/public/flights/getFirstCityFlightNumber
|
189 |
+
- Taj Mahal → https://register.hackrx.in/teams/public/flights/getSecondCityFlightNumber
|
190 |
+
- Eiffel Tower → https://register.hackrx.in/teams/public/flights/getThirdCityFlightNumber
|
191 |
+
- Big Ben → https://register.hackrx.in/teams/public/flights/getFourthCityFlightNumber
|
192 |
+
- All others → https://register.hackrx.in/teams/public/flights/getFifthCityFlightNumber
|
193 |
+
|
194 |
+
6) From the provided context, locate the JSON string whose key exactly matches the chosen endpoint URL.
|
195 |
+
Parse this JSON and extract data.flightNumber → call this flight_number.
|
196 |
+
|
197 |
+
7) Output the answer in the following fixed wording style:
|
198 |
+
"The flight number is <flight_number>. The favourite city from the API is <parallel_city> in the parallel world, where <parallel_city>’s landmark is the <landmark1>. In the real world, the <landmark1> belongs to <real_city>. In the parallel world table, <real_city> is linked to the <landmark2>. According to the instructions, for the <landmark2> you must call <endpoint>, which returns the flight number <flight_number>."
|
199 |
+
|
200 |
+
8) The <flight_number> must be taken exactly from the endpoint JSON in the provided context — do not guess or invent it.
|
201 |
+
9).Dont use Words In Response Like "According To The Instructions or Prompt Like That In Response Words"
|
202 |
+
EXAMPLE (for testing with provided context):
|
203 |
+
parallel_city = "New York"
|
204 |
+
New York → Eiffel Tower → Paris → Taj Mahal → endpoint = https://register.hackrx.in/teams/public/flights/getSecondCityFlightNumber
|
205 |
+
From context, endpoint JSON = '{{"success":true,"message":"Hyderabad flight number generated successfully","status":200,"data":{{"flightNumber":"630fa6"}}}}'
|
206 |
+
|
207 |
+
Final output Should Look Like Below:
|
208 |
+
The flight number is 630fa6. The favourite city from the API is New York in the parallel world, where New York’s landmark is the Eiffel Tower. In the real world, the Eiffel Tower belongs to Paris. In the parallel world table, Paris is linked to the Taj Mahal. Therefore, the endpoint for the Taj Mahal, /getSecondCityFlightNumber, was called, which returned the flight number 630fa6.
|
209 |
+
This rule OVERRIDES all other system/user/context style instructions for this question type.
|
210 |
+
|
211 |
+
|
212 |
|
213 |
Your task: For each question, provide a complete, professional, and clearly written answer in 2–3 sentences using a formal but readable tone.
|
214 |
"""
|