File size: 1,871 Bytes
a0fac64
73378b6
4ec3e55
 
 
 
 
fc974b7
ffc2d4c
4ec3e55
 
 
 
 
 
ffc2d4c
1d3e842
 
 
 
 
ffc2d4c
4ec3e55
ffc2d4c
4ec3e55
 
 
 
 
 
 
 
 
ffc2d4c
4ec3e55
1000f0b
 
 
 
 
194d1cf
 
 
 
 
 
1000f0b
 
 
 
 
 
194d1cf
 
4ec3e55
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
49
50
51
52
53
54
55
56
from openai import AzureOpenAI
import os    
class ContractGenerator:
    """
    A class for generating contract forms based on user instructions using the OpenAI GPT-3.5 model.
    """

    def __init__(self):
        
        """
        Initialize the ContractGenerator.

        Args:
            api_key (str): Your OpenAI API key.
        """
        
        # 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 generate_contract(self, instructions: str) -> None:
        
        """
        Generate a contract form based on user instructions.

        Args:
            instructions (str): User-provided instructions for the contract form.

        Raises:
            openai.error.OpenAIError: If there is an error with the OpenAI API request.
        """
        
        # Define a prompt
        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 Contract Generator."},
                        {"role": "user", "content": f"""Your task is to generate a contract form based on user instructions. ***Instructions:{instructions}***"""}
                      ]
                    
        # Call OpenAI GPT-3.5-turbo
        chat_completion = client.chat.completions.create(
            model = "ChatGPT",
            messages = conversation,
            max_tokens=1000,
            temperature=0
        )
        response = chat_completion.choices[0].message.content
        return response