Contract_Management / key_value_extractor.py
robertselvam's picture
Upload 5 files
a2780b1
raw
history blame
1.18 kB
import openai
import os
# Define the KeyValue class
class KeyValue:
def __init__(self):
"""
Initialize the Extractor class.
"""
# Set OpenAI API key
# os.environ["OPENAI_API_KEY"] = ""
def extract_key_value_pair(extracted_summary):
"""
Extract key-value pairs from the refined summary.
Prints the extracted key-value pairs.
"""
try:
# Use OpenAI's Completion API to analyze the text and extract key-value pairs
response = openai.Completion.create(
engine="text-davinci-003",
temperature=0,
prompt=f"analyze the given contract and get meaningful key value pairs in given content.contract in backticks.```{extracted_summary}```.",
max_tokens=1000
)
# Extract and return the chatbot's reply
result = response['choices'][0]['text'].strip()
return result
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)}")