Sohan Kshirsagar commited on
Commit
b401a63
·
1 Parent(s): 393fccb

persona functionality addition, default personas

Browse files
multi_llm_chatbot_backend/app/models/default_personas.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from app.models.persona import Persona
2
+
3
+ # Registry of default personas
4
+ DEFAULT_PERSONAS = {
5
+ "methodist": {
6
+ "name": "Methodical Advisor",
7
+ "system_prompt": "You are a highly methodical PhD advisor. Provide organized, step-by-step guidance with strong structure and clarity.",
8
+ "default_temperature": 5
9
+ },
10
+ "theorist": {
11
+ "name": "Theorist Advisor",
12
+ "system_prompt": "You are a philosophical PhD advisor who focuses on abstract theories and big-picture thinking.",
13
+ "default_temperature": 8
14
+ },
15
+ "pragmatist": {
16
+ "name": "Pragmatist Advisor",
17
+ "system_prompt": "You are a practical PhD advisor who gives real-world, actionable advice focused on utility and outcomes.",
18
+ "default_temperature": 4
19
+ }
20
+ }
21
+
22
+ OPTIONAL_PERSONAS = {
23
+ "socratic": {
24
+ "name": "Socratic Mentor",
25
+ "system_prompt": "You ask thought-provoking questions to guide the student to their own insights, Socratic style.",
26
+ "default_temperature": 7
27
+ },
28
+ "motivator": {
29
+ "name": "Motivational Coach",
30
+ "system_prompt": "You are an energetic, encouraging mentor who inspires confidence, motivation, and perseverance.",
31
+ "default_temperature": 6
32
+ },
33
+ "critic": {
34
+ "name": "Constructive Critic",
35
+ "system_prompt": "You are a critical advisor who highlights gaps, weaknesses, and areas for improvement with rigor.",
36
+ "default_temperature": 6
37
+ },
38
+ "storyteller": {
39
+ "name": "Narrative Advisor",
40
+ "system_prompt": "You are a storytelling mentor who weaves insights through compelling analogies and narratives.",
41
+ "default_temperature": 9
42
+ },
43
+ "minimalist": {
44
+ "name": "Minimalist Mentor",
45
+ "system_prompt": "You provide concise, no-fluff guidance. Keep it short, clean, and to the point.",
46
+ "default_temperature": 2
47
+ },
48
+ "visionary": {
49
+ "name": "Visionary Strategist",
50
+ "system_prompt": "You are a big-picture strategist who helps students explore futuristic ideas and bold directions.",
51
+ "default_temperature": 9
52
+ },
53
+ "empathetic": {
54
+ "name": "Empathetic Listener",
55
+ "system_prompt": "You are a warm, supportive mentor who emphasizes emotional well-being and understands challenges.",
56
+ "default_temperature": 6
57
+ }
58
+ }
59
+
60
+ def get_default_personas(llm):
61
+ return [
62
+ Persona(
63
+ id=pid,
64
+ name=data["name"],
65
+ system_prompt=data["system_prompt"],
66
+ llm=llm,
67
+ temperature=data.get("default_temperature", 5)
68
+ ) for pid, data in DEFAULT_PERSONAS.items()
69
+ ]
70
+
71
+ def get_default_persona_prompt(persona_id):
72
+ data = DEFAULT_PERSONAS.get(persona_id)
73
+ return data["system_prompt"] if data else None
74
+
75
+ def is_valid_persona_id(pid):
76
+ return pid in DEFAULT_PERSONAS or pid in OPTIONAL_PERSONAS
77
+
78
+ def list_available_personas():
79
+ return list(DEFAULT_PERSONAS.keys()).append(list(OPTIONAL_PERSONAS.keys()))
multi_llm_chatbot_backend/app/models/persona.py CHANGED
@@ -1,11 +1,36 @@
1
  from app.llm.llm_client import LLMClient
2
 
3
  class Persona:
4
- def __init__(self, id: str, name: str, system_prompt: str, llm: LLMClient):
5
  self.id = id
6
  self.name = name
7
  self.system_prompt = system_prompt
8
  self.llm = llm
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- async def respond(self, context: list[dict]) -> str:
11
- return await self.llm.generate(self.system_prompt, context)
 
1
  from app.llm.llm_client import LLMClient
2
 
3
  class Persona:
4
+ def __init__(self, id, name, system_prompt, llm, temperature=5):
5
  self.id = id
6
  self.name = name
7
  self.system_prompt = system_prompt
8
  self.llm = llm
9
+ self.temperature = temperature
10
+
11
+ async def respond(self, context: list[dict], response_length: str = "medium") -> str:
12
+ max_tokens_map = {
13
+ "short": 200,
14
+ "medium": 300,
15
+ "long": 500
16
+ }
17
+
18
+ response_style_map = {
19
+ "short": "Please keep your response concise (1-3 sentences).",
20
+ "medium": "Please provide a moderately detailed explanation (5-7 sentences).",
21
+ "long": "Provide a thorough and in-depth explanation (9+ sentences)."
22
+ }
23
+
24
+ max_tokens = max_tokens_map.get(response_length, 300)
25
+ response_instruction = response_style_map.get(response_length, "medium")
26
+ temp_scaled = round(self.temperature / 10, 2)
27
+
28
+ full_prompt = f"{self.system_prompt}\n\n{response_instruction}"
29
+
30
+ return await self.llm.generate(
31
+ system_prompt=full_prompt,
32
+ context=context,
33
+ temperature=temp_scaled,
34
+ max_tokens=max_tokens
35
+ )
36