fixed the issue so that custom ideas can be provided as input

This commit is contained in:
Khanh Dinh 2025-01-02 22:14:19 +01:00
parent e2f61da273
commit d59ebdc4c3
3 changed files with 20 additions and 10 deletions

25
api.py
View File

@ -5,6 +5,7 @@ from dotenv import load_dotenv
from settings import load_settings
from utils import construct_prompt
from config import INPUT_TEMPLATE, SYSTEM_PROMPT, PROMPT_TEMPLATE
# Load API key from .env file
load_dotenv()
@ -17,21 +18,25 @@ if not api_key:
api_url = "https://genai.dev.odp.lhgroup.de/openai/deployments/gpt-4-turbo/chat/completions?api-version=2023-07-01-preview"
def fetch_okrs(user_input: str):
settings = load_settings()
#settings = load_settings()
system_prompt = settings["system_prompt"]
input_template = settings["input_template"]
#system_prompt = settings["system_prompt"]
#input_template = settings["input_template"]
user_prompt = construct_prompt(prompt_template=input_template, user_input=user_input)
print("fetch_okr-user_input:", user_input)
print("input_template:", INPUT_TEMPLATE)
user_prompt = construct_prompt(prompt_template=PROMPT_TEMPLATE, user_input=user_input)
print(user_prompt)
print("user_prompt:", user_prompt)
headers = {"api-key": api_key, "Content-Type": "application/json"}
body = {
"messages": [
{"role": "system", "content": system_prompt},
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_prompt}
]
}
#print("system prompt:", system_prompt)
print("request body:", body)
try:
response = requests.post(url=api_url, headers=headers, json=body)
response.raise_for_status()
@ -41,7 +46,7 @@ def fetch_okrs(user_input: str):
return None
from config import INPUT_TEMPLATE
result = fetch_okrs(user_input=INPUT_TEMPLATE)
objective = result['choices'][0]['message']['content']
print(type(objective))
#from config import INPUT_TEMPLATE
#result = fetch_okrs(user_input=INPUT_TEMPLATE)
#objective = result['choices'][0]['message']['content']
#print(type(objective))

View File

@ -83,6 +83,7 @@ The json could be structured like this:
PROMPT_TEMPLATE = """
Please help us in defining proper OKRs.
Here is what we have thought about and we would like to phrase an OKR with maximum 5 key results.
The next OKR cycle is from JAN 2025 till APR 2025.
this is the user input:
{user_input}

View File

@ -16,6 +16,8 @@ def proposer_page():
height=300,
)
print("user_input:", user_input)
generate_okrs_clicked = st.button("Generate OKR Proposal")
#col1, col2 = st.columns([1, 1])
#with col1:
@ -28,10 +30,12 @@ def proposer_page():
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)