Spaces:
Running
Running
File size: 1,415 Bytes
cde5cbe a2780b1 cde5cbe a2780b1 cde5cbe 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 39 40 41 42 |
from openai 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:
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 = self.client.chat.completions.create(
model = "gpt-3.5-turbo",
messages = conversation,
max_tokens=500,
temperature=0
)
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)}")
|