naveenvenkatesh commited on
Commit
cde5cbe
·
verified ·
1 Parent(s): a52afff

Update key_value_extractor.py

Browse files
Files changed (1) hide show
  1. key_value_extractor.py +15 -11
key_value_extractor.py CHANGED
@@ -1,4 +1,4 @@
1
- import openai
2
  import os
3
 
4
 
@@ -21,17 +21,21 @@ class KeyValue:
21
  try:
22
 
23
 
24
- # Use OpenAI's Completion API to analyze the text and extract key-value pairs
25
- response = openai.Completion.create(
26
- engine="text-davinci-003",
27
- temperature=0,
28
- prompt=f"analyze the given contract and get meaningful key value pairs in given content.contract in backticks.```{extracted_summary}```.",
29
- max_tokens=1000
 
 
 
 
 
30
  )
31
-
32
- # Extract and return the chatbot's reply
33
- result = response['choices'][0]['text'].strip()
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)}")