Spaces:
Runtime error
Runtime error
| from openai import AzureOpenAI | |
| 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'] | |
| pass | |
| def extract_key_value_pair(extracted_summary): | |
| """ | |
| Extract key-value pairs from the refined summary. | |
| Prints the extracted key-value pairs. | |
| """ | |
| try: | |
| client = AzureOpenAI(api_key=os.getenv("AZURE_OPENAI_KEY"), | |
| api_version="2023-07-01-preview", | |
| azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT") | |
| ) | |
| 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 = client.chat.completions.create( | |
| model = "GPT-3", | |
| messages = conversation, | |
| max_tokens=1000, | |
| 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)}") | |