Spaces:
Runtime error
Runtime error
naveenvenkatesh
commited on
Update key_value_extractor.py
Browse files- key_value_extractor.py +15 -11
key_value_extractor.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import
|
2 |
import os
|
3 |
|
4 |
|
@@ -21,17 +21,21 @@ class KeyValue:
|
|
21 |
try:
|
22 |
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
)
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
return result
|
35 |
except Exception as e:
|
36 |
# If an error occurs during the key-value extraction process, log the error
|
37 |
print(f"Error occurred while extracting key-value pairs: {str(e)}")
|
|
|
1 |
+
from openai import OpenAI
|
2 |
import os
|
3 |
|
4 |
|
|
|
21 |
try:
|
22 |
|
23 |
|
24 |
+
conversation = [
|
25 |
+
{"role": "system", "content": "You are a helpful Keywords Extracter."},
|
26 |
+
{"role": "user", "content": f"""analyze the given contract and Extract Keywords for following contract in triple backticks. tags should be bullet points.contract :```{extracted_summary}```."""}
|
27 |
+
]
|
28 |
+
|
29 |
+
# Call OpenAI GPT-3.5-turbo
|
30 |
+
chat_completion = self.client.chat.completions.create(
|
31 |
+
model = "gpt-3.5-turbo",
|
32 |
+
messages = conversation,
|
33 |
+
max_tokens=500,
|
34 |
+
temperature=0
|
35 |
)
|
36 |
+
response = chat_completion.choices[0].message.content
|
37 |
+
return response
|
38 |
+
|
|
|
39 |
except Exception as e:
|
40 |
# If an error occurs during the key-value extraction process, log the error
|
41 |
print(f"Error occurred while extracting key-value pairs: {str(e)}")
|