Spaces:
Runtime error
Runtime error
| import openai | |
| 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 | |
| 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 = openai.ChatCompletion.create( | |
| engine="ChatGPT", | |
| messages = conversation, | |
| temperature=0.7, | |
| max_tokens=800, | |
| top_p=0.95, | |
| frequency_penalty=0, | |
| presence_penalty=0, | |
| stop=None | |
| ) | |
| response = chat_completion.choices[0].message.content | |
| return response | |