Skip to content

Commit 9412c88

Browse files
authored
feat: enhance search query with advanced depth and refine result content parsing (#629)
Signed-off-by: Bob Du <i@bobdu.cc>
1 parent c7cde18 commit 9412c88

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

service/src/chatgpt/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ async function chatReplyProcess(options: RequestOptions) {
137137
const response = await tvly.search(
138138
searchQuery,
139139
{
140+
// https://docs.tavily.com/documentation/best-practices/best-practices-search#search-depth%3Dadvanced-ideal-for-higher-relevance-in-search-results
141+
searchDepth: 'advanced',
142+
chunksPerSource: 3,
140143
includeRawContent: true,
141144
// 0 <= x <= 20 https://docs.tavily.com/documentation/api-reference/endpoint/search#body-max-results
142-
maxResults: 20,
145+
// https://docs.tavily.com/documentation/best-practices/best-practices-search#max-results-limiting-the-number-of-results
146+
maxResults: 10,
143147
// Max 120s, default to 60 https://github.com/tavily-ai/tavily-js/blob/de69e479c5d3f6c5d443465fa2c29407c0d3515d/src/search.ts#L118
144148
timeout: 120,
145149
},
@@ -156,9 +160,9 @@ async function chatReplyProcess(options: RequestOptions) {
156160
})
157161

158162
let searchResultContent = JSON.stringify(searchResults)
159-
// remove base64 image content
160-
const base64Pattern = /data:image\/[a-zA-Z0-9+.-]+;base64,[A-Za-z0-9+/=]+/g
161-
searchResultContent = searchResultContent.replace(base64Pattern, '')
163+
// remove image url
164+
const base64Pattern = /!\[([^\]]*)\]\([^)]*\)/g
165+
searchResultContent = searchResultContent.replace(base64Pattern, '$1')
162166

163167
messages.push({
164168
role: 'user',

0 commit comments

Comments
 (0)