File size: 1,830 Bytes
0184332
a2780b1
 
 
 
 
 
 
 
 
df50b14
324987f
 
 
 
 
a2780b1
 
 
 
 
 
 
 
c6f0020
 
 
 
 
cde5cbe
 
 
 
 
 
c6f0020
d0d34e0
c6f0020
 
 
 
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
43
44
45
46
47
48
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)}")