feat: add support for 'grok' provider in web search functionality

- Enhanced `isWebSearchModel` to recognize 'grok' as a valid web search model.
- Updated `getOpenAIWebSearchParams` to return specific search parameters for 'grok'.
- Modified `OpenAIProvider` to handle citations from 'grok' in web search results.
- Added 'grok' to the `WebSearchSource` enum for citation formatting.
This commit is contained in:
suyao 2025-05-22 22:51:22 +08:00 committed by 亢奋猫
parent 3ac414e97b
commit 1989f246fd
4 changed files with 29 additions and 1 deletions

View File

@ -2570,6 +2570,10 @@ export function isWebSearchModel(model: Model): boolean {
return true
}
if (provider.id === 'grok') {
return true
}
return false
}
@ -2600,6 +2604,16 @@ export function getOpenAIWebSearchParams(assistant: Assistant, model: Model): Re
if (assistant.enableWebSearch) {
const webSearchTools = getWebSearchTools(model)
if (model.provider === 'grok') {
return {
search_parameters: {
mode: 'auto',
return_citations: true,
sources: [{ type: 'web' }, { type: 'x' }, { type: 'news' }]
}
}
}
if (model.provider === 'hunyuan') {
return { enable_enhancement: true, citation: true, search_info: true }
}

View File

@ -777,6 +777,18 @@ export default class OpenAIProvider extends BaseOpenAIProvider {
}
} as LLMWebSearchCompleteChunk)
}
if (assistant.model?.provider === 'grok') {
const citations = originalFinishRawChunk.citations
if (citations) {
onChunk({
type: ChunkType.LLM_WEB_SEARCH_COMPLETE,
llm_web_search: {
results: citations,
source: WebSearchSource.GROK
}
} as LLMWebSearchCompleteChunk)
}
}
if (assistant.model?.provider === 'perplexity') {
const citations = originalFinishRawChunk.citations
if (citations) {

View File

@ -160,6 +160,7 @@ const formatCitationsFromBlock = (block: CitationMessageBlock | undefined): Cita
}
}) || []
break
case WebSearchSource.GROK:
case WebSearchSource.OPENROUTER:
case WebSearchSource.PERPLEXITY:
formattedCitations =

View File

@ -473,7 +473,8 @@ export enum WebSearchSource {
PERPLEXITY = 'perplexity',
QWEN = 'qwen',
HUNYUAN = 'hunyuan',
ZHIPU = 'zhipu'
ZHIPU = 'zhipu',
GROK = 'grok'
}
export type WebSearchResponse = {