Spaces:
Sleeping
Sleeping
Create components/decision_engine.py
Browse files- components/decision_engine.py +20 -18
components/decision_engine.py
CHANGED
|
@@ -1,32 +1,34 @@
|
|
| 1 |
# components/decision_engine.py
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
-
import
|
|
|
|
| 5 |
from langchain_groq import ChatGroq
|
| 6 |
-
from
|
| 7 |
-
from langchain_core.output_parsers import StrOutputParser
|
| 8 |
from utils.prompts import DECISION_ENGINE_PROMPT
|
| 9 |
|
|
|
|
| 10 |
def run_decision_engine():
|
| 11 |
st.header("🎯 Strategy Suggestions")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
return
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
with st.spinner("Analyzing strategic
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
model_name="llama3-70b-8192",
|
| 23 |
-
groq_api_key=os.getenv("GROQ_API_KEY")
|
| 24 |
)
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
recommendations = chain.invoke({"input": st.session_state.bmc_answers})
|
| 30 |
-
|
| 31 |
-
st.subheader("🧠 Recommended Actions")
|
| 32 |
-
st.write(recommendations)
|
|
|
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|