Spaces:
Sleeping
Sleeping
Download ContractGenerator.py from productions/Data_Conversion: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/productions/Data_Conversion/resolve/4ec3e5510d5605b0020dc05b51b35b3cd7ce3900/ContractGenerator.py
- Command line
-
hf download hf://spaces/productions/Data_Conversion@4ec3e5510d5605b0020dc05b51b35b3cd7ce3900/ContractGenerator.py
-
curl -L -o ContractGenerator.py https://huggingface.co/spaces/productions/Data_Conversion/resolve/4ec3e5510d5605b0020dc05b51b35b3cd7ce3900/ContractGenerator.py
1.33 kB
| import openai | |
| class ContractGenerator: | |
| """ | |
| A class for generating contract forms based on user instructions using the OpenAI GPT-3.5 model. | |
| """ | |
| def __init__(self, api_key: str): | |
| """ | |
| Initialize the ContractGenerator. | |
| Args: | |
| api_key (str): Your OpenAI API key. | |
| """ | |
| openai.api_key = api_key | |
| 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 | |
| prompt = f"Your task is to generate a contract form based on user instructions. ***Instructions:{instructions}***" | |
| try: | |
| # Generate text using the GPT-3.5 model | |
| response = openai.Completion.create( | |
| engine="text-davinci-003", | |
| prompt=prompt, | |
| max_tokens=500 # You can adjust the length of the generated text | |
| ) | |
| # Print the generated text | |
| return response.choices[0].text | |
| except openai.error.OpenAIError as e: | |
| print(f"Error generating the contract: {str(e)}") | |