Spaces:
Sleeping
Sleeping
Update ContractGenerator.py
Browse files- ContractGenerator.py +20 -12
ContractGenerator.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from openai
|
| 2 |
|
| 3 |
class ContractGenerator:
|
| 4 |
"""
|
|
@@ -6,15 +6,21 @@ class ContractGenerator:
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
def __init__(self):
|
|
|
|
| 9 |
"""
|
| 10 |
Initialize the ContractGenerator.
|
| 11 |
|
| 12 |
Args:
|
| 13 |
api_key (str): Your OpenAI API key.
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def generate_contract(self, instructions: str) -> None:
|
|
|
|
| 18 |
"""
|
| 19 |
Generate a contract form based on user instructions.
|
| 20 |
|
|
@@ -24,22 +30,24 @@ class ContractGenerator:
|
|
| 24 |
Raises:
|
| 25 |
openai.error.OpenAIError: If there is an error with the OpenAI API request.
|
| 26 |
"""
|
|
|
|
| 27 |
# Define a prompt
|
| 28 |
-
client = OpenAI()
|
| 29 |
-
os.environ["OPENAI_API_KEY"]="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"
|
| 30 |
-
|
| 31 |
conversation = [
|
| 32 |
{"role": "system", "content": "You are a helpful Contract Generator."},
|
| 33 |
{"role": "user", "content": f"""Your task is to generate a contract form based on user instructions. ***Instructions:{instructions}***"""}
|
| 34 |
]
|
| 35 |
|
| 36 |
# Call OpenAI GPT-3.5-turbo
|
| 37 |
-
chat_completion =
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
response = chat_completion.choices[0].message.content
|
| 44 |
return response
|
| 45 |
|
|
|
|
| 1 |
+
from openai
|
| 2 |
|
| 3 |
class ContractGenerator:
|
| 4 |
"""
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
def __init__(self):
|
| 9 |
+
|
| 10 |
"""
|
| 11 |
Initialize the ContractGenerator.
|
| 12 |
|
| 13 |
Args:
|
| 14 |
api_key (str): Your OpenAI API key.
|
| 15 |
"""
|
| 16 |
+
|
| 17 |
+
openai.api_type = os.getenv['api_type']
|
| 18 |
+
openai.api_base = os.getenv['api_base']
|
| 19 |
+
openai.api_version = os.getenv['api_version']
|
| 20 |
+
openai.api_key = os.getenv['api_key']
|
| 21 |
+
|
| 22 |
def generate_contract(self, instructions: str) -> None:
|
| 23 |
+
|
| 24 |
"""
|
| 25 |
Generate a contract form based on user instructions.
|
| 26 |
|
|
|
|
| 30 |
Raises:
|
| 31 |
openai.error.OpenAIError: If there is an error with the OpenAI API request.
|
| 32 |
"""
|
| 33 |
+
|
| 34 |
# Define a prompt
|
|
|
|
|
|
|
|
|
|
| 35 |
conversation = [
|
| 36 |
{"role": "system", "content": "You are a helpful Contract Generator."},
|
| 37 |
{"role": "user", "content": f"""Your task is to generate a contract form based on user instructions. ***Instructions:{instructions}***"""}
|
| 38 |
]
|
| 39 |
|
| 40 |
# Call OpenAI GPT-3.5-turbo
|
| 41 |
+
chat_completion = openai.ChatCompletion.create(
|
| 42 |
+
engine="ChatGPT",
|
| 43 |
+
messages = conversation,
|
| 44 |
+
temperature=0.7,
|
| 45 |
+
max_tokens=800,
|
| 46 |
+
top_p=0.95,
|
| 47 |
+
frequency_penalty=0,
|
| 48 |
+
presence_penalty=0,
|
| 49 |
+
stop=None
|
| 50 |
+
)
|
| 51 |
response = chat_completion.choices[0].message.content
|
| 52 |
return response
|
| 53 |
|