mirror of
https://github.com/fsolla/teqo.git
synced 2026-12-03 05:43:04 +00:00
style(B192): format (prettier)
This commit is contained in:
parent
382c4c46ec
commit
2fa38a08f5
4 changed files with 23 additions and 20 deletions
|
|
@ -9,11 +9,11 @@ import {
|
||||||
} from 'ai'
|
} from 'ai'
|
||||||
import { getPayload } from 'payload'
|
import { getPayload } from 'payload'
|
||||||
|
|
||||||
|
import { splitSollinhaFollowUpBlock } from '@/lib/sollinhaFollowUpSuggestions'
|
||||||
import { checkRateLimit } from '@/utilities/ai/rateLimit'
|
import { checkRateLimit } from '@/utilities/ai/rateLimit'
|
||||||
import { AI_SYSTEM_PROMPT } from '@/utilities/ai/systemPrompt'
|
import { AI_SYSTEM_PROMPT } from '@/utilities/ai/systemPrompt'
|
||||||
import { buildAITools } from '@/utilities/ai/tools'
|
import { buildAITools } from '@/utilities/ai/tools'
|
||||||
import { getCampaignUserRaw } from '@/utilities/campaignAuth'
|
import { getCampaignUserRaw } from '@/utilities/campaignAuth'
|
||||||
import { splitSollinhaFollowUpBlock } from '@/lib/sollinhaFollowUpSuggestions'
|
|
||||||
|
|
||||||
export const maxDuration = 60
|
export const maxDuration = 60
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ import { cn } from '@/lib/utils'
|
||||||
import { useAISidebar } from '@/components/campaign/shell/ai/CampaignAISidebarContext'
|
import { useAISidebar } from '@/components/campaign/shell/ai/CampaignAISidebarContext'
|
||||||
import { ChatChipGroup } from '@/components/campaign/shell/ai/ChatChipGroup'
|
import { ChatChipGroup } from '@/components/campaign/shell/ai/ChatChipGroup'
|
||||||
import { useMicTranscript } from '@/components/campaign/shell/ai/useMicTranscript'
|
import { useMicTranscript } from '@/components/campaign/shell/ai/useMicTranscript'
|
||||||
import { getSollinhaOpeningQuestions } from '@/lib/sollinhaOpeningQuestions'
|
|
||||||
import { splitSollinhaFollowUpBlock } from '@/lib/sollinhaFollowUpSuggestions'
|
import { splitSollinhaFollowUpBlock } from '@/lib/sollinhaFollowUpSuggestions'
|
||||||
|
import { getSollinhaOpeningQuestions } from '@/lib/sollinhaOpeningQuestions'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* B187+B188 — links in the assistant's markdown must look like links: brand
|
* B187+B188 — links in the assistant's markdown must look like links: brand
|
||||||
|
|
@ -221,9 +221,7 @@ export const CampaignAIChat = ({ className }: { className?: string }) => {
|
||||||
{(showOpeningChips || showFollowUpChips) && (
|
{(showOpeningChips || showFollowUpChips) && (
|
||||||
<ChatChipGroup
|
<ChatChipGroup
|
||||||
questions={
|
questions={
|
||||||
showOpeningChips
|
showOpeningChips ? openingQuestions : followUpSuggestions.map((text) => ({ text }))
|
||||||
? openingQuestions
|
|
||||||
: followUpSuggestions.map((text) => ({ text }))
|
|
||||||
}
|
}
|
||||||
onPick={({ text }) => {
|
onPick={({ text }) => {
|
||||||
if (busy) return
|
if (busy) return
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,11 @@ const THIRD_RESPONSE = `Os dados de 2026 ainda não existem.`
|
||||||
|
|
||||||
const lastUserText = (body: unknown): string | null => {
|
const lastUserText = (body: unknown): string | null => {
|
||||||
const messages =
|
const messages =
|
||||||
(body as { messages?: Array<{ role?: string; parts?: Array<{ type?: string; text?: string }> }> })
|
(
|
||||||
?.messages ?? []
|
body as {
|
||||||
|
messages?: Array<{ role?: string; parts?: Array<{ type?: string; text?: string }> }>
|
||||||
|
}
|
||||||
|
)?.messages ?? []
|
||||||
for (const message of [...messages].reverse()) {
|
for (const message of [...messages].reverse()) {
|
||||||
if (message.role !== 'user') continue
|
if (message.role !== 'user') continue
|
||||||
for (const part of message.parts ?? []) {
|
for (const part of message.parts ?? []) {
|
||||||
|
|
@ -42,10 +45,11 @@ const mockAiChat = (page: Page) =>
|
||||||
page.route('**/campanha/api/ai-chat', async (route) => {
|
page.route('**/campanha/api/ai-chat', async (route) => {
|
||||||
const raw = route.request().postData() ?? ''
|
const raw = route.request().postData() ?? ''
|
||||||
const userText = lastUserText(JSON.parse(raw || '{}'))
|
const userText = lastUserText(JSON.parse(raw || '{}'))
|
||||||
const response =
|
const response = userText?.includes('Ilhéus')
|
||||||
userText?.includes('Ilhéus') ? FIRST_RESPONSE
|
? FIRST_RESPONSE
|
||||||
: userText?.includes('Salvador em 2022?') ? SECOND_RESPONSE
|
: userText?.includes('Salvador em 2022?')
|
||||||
: THIRD_RESPONSE
|
? SECOND_RESPONSE
|
||||||
|
: THIRD_RESPONSE
|
||||||
await route.fulfill({
|
await route.fulfill({
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: { 'Content-Type': 'text/event-stream' },
|
headers: { 'Content-Type': 'text/event-stream' },
|
||||||
|
|
@ -157,16 +161,18 @@ test.describe('B192 — follow-ups sugeridos após cada resposta do Sollinha', (
|
||||||
await page.getByRole('button', { name: 'Sollinha — Assistente virtual' }).click()
|
await page.getByRole('button', { name: 'Sollinha — Assistente virtual' }).click()
|
||||||
await expect(drawer).toBeVisible({ timeout: 20_000 })
|
await expect(drawer).toBeVisible({ timeout: 20_000 })
|
||||||
|
|
||||||
await askViaInput(page, 'Quantos votos tivemos em Ilhéus em 2022?', 'Em 2022, o Solla teve 12.345 votos em Ilhéus.')
|
await askViaInput(
|
||||||
|
page,
|
||||||
|
'Quantos votos tivemos em Ilhéus em 2022?',
|
||||||
|
'Em 2022, o Solla teve 12.345 votos em Ilhéus.',
|
||||||
|
)
|
||||||
await expect(page.getByText('Em 2022, o Solla teve 12.345 votos em Ilhéus.')).toBeVisible({
|
await expect(page.getByText('Em 2022, o Solla teve 12.345 votos em Ilhéus.')).toBeVisible({
|
||||||
timeout: 20_000,
|
timeout: 20_000,
|
||||||
})
|
})
|
||||||
|
|
||||||
await expect(chipButton(page, 'Quantos votos tivemos em Salvador em 2022?')).toBeVisible()
|
await expect(chipButton(page, 'Quantos votos tivemos em Salvador em 2022?')).toBeVisible()
|
||||||
await expect(chipButton(page, 'Quem foi o deputado mais votado em Barreiras?')).toBeVisible()
|
await expect(chipButton(page, 'Quem foi o deputado mais votado em Barreiras?')).toBeVisible()
|
||||||
await expect(
|
await expect(chipButton(page, 'Como está o município de Vitória da Conquista?')).toHaveCount(0)
|
||||||
chipButton(page, 'Como está o município de Vitória da Conquista?'),
|
|
||||||
).toHaveCount(0)
|
|
||||||
await expect(page.getByText('Sugestões de continuação')).toHaveCount(0)
|
await expect(page.getByText('Sugestões de continuação')).toHaveCount(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,10 +74,7 @@ describe('splitSollinhaFollowUpBlock', () => {
|
||||||
|
|
||||||
it('deduplicates repeated items', () => {
|
it('deduplicates repeated items', () => {
|
||||||
const text = `Resposta.\n\n${marker}\n- Mesma pergunta?\n- Mesma pergunta?\n- Outra?`
|
const text = `Resposta.\n\n${marker}\n- Mesma pergunta?\n- Mesma pergunta?\n- Outra?`
|
||||||
expect(splitSollinhaFollowUpBlock(text).suggestions).toEqual([
|
expect(splitSollinhaFollowUpBlock(text).suggestions).toEqual(['Mesma pergunta?', 'Outra?'])
|
||||||
'Mesma pergunta?',
|
|
||||||
'Outra?',
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('handles CRLF line endings', () => {
|
it('handles CRLF line endings', () => {
|
||||||
|
|
@ -93,7 +90,9 @@ describe('splitSollinhaFollowUpBlock', () => {
|
||||||
it('uses the LAST occurrence of the marker when the model repeats it', () => {
|
it('uses the LAST occurrence of the marker when the model repeats it', () => {
|
||||||
const text = `Resposta.\n\n${marker}\n- Antigas?\n- Também antigas?\n\nMais corpo.\n\n${marker}\n- Novas?\n- Atuais?`
|
const text = `Resposta.\n\n${marker}\n- Antigas?\n- Também antigas?\n\nMais corpo.\n\n${marker}\n- Novas?\n- Atuais?`
|
||||||
const { body, suggestions } = splitSollinhaFollowUpBlock(text)
|
const { body, suggestions } = splitSollinhaFollowUpBlock(text)
|
||||||
expect(body).toBe('Resposta.\n\n**Sugestões de continuação:**\n- Antigas?\n- Também antigas?\n\nMais corpo.')
|
expect(body).toBe(
|
||||||
|
'Resposta.\n\n**Sugestões de continuação:**\n- Antigas?\n- Também antigas?\n\nMais corpo.',
|
||||||
|
)
|
||||||
expect(suggestions).toEqual(['Novas?', 'Atuais?'])
|
expect(suggestions).toEqual(['Novas?', 'Atuais?'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue