Contract_Management / key_value_extractor.py
naveenvenkatesh's picture
Update key_value_extractor.py
df50b14 verified
raw
history blame
1.81 kB
import openai
import os
# Define the KeyValue class
class KeyValue:
def __init__(self):
"""
Initialize the Extractor class.
"""
openai.api_type = os.getenv['api_type']
openai.api_base = os.getenv['api_base']
openai.api_version = os.getenv['api_version']
openai.api_key = os.getenv['api_key']
def extract_key_value_pair(extracted_summary):
"""
Extract key-value pairs from the refined summary.
Prints the extracted key-value pairs.
"""
try:
conversation = [
{"role": "system", "content": "You are a helpful Keywords Extracter."},
{"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}```."""}
]
# Call OpenAI GPT-3.5-turbo
chat_completion = openai.ChatCompletion.create(
engine="ChatGPT",
messages = conversation,
temperature=0.7,
max_tokens=800,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
response = chat_completion.choices[0].message.content
return response
except Exception as e:
# If an error occurs during the key-value extraction process, log the error
print(f"Error occurred while extracting key-value pairs: {str(e)}")