Baskar2005 commited on
Commit
549a722
·
verified ·
1 Parent(s): 7f2d761

Update headings_extractor.py

Browse files
Files changed (1) hide show
  1. headings_extractor.py +15 -8
headings_extractor.py CHANGED
@@ -16,7 +16,7 @@ class HeadingsExtractor:
16
  Returns:
17
  str: Extracted headings.
18
  """
19
- pass
20
 
21
  def file_output_fnn(self,file_path):
22
  file_path = file_path.name
@@ -35,15 +35,22 @@ class HeadingsExtractor:
35
  """
36
  try:
37
  #get response from openai api
38
- response = openai.Completion.create(
39
- engine="text-davinci-003",
40
- prompt=f"""Extract Headings from given paragraph do not generate jsu extract the headings from paragraph.
41
- ```paragraph :{contract_page}```""",
42
- max_tokens=100,
 
 
 
 
 
 
 
43
  temperature=0
44
  )
45
- headings = response.choices[0].text.strip()
46
- return headings
47
 
48
  except Exception as e:
49
  # If an error occurs during the key-value extraction process, log the error
 
16
  Returns:
17
  str: Extracted headings.
18
  """
19
+ self.client=OpenAI()
20
 
21
  def file_output_fnn(self,file_path):
22
  file_path = file_path.name
 
35
  """
36
  try:
37
  #get response from openai api
38
+
39
+ conversation = [
40
+ {"role": "system", "content": "You are a helpful assistant."},
41
+ {"role": "user", "content": f"""Extract Headings from given paragraph do not generate jsu extract the headings from paragraph.
42
+ ```paragraph :{contract_page}```"""}
43
+ ]
44
+
45
+ # Call OpenAI GPT-3.5-turbo
46
+ chat_completion =self.client.chat.completions.create(
47
+ model = "gpt-3.5-turbo",
48
+ messages = conversation,
49
+ max_tokens=1000,
50
  temperature=0
51
  )
52
+ response = chat_completion.choices[0].message.content
53
+ return response
54
 
55
  except Exception as e:
56
  # If an error occurs during the key-value extraction process, log the error