Update LLM_automation_GPT.py
Browse files- LLM_automation_GPT.py +4 -6
LLM_automation_GPT.py
CHANGED
@@ -24,7 +24,7 @@ def create_data(description):
|
|
24 |
)
|
25 |
|
26 |
#### Create OpenAI llm:
|
27 |
-
llm=ChatOpenAI(model="gpt-4o")
|
28 |
|
29 |
### Create an output parser:
|
30 |
output_parser=StrOutputParser()
|
@@ -36,9 +36,8 @@ def create_data(description):
|
|
36 |
df = description
|
37 |
df = df.fillna(0)
|
38 |
dj=[]
|
39 |
-
|
40 |
for i in range(len(df)):
|
41 |
-
dj.append(chain.invoke({"question" : df['
|
42 |
|
43 |
df2=df.copy()
|
44 |
df2['Report Type']=dj
|
@@ -56,7 +55,7 @@ def create_data(description):
|
|
56 |
### Now finding column values using llm:
|
57 |
### A function to invoke the llm. For some reason phi3 doesn't give accurate result sometimes if used directly in dj.append()
|
58 |
def res(i):
|
59 |
-
response=chain.invoke({"question" : df2['Description'][i]+f"""Provide only the answers of the following question seperated by a comma only:
|
60 |
If the news was published on {df2['Publish Date'][i]}, what is the date of accident occurrence? The date must be in Day-Month-Year format. Be careful because publish date and accident occurrence date may or may not be the same. Try to deduce correct accident date and do not include Saturday Sunday etc in your date. Only numerics are needed,
|
61 |
Time of Accident occured, How many people were killed in the accident in numeric number?,
|
62 |
How many people were injured in the accident in numeric number?,
|
@@ -121,5 +120,4 @@ def create_data(description):
|
|
121 |
df2["Pedestrian_Involved"]=Pedestrian_Involved
|
122 |
df2["Vehicles Involved"]=vehicles
|
123 |
df3=df2.drop(columns=['Description','Date + Desc','Report Type'])
|
124 |
-
return df3
|
125 |
-
|
|
|
24 |
)
|
25 |
|
26 |
#### Create OpenAI llm:
|
27 |
+
llm=ChatOpenAI(model="gpt-4o-mini")
|
28 |
|
29 |
### Create an output parser:
|
30 |
output_parser=StrOutputParser()
|
|
|
36 |
df = description
|
37 |
df = df.fillna(0)
|
38 |
dj=[]
|
|
|
39 |
for i in range(len(df)):
|
40 |
+
dj.append(chain.invoke({"question" : df['Description'][i]+" Is the news about road accident? If no, then reply 'General'. Else if the news is about road accident then check if the news is referring to a specific accident incident or accident in general? Answer only in a word: Either specific or general."}))
|
41 |
|
42 |
df2=df.copy()
|
43 |
df2['Report Type']=dj
|
|
|
55 |
### Now finding column values using llm:
|
56 |
### A function to invoke the llm. For some reason phi3 doesn't give accurate result sometimes if used directly in dj.append()
|
57 |
def res(i):
|
58 |
+
response=chain.invoke({"question" : df2['Description'][i]+f"""Provide only the answers of the following question seperated by a comma only and your answers MUST BE IN ENGLISH:
|
59 |
If the news was published on {df2['Publish Date'][i]}, what is the date of accident occurrence? The date must be in Day-Month-Year format. Be careful because publish date and accident occurrence date may or may not be the same. Try to deduce correct accident date and do not include Saturday Sunday etc in your date. Only numerics are needed,
|
60 |
Time of Accident occured, How many people were killed in the accident in numeric number?,
|
61 |
How many people were injured in the accident in numeric number?,
|
|
|
120 |
df2["Pedestrian_Involved"]=Pedestrian_Involved
|
121 |
df2["Vehicles Involved"]=vehicles
|
122 |
df3=df2.drop(columns=['Description','Date + Desc','Report Type'])
|
123 |
+
return df3
|
|