a9 commited on
Commit
7af317a
·
verified ·
1 Parent(s): 6c02b49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -91,7 +91,20 @@ def call_gemini(history: List[types.Content]):
91
  except Exception as e:
92
  print(f"GenAI Error: {e}")
93
  raise HTTPException(status_code=500, detail="AI Generation Failed")
 
94
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  def getSystemPrompt():
97
  text = ''
@@ -128,7 +141,7 @@ async def handleNewConv(new_conv: NewConv, token: str = Depends(verify_access_to
128
  raw_history.append(["user", new_conv.prompt])
129
  raw_history.append(["model", text])
130
  convs[conv_id] = raw_history
131
- return {"title": new_conv.prompt, "text": text, "conv_id": conv_id}
132
 
133
 
134
  @app.post("/gen_resp")
 
91
  except Exception as e:
92
  print(f"GenAI Error: {e}")
93
  raise HTTPException(status_code=500, detail="AI Generation Failed")
94
+
95
 
96
+ def gen_title(user, model):
97
+ try:
98
+ response = client.models.generate_content(
99
+ model="gemma-3-1b-it",
100
+ contents= title_prompt(user, model)
101
+ )
102
+ return response.text
103
+ except Exception as e:
104
+ return user
105
+
106
+ def title_prompt(user, model):
107
+ return f'''---\n**System Role:**\n\n> You are a specialized utility model. Your sole task is to generate a concise, descriptive title (2–6 words) for a chat conversation based on the provided user query and model response.\n\n**Constraints:**\n\n* **Output only the title.** Do not include labels, quotes, full-stop or introductory text.\n* **Focus on the core intent** of the conversation.\n* **Avoid generic terms** like "Chat about..." or "Request for..."\n* **Style:** Professional, catchy, and informative.\n\n---\n\n**User Query:** {user}\n\n**Model Response:** {model}'''
108
 
109
  def getSystemPrompt():
110
  text = ''
 
141
  raw_history.append(["user", new_conv.prompt])
142
  raw_history.append(["model", text])
143
  convs[conv_id] = raw_history
144
+ return {"title": gen_title(new_conv.prompt,text), "text": text, "conv_id": conv_id}
145
 
146
 
147
  @app.post("/gen_resp")