Compare commits
No commits in common. "9a09d2a40fce9639fb6812cde9e4be192f61e945" and "d5ddfa45876a099fca5a3b1be8e3c0d20a604ee1" have entirely different histories.
9a09d2a40f
...
d5ddfa4587
12
api.py
12
api.py
@ -23,8 +23,11 @@ def fetch_okrs(user_input: str):
|
|||||||
#system_prompt = settings["system_prompt"]
|
#system_prompt = settings["system_prompt"]
|
||||||
#input_template = settings["input_template"]
|
#input_template = settings["input_template"]
|
||||||
|
|
||||||
|
print("fetch_okr-user_input:", user_input)
|
||||||
|
print("input_template:", INPUT_TEMPLATE)
|
||||||
user_prompt = construct_prompt(prompt_template=PROMPT_TEMPLATE, user_input=user_input)
|
user_prompt = construct_prompt(prompt_template=PROMPT_TEMPLATE, user_input=user_input)
|
||||||
|
|
||||||
|
print("user_prompt:", user_prompt)
|
||||||
headers = {"api-key": api_key, "Content-Type": "application/json"}
|
headers = {"api-key": api_key, "Content-Type": "application/json"}
|
||||||
body = {
|
body = {
|
||||||
"messages": [
|
"messages": [
|
||||||
@ -32,7 +35,8 @@ def fetch_okrs(user_input: str):
|
|||||||
{"role": "user", "content": user_prompt}
|
{"role": "user", "content": user_prompt}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
#print("system prompt:", system_prompt)
|
||||||
|
print("request body:", body)
|
||||||
try:
|
try:
|
||||||
response = requests.post(url=api_url, headers=headers, json=body)
|
response = requests.post(url=api_url, headers=headers, json=body)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@ -40,3 +44,9 @@ def fetch_okrs(user_input: str):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Error fetching data from API: {e}")
|
st.error(f"Error fetching data from API: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
#from config import INPUT_TEMPLATE
|
||||||
|
#result = fetch_okrs(user_input=INPUT_TEMPLATE)
|
||||||
|
#objective = result['choices'][0]['message']['content']
|
||||||
|
#print(type(objective))
|
||||||
124
proposer.py
124
proposer.py
@ -1,3 +1,127 @@
|
|||||||
|
'''import streamlit as st
|
||||||
|
|
||||||
|
from api import fetch_okrs
|
||||||
|
from config import SYSTEM_PROMPT, INPUT_TEMPLATE, PROMPT_TEMPLATE
|
||||||
|
from utils import construct_prompt, extract_llm_response
|
||||||
|
|
||||||
|
def proposer_page():
|
||||||
|
# Streamlit App Layout
|
||||||
|
st.title("AO/PM OKR Proposer")
|
||||||
|
|
||||||
|
# Input Section and Buttons Row
|
||||||
|
st.subheader("Enter your idea or goal:")
|
||||||
|
user_input = st.text_area(
|
||||||
|
"Input your idea here:",
|
||||||
|
value=st.session_state.get("user_input", INPUT_TEMPLATE.strip()),
|
||||||
|
height=300,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("user_input:", user_input)
|
||||||
|
|
||||||
|
generate_okrs_clicked = st.button("Generate OKR Proposal")
|
||||||
|
#col1, col2 = st.columns([1, 1])
|
||||||
|
#with col1:
|
||||||
|
# if st.button("Reset All"):
|
||||||
|
# st.session_state.clear()
|
||||||
|
#with col2:
|
||||||
|
|
||||||
|
|
||||||
|
if generate_okrs_clicked:
|
||||||
|
if not user_input.strip():
|
||||||
|
st.warning("Please provide some input before generating OKRs.")
|
||||||
|
else:
|
||||||
|
#user_input = st.session_state.get("user_input")
|
||||||
|
with st.spinner("Generating OKRs..."):
|
||||||
|
# Construct prompt and call API
|
||||||
|
#prompt = construct_prompt(prompt_template=PROMPT_TEMPLATE, user_input=user_input)
|
||||||
|
response = fetch_okrs(user_input=user_input)
|
||||||
|
#print("user_input:", user_input)
|
||||||
|
if response:
|
||||||
|
# Extract Objective and Key Results from response
|
||||||
|
print(response)
|
||||||
|
objective, key_results, hint = extract_llm_response(response)
|
||||||
|
|
||||||
|
st.session_state["objective"] = objective
|
||||||
|
st.session_state["key_results"] = key_results
|
||||||
|
st.session_state["hint"] = hint
|
||||||
|
|
||||||
|
#st.subheader("Hint to improve the OKR proposal")
|
||||||
|
#st.text(hint)
|
||||||
|
|
||||||
|
# Display Results Only if an OKR Has Been Generated
|
||||||
|
if "objective" in st.session_state and "key_results" in st.session_state:
|
||||||
|
|
||||||
|
# Display Objective Field with Responsibles Input Below It
|
||||||
|
st.subheader("Proposal Objective:")
|
||||||
|
objective_text = st.text_area(
|
||||||
|
"Proposal Objective:",
|
||||||
|
value=st.session_state.get("objective", ""),
|
||||||
|
height=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
responsible_for_objective = st.text_input(
|
||||||
|
"Responsibles for Objective (comma-separated):",
|
||||||
|
value="",
|
||||||
|
placeholder="e.g., Khanh Dinh, John Doe",
|
||||||
|
key="responsibles_objective"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Display Key Results with Responsibles Below Each One
|
||||||
|
st.subheader("Proposal Key Results:")
|
||||||
|
key_result_boxes = []
|
||||||
|
responsibles_for_key_results = []
|
||||||
|
|
||||||
|
for i, kr in enumerate(st.session_state["key_results"], start=1):
|
||||||
|
kr_text = st.text_area(f"Key Result {i}:", value=kr, key=f"kr_{i}")
|
||||||
|
responsible_for_kr = st.text_input(
|
||||||
|
f"Responsibles for Key Result {i} (comma-separated):",
|
||||||
|
value="",
|
||||||
|
placeholder="e.g., Khanh Dinh",
|
||||||
|
key=f"responsibles_kr_{i}"
|
||||||
|
)
|
||||||
|
|
||||||
|
key_result_boxes.append(kr_text)
|
||||||
|
responsibles_for_key_results.append(responsible_for_kr)
|
||||||
|
|
||||||
|
# Finalize Button Center-Aligned
|
||||||
|
#finalize_col = st.columns([3, 2, 3])[1]
|
||||||
|
#with finalize_col:
|
||||||
|
if st.button("Finalize"):
|
||||||
|
finalized_objective = objective_text.strip()
|
||||||
|
finalized_key_results = [st.session_state[f"kr_{i+1}"].strip() for i in range(len(key_result_boxes))]
|
||||||
|
|
||||||
|
# Append initials of responsibles to Objective and Key Results
|
||||||
|
responsibles_list_objective = [name.strip() for name in responsible_for_objective.split(",") if name.strip()]
|
||||||
|
initials_objective = [f"[{''.join([part[0] for part in name.split()]).upper()}]" for name in responsibles_list_objective]
|
||||||
|
initials_str_objective = ", ".join(initials_objective)
|
||||||
|
|
||||||
|
finalized_objective = f"{initials_str_objective} {finalized_objective}"
|
||||||
|
|
||||||
|
finalized_key_results_with_initials = []
|
||||||
|
for i, kr in enumerate(finalized_key_results):
|
||||||
|
responsibles_list_kr = [name.strip() for name in responsibles_for_key_results[i].split(",") if name.strip()]
|
||||||
|
initials_kr = [f"{''.join([part[0] for part in name.split()]).upper()}" for name in responsibles_list_kr]
|
||||||
|
initials_str_kr = ", ".join(initials_kr)
|
||||||
|
finalized_key_results_with_initials.append(f"KR{i+1}: [{initials_str_kr}] {kr}")
|
||||||
|
|
||||||
|
# Display finalized data in non-editable format (full width)
|
||||||
|
st.subheader("Finalized Objective:")
|
||||||
|
st.code(
|
||||||
|
body=finalized_objective,
|
||||||
|
language=None,
|
||||||
|
wrap_lines=True
|
||||||
|
)
|
||||||
|
|
||||||
|
st.subheader("Finalized Key Results:")
|
||||||
|
for kr in finalized_key_results_with_initials:
|
||||||
|
st.code(
|
||||||
|
body=kr,
|
||||||
|
language=None,
|
||||||
|
wrap_lines=True
|
||||||
|
)
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
from api import fetch_okrs
|
from api import fetch_okrs
|
||||||
from config import INPUT_TEMPLATE, team
|
from config import INPUT_TEMPLATE, team
|
||||||
|
|||||||
57
utils.py
57
utils.py
@ -1,11 +1,66 @@
|
|||||||
import json
|
import json
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
import re
|
|
||||||
|
|
||||||
# Function to construct the prompt
|
# Function to construct the prompt
|
||||||
def construct_prompt(prompt_template: str, user_input: str) -> str:
|
def construct_prompt(prompt_template: str, user_input: str) -> str:
|
||||||
return prompt_template.format(user_input=user_input)
|
return prompt_template.format(user_input=user_input)
|
||||||
|
|
||||||
|
'''# Function to extract and parse JSON response
|
||||||
|
def extract_llm_response(response):
|
||||||
|
print("response:", response)
|
||||||
|
try:
|
||||||
|
raw_message_content = response["choices"][0]["message"]["content"]
|
||||||
|
print("raw_message_content:", raw_message_content)
|
||||||
|
# Clean and parse the JSON content
|
||||||
|
cleaned_content = raw_message_content.replace("`", "").split("json")[-1]
|
||||||
|
|
||||||
|
# for debugging
|
||||||
|
#if debug:
|
||||||
|
# print("cleaned:", '-'*50)
|
||||||
|
# print(cleaned_content.strip())
|
||||||
|
|
||||||
|
def parse_json_content(cleaned_content: str):
|
||||||
|
"""
|
||||||
|
Parses the cleaned content to extract valid JSON data.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
cleaned_content (str): The raw content containing JSON data.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict or list: The parsed JSON object.
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
|
||||||
|
# Step 1: Strip unwanted characters and clean the content
|
||||||
|
cleaned_content = cleaned_content.strip()
|
||||||
|
|
||||||
|
# Step 2: Use regex to extract only the valid JSON block (e.g., starts with [ or {)
|
||||||
|
json_match = re.search(r"(\{.*\}|\[.*\])", cleaned_content, re.DOTALL)
|
||||||
|
|
||||||
|
if not json_match:
|
||||||
|
raise ValueError("No valid JSON found in the content.")
|
||||||
|
|
||||||
|
# Step 3: Extract and parse the valid JSON
|
||||||
|
valid_json = json_match.group(0) # Extract matched JSON block
|
||||||
|
try:
|
||||||
|
extracted_data = json.loads(valid_json)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
raise ValueError(f"Failed to decode JSON. Error: {e}\nContent:\n{valid_json}")
|
||||||
|
|
||||||
|
return extracted_data
|
||||||
|
|
||||||
|
parsed_data = parse_json_content(cleaned_content=cleaned_content)
|
||||||
|
print("parsed_data:",parsed_data)
|
||||||
|
print("debug:", parsed_data.get("objective", ""))
|
||||||
|
|
||||||
|
#parsed_data = json.loads(cleaned_content)
|
||||||
|
return parsed_data.get("objective", ""), parsed_data.get("key_results", [])
|
||||||
|
except Exception as e:
|
||||||
|
st.error(f"Error parsing API response: {e}")
|
||||||
|
return "", []'''
|
||||||
|
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
def parse_json_content(cleaned_content: str):
|
def parse_json_content(cleaned_content: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user