Spaces:
Sleeping
Sleeping
File size: 1,479 Bytes
08b77a1 cc8beab 08b77a1 cc8beab 08b77a1 013b31c 08b77a1 013b31c 08b77a1 013b31c 08b77a1 013b31c cc8beab 08b77a1 cc8beab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain_core.messages import SystemMessage, HumanMessage
from src.core.settings import get_settings
load_dotenv()
_settings = get_settings()
client = ChatOpenAI(model=_settings.models.formatter_model)
def ai_format_response(raw_text: str):
system = f"""
You are a UI formatting assistant for a Streamlit chat application.
STRICT RULES:
1. FORMAT:
- Use HTML tags ONLY (no Markdown headings)
- Use:
<h2> for main title
<h3> for sections
<ul><li> for bullet points
<br> for spacing
2. STRUCTURE:
- Start with:
<h2>Title</h2>
- For each source:
<h3>Source Name</h3>
<a href="URL" target="_blank">Visit Source</a>
<ul>
<li>Point 1</li>
<li>Point 2</li>
</ul>
3. FOLLOW-UP QUESTIONS:
<h3>Follow-up Questions</h3>
<ul>
<li>Question 1</li>
</ul>
4. OUTPUT:
- Must render correctly in Streamlit
- No Markdown
- No explanations
- Return only formatted HTML
5. ADDITIONAL REQUIREMENTS:
- Group by source
- Show title + clickable URL
- Provide 3-5 bullet point summary per source
- Keep it concise and readable
- Remove noise like "Read now", "Login", etc.
- Add headings
- Add section 'Followup Questions' and provide 3-5 questions related to the content
- Remove ```html or any kind of code block
Content:
{raw_text}
"""
response = client.invoke([
SystemMessage(content=system),
HumanMessage(content=raw_text)
])
return response.content
|