mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-04 11:49:02 +08:00
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:
parent
3ac414e97b
commit
1989f246fd
@ -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 }
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -160,6 +160,7 @@ const formatCitationsFromBlock = (block: CitationMessageBlock | undefined): Cita
|
||||
}
|
||||
}) || []
|
||||
break
|
||||
case WebSearchSource.GROK:
|
||||
case WebSearchSource.OPENROUTER:
|
||||
case WebSearchSource.PERPLEXITY:
|
||||
formattedCitations =
|
||||
|
||||
@ -473,7 +473,8 @@ export enum WebSearchSource {
|
||||
PERPLEXITY = 'perplexity',
|
||||
QWEN = 'qwen',
|
||||
HUNYUAN = 'hunyuan',
|
||||
ZHIPU = 'zhipu'
|
||||
ZHIPU = 'zhipu',
|
||||
GROK = 'grok'
|
||||
}
|
||||
|
||||
export type WebSearchResponse = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user