Spaces:
Running
Running
File size: 1,925 Bytes
c30daf2 a2780b1 0124e48 a2780b1 0124e48 a9a451b a2780b1 aba6195 a2780b1 e0e4187 f638900 e0e4187 184f51f e0e4187 f638900 a2780b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
from openai import AzureOpenAI
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(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:
client = AzureOpenAI(api_key=os.getenv("AZURE_OPENAI_KEY"),
api_version="2023-07-01-preview",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
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 = client.chat.completions.create(
model = "GPT-3",
messages = conversation,
max_tokens=1000,
temperature=0
)
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
|