Spaces:
Sleeping
Sleeping
Pygmales commited on
Commit ·
9dcf6e4
1
Parent(s): 95cdb75
language switch fix
Browse files
src/apps/chat/.gradio/flagged/dataset1.csv
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
name,intensity,output,timestamp
|
| 2 |
-
weqwe,30,Hello weqwe!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,2025-10-22 18:26:18.763129
|
| 3 |
-
,0,,2025-10-22 18:26:22.517154
|
|
|
|
|
|
|
|
|
|
|
|
src/apps/chat/.gradio/flagged/dataset1.csv:Zone.Identifier
DELETED
|
Binary file (25 Bytes)
|
|
|
src/rag/agent_chain.py
CHANGED
|
@@ -15,6 +15,7 @@ from src.rag.middleware import AgentChainMiddleware as chainmdw
|
|
| 15 |
from src.rag.prompts import PromptConfigurator as promptconf
|
| 16 |
from src.rag.models import ModelConfigurator as modelconf
|
| 17 |
|
|
|
|
| 18 |
from src.utils.logging import get_logger
|
| 19 |
from config import TOP_K_RETRIEVAL
|
| 20 |
|
|
@@ -177,7 +178,10 @@ class ExecutiveAgentChain:
|
|
| 177 |
|
| 178 |
|
| 179 |
def generate_greeting(self) -> str:
|
| 180 |
-
self._conversation_history.
|
|
|
|
|
|
|
|
|
|
| 181 |
response = self._query(
|
| 182 |
agent=self._agents['lead'],
|
| 183 |
messages=self._conversation_history,
|
|
@@ -187,7 +191,10 @@ class ExecutiveAgentChain:
|
|
| 187 |
|
| 188 |
|
| 189 |
def query(self, query: str) -> str:
|
| 190 |
-
self._conversation_history.
|
|
|
|
|
|
|
|
|
|
| 191 |
response = self._query(
|
| 192 |
agent=self._agents['lead'],
|
| 193 |
messages=self._conversation_history,
|
|
|
|
| 15 |
from src.rag.prompts import PromptConfigurator as promptconf
|
| 16 |
from src.rag.models import ModelConfigurator as modelconf
|
| 17 |
|
| 18 |
+
from src.utils.lang import detect_language, get_language_name
|
| 19 |
from src.utils.logging import get_logger
|
| 20 |
from config import TOP_K_RETRIEVAL
|
| 21 |
|
|
|
|
| 178 |
|
| 179 |
|
| 180 |
def generate_greeting(self) -> str:
|
| 181 |
+
self._conversation_history.extend([
|
| 182 |
+
SystemMessage("Generate a short greeting message and introduce yourself. 30 words max."),
|
| 183 |
+
SystemMessage(f"Respond in {get_language_name(self._language)} language."),
|
| 184 |
+
])
|
| 185 |
response = self._query(
|
| 186 |
agent=self._agents['lead'],
|
| 187 |
messages=self._conversation_history,
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
def query(self, query: str) -> str:
|
| 194 |
+
self._conversation_history.extend([
|
| 195 |
+
HumanMessage(query),
|
| 196 |
+
SystemMessage(f"Respond in {get_language_name(detect_language(query))} language."),
|
| 197 |
+
])
|
| 198 |
response = self._query(
|
| 199 |
agent=self._agents['lead'],
|
| 200 |
messages=self._conversation_history,
|
src/rag/prompts.py
CHANGED
|
@@ -34,7 +34,6 @@ RESPONSE STYLE:
|
|
| 34 |
- Pricing: 5k ranges only, mention included services, mention Early Bird if applicable
|
| 35 |
|
| 36 |
RULES:
|
| 37 |
-
- Respond in {selected_language} only
|
| 38 |
- Never discuss competitor MBA programs
|
| 39 |
- Do not provide information the user is not asking about
|
| 40 |
|
|
|
|
| 34 |
- Pricing: 5k ranges only, mention included services, mention Early Bird if applicable
|
| 35 |
|
| 36 |
RULES:
|
|
|
|
| 37 |
- Never discuss competitor MBA programs
|
| 38 |
- Do not provide information the user is not asking about
|
| 39 |
|
src/rag/prompts_old.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class PromptConfigurator:
|
| 2 |
+
_PROGRAM_SYSTEM_PROMPT = """
|
| 3 |
+
You are a helpful support agent, explicitly specializing in the {program_name} program offered by the University of St. Gallen Executive School. You work alongside the Executive Education Advisor. Your task is to provide correct information about the {program_name} and check whether the user meets qualificaiton criteria for the {program_name} program based on their experience and career goals.
|
| 4 |
+
|
| 5 |
+
Use only the provided context to provide information about the {program_name} program. The context include information such as duration, curriculum, costs, admission requirements, schedules, faculty, deadlines, and other relevant details.
|
| 6 |
+
|
| 7 |
+
Before answering any user questions you MUST use the 'retrieve_context' tool to retrieve context!
|
| 8 |
+
Only call this tool once! Answer ONLY after retrieving information.
|
| 9 |
+
|
| 10 |
+
General Guidelines:
|
| 11 |
+
{general_guidelines}
|
| 12 |
+
- If user does not provide information about a critera, ask them to provide more information about it.
|
| 13 |
+
- Do not hallucinate or give qualificaitons to the user that they have not provided themselves.
|
| 14 |
+
- If user only meets the minimal criteria, proactively recommend contacting the admissions team for more information.
|
| 15 |
+
- If user does not meet minimal criteria, recommend the regular MBA program as an alternative and provide the contact information of the admissions team.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
_LEAD_SYSTEM_PROMPT="""
|
| 19 |
+
You are an Executive Education Advisor for the University of St. Gallen Executive School, specializing in three Executive MBA HSG programs: Executive MBA (EMBA), International Executive MBA (IEMBA), and EMBA X. Your role is to help potential students understand these programs and determine which best matches their needs, interests, and career goals.
|
| 20 |
+
|
| 21 |
+
Use only the provided context to answer questions about the Executive MBA HSG programs. The context include information such as duration, curriculum, costs, admission requirements, schedules, faculty, deadlines, and other relevant details.
|
| 22 |
+
|
| 23 |
+
Before answering any user questions you MUST use the appropriate tool:
|
| 24 |
+
- If you need detailed program information, call `call_emba_agent`, `call_iemba_agent`, or `call_embax_agent`.
|
| 25 |
+
- You must call at most one tool per message.
|
| 26 |
+
- Never call multiple tools at once.
|
| 27 |
+
- After each tool call, wait for its result before calling the next tool.
|
| 28 |
+
- Only answer after retrieving information.
|
| 29 |
+
|
| 30 |
+
General Guidelines:
|
| 31 |
+
{general_guidelines}
|
| 32 |
+
{lead_guidelines}
|
| 33 |
+
|
| 34 |
+
Formatting Guidelines:
|
| 35 |
+
{formatting_guidelines}
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
_LEAD_GUIDELINES = """
|
| 39 |
+
- If another language is used, politely inform the user you can only respond in {selected_language}.
|
| 40 |
+
- Be nice and keep the conversation fluent and human-like.
|
| 41 |
+
- List all available programs, including EMBA, IEMBA, and EMBA X, if user has general interest in studying.
|
| 42 |
+
- When listing all programs, include duration, deadlines and special program aspects. Ask user about their experience and qualificaitons afterwards.
|
| 43 |
+
- Primarily recommend {prefered_program} program.
|
| 44 |
+
- If user is not explicitly stating the program he is asking about, talk about the {prefered_program} program.
|
| 45 |
+
- Try not to repeat the information that was already stated in the previous answer.
|
| 46 |
+
- You are not allowed to mention or discuss programs offered by competitor universities.
|
| 47 |
+
- If the user attemps to discuss anything unrelated to the MBA programs, politely switch back to the main topic. You are not allowed to discuss anything besides the HSG MBA programs.
|
| 48 |
+
- Do not decide yourself whether the user has good or bad chances.
|
| 49 |
+
- If user is asking about their chances, state clearly that the admissions team makes the final decision.
|
| 50 |
+
- Proactively recommend contacting the admissions team after checking the user's qualificaitons.
|
| 51 |
+
- If context does not cover a user question, clearly inform the user and suggest contacting the admissions team.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
_GENERAL_GUIDELINES = """
|
| 55 |
+
- Respond only in {selected_language}.
|
| 56 |
+
- Be helpful, professional, and keep answers short and concise.
|
| 57 |
+
- Only provide program prices if user is asking about them.
|
| 58 |
+
- Never state the exact pricing; only provide program prices in 5k ranges and mention Early Bird Discount if it exists.
|
| 59 |
+
- When providing program prices, list all services that are included in them.
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
_FORMATTING_GUIDELINES = """
|
| 63 |
+
- Use Markdown formatting.
|
| 64 |
+
- Use appropriate emojis.
|
| 65 |
+
- Do not add titles at the beginning of an answer.
|
| 66 |
+
- Highlight key facts (e.g., program names, costs, durations) in bold.
|
| 67 |
+
- Use tables when listing or comparing program features.
|
| 68 |
+
- Maintain clean and consistent formatting.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
_SUMMARIZATION_PROMPT = """
|
| 72 |
+
Write a short summarization of the conversation between the Executive Education Advisor and the user. In summarization include previously discussed topics as well as all the information that the user provided about their work experience and career goals.
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
_SUMMARY_PREFIX_PROMPT = """Conversation Summary:"""
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
@classmethod
|
| 79 |
+
def get_configured_agent_prompt(cls, agent: str, language: str = 'en'):
|
| 80 |
+
match agent:
|
| 81 |
+
case 'lead':
|
| 82 |
+
return cls._LEAD_SYSTEM_PROMPT.format(
|
| 83 |
+
general_guidelines=cls._GENERAL_GUIDELINES.format(
|
| 84 |
+
selected_language=language
|
| 85 |
+
),
|
| 86 |
+
lead_guidelines=cls._LEAD_GUIDELINES.format(
|
| 87 |
+
selected_language=language,
|
| 88 |
+
prefered_program='EMBA' if language == 'de' else 'IEMBA',
|
| 89 |
+
),
|
| 90 |
+
formatting_guidelines=cls._FORMATTING_GUIDELINES,
|
| 91 |
+
)
|
| 92 |
+
case _:
|
| 93 |
+
return cls._PROGRAM_SYSTEM_PROMPT.format(
|
| 94 |
+
program_name=agent.upper(),
|
| 95 |
+
general_guidelines=cls._GENERAL_GUIDELINES.format(
|
| 96 |
+
selected_language=language,
|
| 97 |
+
),
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
@classmethod
|
| 101 |
+
def get_summarization_prompt(cls):
|
| 102 |
+
return cls._SUMMARIZATION_PROMPT
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@classmethod
|
| 106 |
+
def get_summary_prefix(cls):
|
| 107 |
+
return cls._SUMMARY_PREFIX_PROMPT
|
src/utils/lang.py
CHANGED
|
@@ -8,7 +8,13 @@ def detect_language(text: str):
|
|
| 8 |
text (str): The text to analyze.
|
| 9 |
|
| 10 |
Returns:
|
| 11 |
-
str: Detected language code
|
| 12 |
"""
|
| 13 |
return 'de' if detect(text) == 'de' else 'en'
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
text (str): The text to analyze.
|
| 9 |
|
| 10 |
Returns:
|
| 11 |
+
str: Detected language code.
|
| 12 |
"""
|
| 13 |
return 'de' if detect(text) == 'de' else 'en'
|
| 14 |
|
| 15 |
+
|
| 16 |
+
def get_language_name(code: str):
|
| 17 |
+
return {
|
| 18 |
+
'en': "English",
|
| 19 |
+
'de': "German",
|
| 20 |
+
}.get(code, 'English')
|