naveenvenkatesh commited on
Commit
f8d40ff
1 Parent(s): f67b4b0

Update aggressive_content_finder.py

Browse files
Files changed (1) hide show
  1. aggressive_content_finder.py +15 -11
aggressive_content_finder.py CHANGED
@@ -14,8 +14,7 @@ class AggressiveContentFinder:
14
  """
15
  Initialize the AggressiveContentFinder with your OpenAI API key.
16
  """
17
- # openai.api_key = openai_api_key
18
- pass
19
 
20
  def _extract_aggressive_content(self, contract_text: str) -> str:
21
  """
@@ -28,17 +27,22 @@ class AggressiveContentFinder:
28
  str: Identified aggressive terms.
29
  """
30
  try:
31
- response = openai.Completion.create(
32
- engine="text-davinci-003",
33
- prompt=f"""This is a contract document content. Your task is to identify aggressive terms like warning terms, penalties in the given contract:
34
- (Example: "The bank may take possession of the property.")
35
- ```contract: {contract_text}```
36
- """,
37
- max_tokens=70,
 
 
 
 
38
  temperature=0
39
  )
40
- aggressive_terms = response.choices[0].text.strip()
41
- return aggressive_terms
 
42
  except Exception as e:
43
  print(f"An error occurred during text analysis: {str(e)}")
44
 
 
14
  """
15
  Initialize the AggressiveContentFinder with your OpenAI API key.
16
  """
17
+ self.client = OpenAI()
 
18
 
19
  def _extract_aggressive_content(self, contract_text: str) -> str:
20
  """
 
27
  str: Identified aggressive terms.
28
  """
29
  try:
30
+ conversation = [
31
+ {"role": "system", "content": "You are a helpful Aggressive Terms Finder in Given Contract."},
32
+ {"role": "user", "content": f"""This is a contract document content. Your task is to identify aggressive terms like warning terms, penalties in the given contract:
33
+ ```contract: {contract_text}```"""}
34
+ ]
35
+
36
+ # Call OpenAI GPT-3.5-turbo
37
+ chat_completion = self.client.chat.completions.create(
38
+ model = "gpt-3.5-turbo",
39
+ messages = conversation,
40
+ max_tokens=500,
41
  temperature=0
42
  )
43
+ response = chat_completion.choices[0].message.content
44
+ return response
45
+
46
  except Exception as e:
47
  print(f"An error occurred during text analysis: {str(e)}")
48