Spaces:
Running
Running
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)}") | |