Spaces:
Running
Running
naveenvenkatesh
commited on
Update Tags_Extractor.py
Browse files- Tags_Extractor.py +15 -16
Tags_Extractor.py
CHANGED
@@ -7,14 +7,10 @@ class Tags:
|
|
7 |
"""
|
8 |
Initialize the Extractor class.
|
9 |
"""
|
|
|
10 |
|
11 |
-
# Set OpenAI API key
|
12 |
|
13 |
-
|
14 |
-
# openai.api_key = ""
|
15 |
-
|
16 |
-
|
17 |
-
def extract_tags(extracted_summary):
|
18 |
"""
|
19 |
Extract tags from the refined summary using OpenAI API.
|
20 |
|
@@ -23,17 +19,20 @@ class Tags:
|
|
23 |
"""
|
24 |
try:
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
)
|
33 |
-
|
34 |
-
|
35 |
-
result = response['choices'][0]['text'].strip()
|
36 |
-
return result
|
37 |
|
38 |
except Exception as e:
|
39 |
print(f"Error occurred while extracting tags: {str(e)}")
|
|
|
7 |
"""
|
8 |
Initialize the Extractor class.
|
9 |
"""
|
10 |
+
self.client = OpenAI()
|
11 |
|
|
|
12 |
|
13 |
+
def extract_tags(self,extracted_summary):
|
|
|
|
|
|
|
|
|
14 |
"""
|
15 |
Extract tags from the refined summary using OpenAI API.
|
16 |
|
|
|
19 |
"""
|
20 |
try:
|
21 |
|
22 |
+
conversation = [
|
23 |
+
{"role": "system", "content": "You are a helpful Tags Extracter."},
|
24 |
+
{"role": "user", "content": f"""analyze the given contract to extract tags for following contract in triple backticks. tags should be bullet points.contract :```{extracted_summary}```."""}
|
25 |
+
]
|
26 |
+
|
27 |
+
# Call OpenAI GPT-3.5-turbo
|
28 |
+
chat_completion = self.client.chat.completions.create(
|
29 |
+
model = "gpt-3.5-turbo",
|
30 |
+
messages = conversation,
|
31 |
+
max_tokens=500,
|
32 |
+
temperature=0
|
33 |
)
|
34 |
+
response = chat_completion.choices[0].message.content
|
35 |
+
return response
|
|
|
|
|
36 |
|
37 |
except Exception as e:
|
38 |
print(f"Error occurred while extracting tags: {str(e)}")
|