naveenvenkatesh commited on
Commit
f67b4b0
·
verified ·
1 Parent(s): 194d1cf

Update Tags_Extractor.py

Browse files
Files changed (1) hide show
  1. 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
- # Use OpenAI's Completion API to analyze the text and extract tags
27
- response = openai.Completion.create(
28
- engine="text-davinci-003",
29
- temperature=0,
30
- prompt=f"analyze the given contract to extract tags for following contract in triple backticks. tags should be bullet points.contract :```{extracted_summary}```.",
31
- max_tokens=1000
 
 
 
 
 
32
  )
33
-
34
- # Extract and return the chatbot's reply
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)}")