File size: 3,192 Bytes
c16c548
3a51e49
dbfae32
c16c548
 
 
bbb957e
c16c548
dbfae32
 
c16c548
 
dd0cd45
c16c548
dbfae32
 
c16c548
 
bbb957e
 
78dfdff
bbb957e
 
 
 
 
dbfae32
3a51e49
 
 
 
 
 
dbfae32
 
 
 
 
 
 
 
 
 
 
3a51e49
 
c16c548
3a51e49
 
 
 
 
 
 
e2bb6ed
3a51e49
 
 
 
dbfae32
 
 
3a51e49
e0da68f
 
 
 
 
dbfae32
c16c548
 
dbfae32
c16c548
855b4b0
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from pdfminer import high_level
from langchain_astradb import AstraDBVectorStore
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAIEmbeddings
from langchain_anthropic import ChatAnthropic
from langchain_google_genai import ChatGoogleGenerativeAI

ASTRA_DB_API_ENDPOINT = os.environ["ASTRA_DB_API_ENDPOINT"]
ASTRA_DB_APPLICATION_TOKEN = os.environ["ASTRA_DB_APPLICATION_TOKEN"]
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
ANTHROPIC_API_KEY = os.environ["ANTHROPIC_API_KEY"]
GOOGLE_API_KEY = os.environ["GOOGLE_API_KEY"]

collection_name = "ilj_test"

embedding = OpenAIEmbeddings(model="text-embedding-ada-002")

models = {
    "claude-3": ChatAnthropic(model='claude-3-sonnet-20240229'),
    "gemini-pro": ChatGoogleGenerativeAI(model="gemini-1.5-pro-latest", temperature=0.0)
}

def model_names():
    return models.keys()

def pipeline(file, model_name, balance_type, apsn_transactions, max_fees_per_day, min_overdrawn_fee, min_transaction_overdraft):
    disclosure_text = high_level.extract_text(file)
    
    # Read the legal cases context from the text file
    with open("all Text OCR.txt", "r") as f:
        legal_cases_context = f.read()

    astra = AstraDBVectorStore(
        api_endpoint=ASTRA_DB_API_ENDPOINT,
        token=ASTRA_DB_APPLICATION_TOKEN,
        collection_name=collection_name,
        embedding=embedding
    )

    related_docs = astra.search(disclosure_text, search_type="similarity")

    prompt = PromptTemplate.from_template(
        """
        law context:
        {context}

        above are several cases and a bank disclosure. Using the cases, please provide changes to the disclosure and keep as much formatting as possible and to ensure there are no legal contradictions between the content of the disclosure and the cases and please provide reasoning for each proposed change. Please also integrate the bank's policies into the disclosure. In the first sentence, please include a reference to the account agreement "for more information on overdrafts" and a placeholder for a URL. Available balance or ledger balance should replace money in the first sentence.
        Here are the answers to the bank's policy questions:
        Do you charge on available balance or ledger balance?: {balance_type}
        Do you charge for APSN transactions?: {apsn_transactions}
        How many overdraft fees per day can be charged?: {max_fees_per_day}
        What is the minimum amount overdrawn to incur a fee?: {min_overdrawn_fee}
        What is the minimum transaction amount to trigger an overdraft?: {min_transaction_overdraft}

        Please output in the following format: 
        {{entire disclosure text}}
        ------
        {{reasons_for_changes}}
        """
    )
    val = prompt.format(
        context=legal_cases_context,
        disclosure=disclosure_text,
        balance_type=balance_type,
        apsn_transactions=apsn_transactions,
        max_fees_per_day=max_fees_per_day,
        min_overdrawn_fee=min_overdrawn_fee,
        min_transaction_overdraft=min_transaction_overdraft,
    )

    chat_response = models[model_name].invoke(input=val)

    return chat_response.content