-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff0c5d3
commit 2c8523c
Showing
20 changed files
with
3,999 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# budgeting/agent.py | ||
from langchain_core.messages import BaseMessage | ||
from langchain_huggingface import HuggingFaceEndpoint | ||
|
||
class BudgetingAgent: | ||
def __init__(self, model_id="meta-llama/Llama-3.2-3B-Instruct"): | ||
self.model = HuggingFaceEndpoint( | ||
repo_id=model_id, | ||
task="text_generation", | ||
max_new_tokens=512, | ||
temperature=0.3, | ||
streaming=True, | ||
) | ||
|
||
def process_budgeting_query(self, state): | ||
""" | ||
Process the user query related to budgeting. | ||
Args: | ||
state (dict): The current state containing user messages. | ||
""" | ||
messages = state["messages"] | ||
question = messages[0].content | ||
|
||
response = self.model.invoke([{"content": question}]) | ||
return {"messages": [response]} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# budgeting/__init__.py | ||
from .agent import BudgetingAgent | ||
from .prompt import budgeting_prompt | ||
from .workflow import budgeting_workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Budgeting/budgeting_workflow.py | ||
from prefect import task, flow | ||
|
||
@task | ||
def fetch_budget_data(): | ||
# Placeholder for fetching budget data | ||
return {"budget": 5000, "expenses": 2000, "savings": 3000} | ||
|
||
@task | ||
def calculate_savings(data): | ||
savings = data["budget"] - data["expenses"] | ||
return savings | ||
|
||
@flow | ||
def budgeting_workflow(state): | ||
# This flow orchestrates the budgeting process | ||
budget_data = fetch_budget_data() | ||
savings = calculate_savings(budget_data) | ||
return {"messages": [{"content": f"Savings: {savings}"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# budgeting/prompt.py | ||
from langchain.prompts import PromptTemplate | ||
|
||
budgeting_prompt = PromptTemplate( | ||
template="""You are a financial advisor helping the user with budgeting. \n | ||
Here is the user's query: {question}\n | ||
Provide actionable advice on how they can manage their budget effectively.""", | ||
input_variables=["question"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# credit/agent.py | ||
from langchain_huggingface import HuggingFaceEndpoint | ||
|
||
class CreditAgent: | ||
def __init__(self, model_id="meta-llama/Llama-3.2-3B-Instruct"): | ||
self.model = HuggingFaceEndpoint( | ||
repo_id=model_id, | ||
task="text_generation", | ||
max_new_tokens=512, | ||
temperature=0.3, | ||
streaming=True, | ||
) | ||
|
||
def process_credit_query(self, state): | ||
""" | ||
Process the user query related to credit. | ||
Args: | ||
state (dict): The current state containing user messages. | ||
""" | ||
messages = state["messages"] | ||
question = messages[0].content | ||
|
||
response = self.model.invoke([{"content": question}]) | ||
return {"messages": [response]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# credit/prompt.py | ||
from langchain.prompts import PromptTemplate | ||
|
||
credit_prompt = PromptTemplate( | ||
template="""You are a credit advisor helping the user understand credit management. \n | ||
Here is the user's query: {question}\n | ||
Provide detailed guidance on credit management and options for the user.""", | ||
input_variables=["question"], | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# credit/__init__.py | ||
from .agent import CreditAgent | ||
from .prompt import credit_prompt | ||
from .workflow import credit_workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Credit/credit_workflow.py | ||
from prefect import task, flow | ||
|
||
@task | ||
def fetch_credit_data(state): | ||
# Simulated credit data | ||
return {"credit_id": state, "limit": 5000, "used": 1200} | ||
|
||
@task | ||
def calculate_remaining_credit(data): | ||
# Calculate remaining credit | ||
limit = data["limit"] | ||
used = data["used"] | ||
remaining_credit = limit - used | ||
return remaining_credit | ||
|
||
@flow | ||
def credit_workflow(state): | ||
credit_data = fetch_credit_data(state) | ||
remaining_credit = calculate_remaining_credit(credit_data) | ||
# Return in the expected format | ||
return {"messages": [{"content": f"Remaining credit amount is: {remaining_credit}"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# loan/agent.py | ||
from langchain_huggingface import HuggingFaceEndpoint | ||
|
||
class LoanAgent: | ||
def __init__(self, model_id="meta-llama/Llama-3.2-3B-Instruct"): | ||
self.model = HuggingFaceEndpoint( | ||
repo_id=model_id, | ||
task="text_generation", | ||
max_new_tokens=512, | ||
temperature=0.3, | ||
streaming=True, | ||
) | ||
|
||
def process_loan_query(self, state): | ||
""" | ||
Process the user query related to loans. | ||
Args: | ||
state (dict): The current state containing user messages. | ||
""" | ||
messages = state["messages"] | ||
question = messages[0].content | ||
|
||
response = self.model.invoke([{"content": question}]) | ||
return {"messages": [response]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"path": ".." | ||
} | ||
], | ||
"settings": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# loan/prompt.py | ||
from langchain.prompts import PromptTemplate | ||
|
||
loan_prompt = PromptTemplate( | ||
template="""You are a loan advisor assisting the user with their loan inquiries. \n | ||
Here is the user's query: {question}\n | ||
Provide a detailed response regarding the loan options, eligibility, and best advice.""", | ||
input_variables=["question"], | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# loan/__init__.py | ||
from .agent import LoanAgent | ||
from .prompt import loan_prompt | ||
from .workflow import loan_workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Loan/loan_workflow.py | ||
|
||
from prefect import task, flow | ||
|
||
# Define a Prefect task for loan data processing | ||
@task | ||
def fetch_loan_data(loan_id): | ||
# Placeholder for fetching loan data (could be from a database or API) | ||
loan_data = {"loan_id": loan_id, "amount": 10000, "interest_rate": 5.5} | ||
#print(f"Fetched loan data: {loan_data}") | ||
return loan_data | ||
|
||
# Define a task to calculate loan repayment | ||
@task | ||
def calculate_repayment(loan_data): | ||
amount = loan_data["amount"] | ||
interest_rate = loan_data["interest_rate"] | ||
repayment = amount * (1 + interest_rate / 100) | ||
#print(f"Calculated repayment amount: {repayment}") | ||
return repayment | ||
|
||
# Define a Prefect flow to tie tasks together | ||
@flow | ||
def loan_workflow(loan_id): | ||
loan_data = fetch_loan_data(loan_id) | ||
repayment = calculate_repayment(loan_data) | ||
#print(f"Final repayment for loan {loan_id}: {repayment}") | ||
return {"messages": [{"content": f"Loan repayment amount is: {repayment}"}]} | ||
|
||
# Call the workflow in main block | ||
if __name__ == "__main__": | ||
loan_workflow(12345) # Pass a sample loan ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
Budget Report: | ||
-------------- | ||
Remaining Budget: 1000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# main.py | ||
import logging | ||
from Budgeting.budgeting_workflow import budgeting_workflow | ||
from Loan.loan_workflow import loan_workflow | ||
from Credit.credit_workflow import credit_workflow | ||
|
||
logging.getLogger("prefect").setLevel(logging.CRITICAL) | ||
|
||
def handle_query(query): | ||
state = {"messages": [{"content": query}]} | ||
|
||
if "budget" in query.lower(): | ||
response = budgeting_workflow(state) # Call the function here | ||
elif "loan" in query.lower(): | ||
response = loan_workflow(state) | ||
elif "credit" in query.lower(): | ||
response = credit_workflow(state) | ||
else: | ||
response = {"messages": [{"content": "I'm not sure about that."}]} | ||
|
||
return response | ||
|
||
def main(): | ||
print("Welcome to the Financial Agent Chatbot! ") | ||
while True: | ||
user_input = input("You: ") | ||
|
||
if user_input.lower() in ["exit", "quit"]: | ||
print("Bot: Goodbye! Have a great day!") | ||
break | ||
|
||
response = handle_query(user_input) | ||
print(f"Bot: {response['messages'][0]['content']}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.