|
from exa_py import Exa |
|
from groq import Groq |
|
import os |
|
import streamlit as st |
|
from app import data |
|
|
|
|
|
exa = Exa(api_key=os.getenv("EXA_API_KEY")) |
|
|
|
|
|
groq_api_keys = os.getenv("GROQ_API_KEYS").split(",") |
|
available_groq_apis = [Groq(api_key=key.strip()) for key in groq_api_keys if key.strip()] |
|
|
|
current_api_index = 0 |
|
utilized_model = "llama3-70b-8192" |
|
|
|
highlights_options = { |
|
"num_sentences": 7, |
|
"highlights_per_url": 1, |
|
} |
|
|
|
def call_llm(prompt): |
|
global current_api_index,data |
|
|
|
while current_api_index < len(available_groq_apis): |
|
try: |
|
client = available_groq_apis[current_api_index] |
|
search_response = exa.search_and_contents(query=prompt, highlights=highlights_options, num_results=3, use_autoprompt=True) |
|
info = [sr.highlights[0] for sr in search_response.results] |
|
|
|
system_prompt = f"You are a Business proposal generator in language of {data['language']}. Read the provided contexts and, if relevant, use them to answer the user's question." |
|
user_prompt = f"Sources: {info}\nQuestion: {prompt}" |
|
|
|
completion = client.chat.completions.create( |
|
model=utilized_model, |
|
messages=[ |
|
{"role": "system", "content": system_prompt}, |
|
{"role": "user", "content": user_prompt}, |
|
] |
|
) |
|
return completion.choices[0].message.content |
|
|
|
except Exception as e: |
|
st.error(f"API {current_api_index + 1} expired or failed: {str(e)}") |
|
current_api_index += 1 |
|
|
|
raise Exception("All available APIs have expired.") |
|
|
|
|
|
|
|
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN") |
|
|
|
def send_telegram_message(chat_id, text): |
|
url = f'https://api.telegram.org/bot{BOT_TOKEN}/sendMessage' |
|
payload = {'chat_id': chat_id, 'text': text, 'parse_mode': 'Markdown'} |
|
response = requests.post(url, data=payload) |
|
return response.json() |
|
|
|
def get_chat_id(): |
|
url = f'https://api.telegram.org/bot{BOT_TOKEN}/getUpdates' |
|
response = requests.get(url) |
|
updates = response.json().get('result', []) |
|
if updates: |
|
chat_id = updates[0]['message']['chat']['id'] |
|
return chat_id |
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def generate_executive_summary(data): |
|
prompt = f""" |
|
Generate a concise executive summary for a business proposal based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
Location: {data["location"]} |
|
Mission Statement: {data["mission"]} |
|
Vision Statement: {data["vision"]} |
|
Products/Services: {data["products_services"]} |
|
Target Market: {data["target_market"]} |
|
Value Proposition: {data["value_proposition"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
Funding Requirements: {data["funding_requirements"]} |
|
Management Team: {data["management_team"]} |
|
Company Structure: {data["company_structure"]} |
|
Goals and Objectives: {data["goals_objectives"]} |
|
Operational Strategy: {data["operational_strategy"]} |
|
Market Overview: {data["market_overview"]} |
|
Promotional Strategy: {data["promotional_strategy"]} |
|
|
|
The executive summary should highlight the key points of the business proposal, including the company's mission, products/services, target market, competitive advantage, financial information, and funding requirements. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_mission(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's mission based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Mission Statement: {data["mission"]} |
|
|
|
The mission statement should clearly explain the company's purpose, values, and goals. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_vision(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's vision based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Vision Statement: {data["vision"]} |
|
|
|
The vision statement should describe the company's long-term aspirations and the desired future state of the business. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_objectives(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's short-term and long-term goals and objectives based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Goals and Objectives: {data["goals_objectives"]} |
|
|
|
The objectives should be specific, measurable, achievable, relevant, and time-bound (SMART). |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_core_values(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's core values based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Mission Statement: {data["mission"]} |
|
|
|
The core values should reflect the principles and beliefs that guide the company's decision-making and behavior. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_business_description(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's business based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
Products/Services: {data["products_services"]} |
|
|
|
The business description should provide an overview of the company's operations, including its products or services, target market, and competitive advantages. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_company_location(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's location based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Location: {data["location"]} |
|
|
|
The company location description should highlight the advantages and benefits of the chosen location for the business. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_products(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's products or services based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Products/Services: {data["products_services"]} |
|
|
|
The product description should provide a comprehensive overview of the company's offerings, including their features, benefits, and unique selling points. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_ownership(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's ownership structure based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Management Team: {data["management_team"]} |
|
Company Structure: {data["company_structure"]} |
|
|
|
The ownership description should explain the legal structure of the company and the roles and responsibilities of the management team. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_company_structure(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's organizational structure based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Company Structure: {data["company_structure"]} |
|
|
|
The company structure description should outline the various departments, teams, and reporting relationships within the organization. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_management_profiles(data): |
|
prompt = f""" |
|
Generate detailed profiles of the key members of the management team based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Management Team: {data["management_team"]} |
|
|
|
The management profiles should highlight the relevant experience, skills, and achievements of each team member. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_operational_strategy(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's operational strategy based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Operational Strategy: {data["operational_strategy"]} |
|
|
|
The operational strategy description should explain how the company will efficiently manage its day-to-day operations to achieve its goals and objectives. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_marketing_mix(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's marketing mix strategy based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Products/Services: {data["products_services"]} |
|
Target Market: {data["target_market"]} |
|
Value Proposition: {data["value_proposition"]} |
|
Promotional Strategy: {data["promotional_strategy"]} |
|
|
|
The marketing mix strategy should cover the 4Ps: product, price, place, and promotion. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_promotional_strategy(data): |
|
prompt = f""" |
|
Generate a detailed description of the company's promotional strategy based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Promotional Strategy: {data["promotional_strategy"]} |
|
|
|
The promotional strategy should outline the various marketing channels and tactics the company will use to reach its target market and promote its products or services. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def analyze_demand(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the market demand for the company's products or services based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
Target Market: {data["target_market"]} |
|
Market Overview: {data["market_overview"]} |
|
|
|
The market demand analysis should include information on market size, growth trends, and potential for the company's offerings. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def segment_market(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the target market segmentation based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Target Market: {data["target_market"]} |
|
|
|
The market segmentation analysis should identify and describe the key customer segments the company will target, including their demographics, psychographics, and buying behaviors. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def analyze_competitors(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the company's competitors based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
Products/Services: {data["products_services"]} |
|
|
|
The competitor analysis should identify the key players in the market, their market share, strengths, weaknesses, and strategies. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def perform_porters_five_forces(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the company's industry using Porter's Five Forces framework based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
|
|
The Porter's Five Forces analysis should assess the level of competition and profitability in the industry based on the bargaining power of suppliers and buyers, the threat of new entrants and substitutes, and the intensity of rivalry among existing competitors. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def analyze_industry_accommodation(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the company's industry based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
|
|
The industry analysis should provide an overview of the key trends, challenges, and opportunities in the industry, as well as the company's position within the industry. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def list_major_players(data): |
|
prompt = f""" |
|
Generate a list of the major players in the company's industry based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
|
|
The list of major players should include the company's key competitors and their market share, products or services, and competitive advantages. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def analyze_business_sub_sector(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the company's business sub-sector based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
Products/Services: {data["products_services"]} |
|
|
|
The business sub-sector analysis should provide an in-depth look at the specific segment of the industry in which the company operates, including market trends, growth potential, and competitive landscape. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_swot_analysis(data): |
|
prompt = f""" |
|
Generate a detailed SWOT analysis for the company based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
Products/Services: {data["products_services"]} |
|
Target Market: {data["target_market"]} |
|
Value Proposition: {data["value_proposition"]} |
|
|
|
The SWOT analysis should identify the company's strengths, weaknesses, opportunities, and threats, taking into account both internal and external factors. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_funding_request(data): |
|
prompt = f""" |
|
Generate a detailed funding request section based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
Funding Requirements: {data["funding_requirements"]} |
|
|
|
The funding request should clearly state the amount of funding needed, how the funds will be used, and the expected return on investment for investors. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def create_financing_plan(data): |
|
prompt = f""" |
|
Generate a detailed financing plan and bank loan amortization schedule based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Funding Requirements: {data["funding_requirements"]} |
|
|
|
The financing plan should outline the sources of funding, repayment terms, and projected cash flows to demonstrate the company's ability to service the debt. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_pro_forma_income_statement(data): |
|
prompt = f""" |
|
Generate a pro forma income statement analysis based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
|
|
The pro forma income statement should project the company's future revenues, expenses, and net income based on assumptions about growth, pricing, and cost structure. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def predict_revenue_expenses(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the company's projected revenue and expenses based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
|
|
The revenue and expense analysis should provide a breakdown of the key drivers of revenue and cost, and explain the assumptions used in the projections. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_monthly_cash_flow(data): |
|
prompt = f""" |
|
Generate a monthly cash flow analysis for the company based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
|
|
The monthly cash flow analysis should project the company's cash inflows and outflows on a monthly basis, taking into account factors such as sales, collections, payments, and financing activities. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_pro_forma_annual_cash_flow(data): |
|
prompt = f""" |
|
Generate a pro forma annual cash flow analysis for the company based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
|
|
The pro forma annual cash flow analysis should provide a summary of the expected cash inflows and outflows for the upcoming year, including assumptions about growth and expenses. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_pro_forma_balance_sheet(data): |
|
prompt = f""" |
|
Generate a pro forma balance sheet analysis for the company based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
|
|
The pro forma balance sheet should project the company's assets, liabilities, and equity based on expected growth and funding requirements. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def perform_break_even_analysis(data): |
|
prompt = f""" |
|
Generate a break-even analysis for the company based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
|
|
The break-even analysis should determine the sales volume at which the company will cover its costs and begin to make a profit. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def calculate_payback_period(data): |
|
prompt = f""" |
|
Generate a payback period analysis for the company based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Funding Requirements: {data["funding_requirements"]} |
|
|
|
The payback period analysis should calculate the time it will take for the company to recover its initial investment from cash inflows. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def generate_financial_graphs(data): |
|
prompt = f""" |
|
Generate a summary of the key financial graphs that should be included in the business proposal based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Current Revenue: {data["current_revenue"]} |
|
Current Expenses: {data["current_expenses"]} |
|
|
|
The financial graphs should visually represent the company's projected income statement, cash flow statement, and balance sheet. |
|
""" |
|
return call_llm(prompt) |
|
|
|
def identify_risks_mitigations(data): |
|
prompt = f""" |
|
Generate a detailed analysis of the risks and mitigations for the company based on the following information: |
|
|
|
Company Name: {data["company_name"]} |
|
Industry: {data["industry"]} |
|
|
|
The risk mitigations analysis should identify potential risks to the business and outline strategies to mitigate those risks. |
|
""" |
|
return call_llm(prompt) |