naveenvenkatesh commited on
Commit
194d1cf
1 Parent(s): f638900

Update ContractGenerator.py

Browse files
Files changed (1) hide show
  1. ContractGenerator.py +18 -16
ContractGenerator.py CHANGED
@@ -12,7 +12,7 @@ class ContractGenerator:
12
  Args:
13
  api_key (str): Your OpenAI API key.
14
  """
15
- pass
16
 
17
  def generate_contract(self, instructions: str) -> None:
18
  """
@@ -25,19 +25,21 @@ class ContractGenerator:
25
  openai.error.OpenAIError: If there is an error with the OpenAI API request.
26
  """
27
  # Define a prompt
28
- prompt = f"Your task is to generate a contract form based on user instructions. ***Instructions:{instructions}***"
29
-
30
- try:
31
- # Generate text using the GPT-3.5 model
32
- response = openai.Completion.create(
33
- engine="text-davinci-003",
34
- prompt=prompt,
35
- max_tokens=500 # You can adjust the length of the generated text
36
- )
37
-
38
- # Print the generated text
39
- return response.choices[0].text
40
-
41
- except openai.error.OpenAIError as e:
42
- print(f"Error generating the contract: {str(e)}")
 
 
43
 
 
12
  Args:
13
  api_key (str): Your OpenAI API key.
14
  """
15
+ self.client = OpenAI()
16
 
17
  def generate_contract(self, instructions: str) -> None:
18
  """
 
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 = client.chat.completions.create(
38
+ model = "gpt-3.5-turbo",
39
+ messages = conversation,
40
+ max_tokens=500,
41
+ temperature=0
42
+ )
43
+ response = chat_completion.choices[0].message.content
44
+ return response
45