Skip to content

Commit 6c92caf

Browse files
authored
Merge pull request #37420 from github/repo-sync
Repo sync
2 parents d250706 + cca9899 commit 6c92caf

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

Diff for: src/search/components/input/AskAIResults.tsx

+15-9
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function AskAIResults({
7676

7777
const [conversationId, setConversationId] = useState<string>('')
7878

79-
const handleAICannotAnswer = () => {
79+
const handleAICannotAnswer = (passedConversationId?: string) => {
8080
setInitialLoading(false)
8181
setResponseLoading(false)
8282
setAICouldNotAnswer(true)
@@ -87,6 +87,7 @@ export function AskAIResults({
8787
eventGroupId: askAIEventGroupId.current,
8888
couldNotAnswer: true,
8989
status: 400,
90+
connectedEventId: passedConversationId || conversationId,
9091
})
9192
setMessage(cannedResponse)
9293
setAnnouncement(cannedResponse)
@@ -98,6 +99,7 @@ export function AskAIResults({
9899
message: cannedResponse,
99100
sources: [],
100101
aiCouldNotAnswer: true,
102+
connectedEventId: passedConversationId || conversationId,
101103
},
102104
version,
103105
router.locale || 'en',
@@ -123,6 +125,7 @@ export function AskAIResults({
123125
if (cachedData) {
124126
setMessage(cachedData.message)
125127
setReferences(cachedData.sources)
128+
setConversationId(cachedData.connectedEventId || '')
126129
setAICouldNotAnswer(cachedData.aiCouldNotAnswer || false)
127130
setInitialLoading(false)
128131
setResponseLoading(false)
@@ -150,10 +153,6 @@ export function AskAIResults({
150153

151154
try {
152155
const response = await executeAISearch(router, version, query, debug)
153-
// Serve canned response. A question that cannot be answered was asked
154-
if (response.status === 400) {
155-
return handleAICannotAnswer()
156-
}
157156
if (!response.ok) {
158157
console.error(
159158
`Failed to fetch search results.\nStatus ${response.status}\n${response.statusText}`,
@@ -219,7 +218,14 @@ export function AskAIResults({
219218
continue
220219
}
221220

222-
if (parsedLine.chunkType === 'SOURCES') {
221+
// A conversation ID will still be sent when a question cannot be answered
222+
if (parsedLine.chunkType === 'CONVERSATION_ID') {
223+
conversationIdBuffer = parsedLine.conversation_id
224+
setConversationId(parsedLine.conversation_id)
225+
} else if (parsedLine.chunkType === 'NO_CONTENT_SIGNAL') {
226+
// Serve canned response. A question that cannot be answered was asked
227+
handleAICannotAnswer(conversationIdBuffer)
228+
} else if (parsedLine.chunkType === 'SOURCES') {
223229
if (!isCancelled) {
224230
sourcesBuffer = sourcesBuffer.concat(parsedLine.sources)
225231
sourcesBuffer = uniqBy(sourcesBuffer, 'url')
@@ -230,9 +236,9 @@ export function AskAIResults({
230236
messageBuffer += parsedLine.text
231237
setMessage(messageBuffer)
232238
}
233-
} else if (parsedLine.chunkType === 'CONVERSATION_ID') {
234-
conversationIdBuffer = parsedLine.conversation_id
235-
setConversationId(parsedLine.conversation_id)
239+
} else if (parsedLine.chunkType === 'INPUT_CONTENT_FILTER') {
240+
// Serve canned response. A spam question was asked
241+
handleAICannotAnswer(conversationIdBuffer)
236242
}
237243
if (!isCancelled) {
238244
setAnnouncement('Copilot Response Loading...')

Diff for: src/search/lib/ai-search-proxy.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,7 @@ export const aiSearchProxy = async (req: Request, res: Response) => {
8080

8181
// Handle the upstream response before piping
8282
stream.on('response', (upstreamResponse) => {
83-
// When cse-copilot returns a 204, it means the backend received the request
84-
// but was unable to answer the question. So we return a 400 to the client to be handled.
85-
if (upstreamResponse.statusCode === 204) {
86-
statsd.increment('ai-search.unable_to_answer_query', 1, diagnosticTags)
87-
return res
88-
.status(400)
89-
.json({ errors: [{ message: 'Sorry I am unable to answer this question.' }] })
90-
} else if (upstreamResponse.statusCode !== 200) {
83+
if (upstreamResponse.statusCode !== 200) {
9184
const errorMessage = `Upstream server responded with status code ${upstreamResponse.statusCode}`
9285
console.error(errorMessage)
9386
statsd.increment('ai-search.stream_response_error', 1, diagnosticTags)

0 commit comments

Comments
 (0)