Contract_Management / Clauses_Extractor.py
naveenvenkatesh's picture
Update Clauses_Extractor.py
a9a451b verified
raw
history blame
1.95 kB
import openai
import os
# Define the Clauses class
class Clauses:
def __init__(self):
# 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 get_extracted_clauses(self,extracted_summary):
"""
Gets extracted clauses using GPT-3 based on the provided PDF.
Args:
max_tokens (int, optional): Maximum number of tokens for GPT-3 response.
Returns:
str: Extracted clauses from GPT-3 response.
"""
try:
conversation = [
{"role": "system", "content": "You are a helpful Cluases and SubCluases Extracter From Given Content."},
{"role": "user", "content": f"""Extract clauses and sub-clauses from the provided contract PDF
{extracted_summary}"""}
]
# 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
except Exception as e:
# If an error occurs during GPT-3 processing, log the error and raise an exception
print(f"Error occurred while processing PDF with GPT-3. Error message: {str(e)}")
raise