Spaces:
Running
Running
NeonClary commited on
Commit ·
4fd9d4c
1
Parent(s): bcdbb51
Improve freeform role generation prompt and expose finish_reason
Browse files
backend/app/clients/openai_compat.py
CHANGED
|
@@ -74,13 +74,16 @@ async def openai_chat_completion(
|
|
| 74 |
data = resp.json()
|
| 75 |
choices = data.get("choices", [])
|
| 76 |
text = ""
|
|
|
|
| 77 |
if choices:
|
| 78 |
msg = choices[0].get("message") or {}
|
| 79 |
text = msg.get("content") or ""
|
|
|
|
| 80 |
return {
|
| 81 |
"response": text.strip(),
|
| 82 |
"elapsed_seconds": round(elapsed, 2),
|
| 83 |
"model": data.get("model", model),
|
|
|
|
| 84 |
}
|
| 85 |
except httpx.HTTPStatusError as exc:
|
| 86 |
if attempt == 0:
|
|
|
|
| 74 |
data = resp.json()
|
| 75 |
choices = data.get("choices", [])
|
| 76 |
text = ""
|
| 77 |
+
finish_reason = ""
|
| 78 |
if choices:
|
| 79 |
msg = choices[0].get("message") or {}
|
| 80 |
text = msg.get("content") or ""
|
| 81 |
+
finish_reason = choices[0].get("finish_reason") or ""
|
| 82 |
return {
|
| 83 |
"response": text.strip(),
|
| 84 |
"elapsed_seconds": round(elapsed, 2),
|
| 85 |
"model": data.get("model", model),
|
| 86 |
+
"finish_reason": finish_reason,
|
| 87 |
}
|
| 88 |
except httpx.HTTPStatusError as exc:
|
| 89 |
if attempt == 0:
|
backend/app/services/persona.py
CHANGED
|
@@ -21,12 +21,16 @@ ROLE_GENERATION_PROMPT = (
|
|
| 21 |
)
|
| 22 |
|
| 23 |
FREEFORM_ROLE_GENERATION_PROMPT = (
|
| 24 |
-
"
|
| 25 |
-
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
"
|
| 29 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
"The persona's name is: {name}\n\n"
|
| 31 |
"Here is everything provided about this persona:\n"
|
| 32 |
"---\n{text}\n---"
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
FREEFORM_ROLE_GENERATION_PROMPT = (
|
| 24 |
+
"You will receive freeform information about a character or persona. The input may be "
|
| 25 |
+
"detailed (with writing samples, background, etc.) or very brief (just a name or a short "
|
| 26 |
+
"description). Regardless of how much is provided, write a complete, vivid 3-5 sentence "
|
| 27 |
+
"role prompt that an LLM can use to convincingly embody this persona in a conversation.\n\n"
|
| 28 |
+
"If the input is sparse, infer plausible personality traits, speech patterns, interests, "
|
| 29 |
+
"and conversational style from whatever clues are available (the name, any title or "
|
| 30 |
+
"occupation, context, etc.). Fill in realistic detail so the role prompt is rich and "
|
| 31 |
+
"actionable — never produce a vague or skeletal prompt.\n\n"
|
| 32 |
+
"Cover: personality, tone and speech patterns, background/expertise, interests and "
|
| 33 |
+
"motivations, and how they would naturally interact in a casual conversation.\n\n"
|
| 34 |
"The persona's name is: {name}\n\n"
|
| 35 |
"Here is everything provided about this persona:\n"
|
| 36 |
"---\n{text}\n---"
|