JARVISXIRONMAN commited on
Commit
84b6fb2
Β·
verified Β·
1 Parent(s): ff228a3

Create components/decision_engine.py

Browse files
Files changed (1) hide show
  1. components/decision_engine.py +24 -21
components/decision_engine.py CHANGED
@@ -1,31 +1,34 @@
 
 
1
  import streamlit as st
 
 
2
  from langchain_groq import ChatGroq
3
- from langchain.prompts import ChatPromptTemplate
4
- from langchain_core.output_parsers import StrOutputParser
5
- from utils.session import get_state_value
6
 
7
  def run_decision_engine():
8
- st.title("🎯 Strategy Suggestions")
9
- st.markdown("Let the AI suggest smart next steps based on your Business Model Canvas.")
10
 
11
- canvas_data = get_state_value("canvas_data", None)
12
- if not canvas_data:
13
  st.warning("Please complete the Canvas Assistant first.")
14
  return
15
 
16
- sections_text = "\n\n".join(
17
- [f"**{section.replace('_', ' ').title()}**:\n{value}" for section, value in canvas_data.items()]
18
- )
19
-
20
- prompt = ChatPromptTemplate.from_messages([
21
- ("system", "You're a strategic business advisor. Analyze the provided Business Model Canvas data and suggest specific next steps to improve and grow the business."),
22
- ("user", "{canvas_summary}")
23
- ])
24
 
25
- chain = prompt | ChatGroq(model_name="llama3-8b-8192", temperature=0.4) | StrOutputParser()
 
 
 
 
 
 
26
 
27
- if st.button("πŸš€ Suggest Strategies"):
28
- with st.spinner("Analyzing your business model..."):
29
- result = chain.invoke({"canvas_summary": sections_text})
30
- st.markdown("### πŸ” AI-Generated Strategy Suggestions")
31
- st.markdown(result)
 
1
+ # components/decision_engine.py
2
+
3
  import streamlit as st
4
+ from langchain_core.prompts import ChatPromptTemplate
5
+ from langchain_core.runnables import Runnable
6
  from langchain_groq import ChatGroq
7
+ from utils.session import get_canvas_data
8
+ from utils.prompts import DECISION_ENGINE_PROMPT
9
+
10
 
11
  def run_decision_engine():
12
+ st.header("🎯 Strategy Suggestions")
 
13
 
14
+ canvas = get_canvas_data()
15
+ if not canvas:
16
  st.warning("Please complete the Canvas Assistant first.")
17
  return
18
 
19
+ # Show canvas summary
20
+ st.subheader("πŸ“‹ Canvas Overview")
21
+ for section, content in canvas.items():
22
+ st.markdown(f"**{section}**")
23
+ st.info(content)
 
 
 
24
 
25
+ with st.spinner("Analyzing canvas for strategic insights..."):
26
+ prompt = ChatPromptTemplate.from_template(
27
+ DECISION_ENGINE_PROMPT + "\n\nCanvas Data:\n{input}"
28
+ )
29
+ chain: Runnable = prompt | ChatGroq(model="llama3-8b-8192", temperature=0.3)
30
+ full_canvas_text = "\n".join([f"{k}: {v}" for k, v in canvas.items()])
31
+ result = chain.invoke({"input": full_canvas_text})
32
 
33
+ st.subheader("🧠 AI Strategy Suggestions")
34
+ st.success(result.content)