Spaces:
Running
Running
File size: 1,181 Bytes
a2780b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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)}")
|