mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 23:10:20 +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
4af62c4345
commit
cf26ffd47a
@ -2570,6 +2570,10 @@ export function isWebSearchModel(model: Model): boolean {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (provider.id === 'grok') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2600,6 +2604,16 @@ export function getOpenAIWebSearchParams(assistant: Assistant, model: Model): Re
|
|||||||
if (assistant.enableWebSearch) {
|
if (assistant.enableWebSearch) {
|
||||||
const webSearchTools = getWebSearchTools(model)
|
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') {
|
if (model.provider === 'hunyuan') {
|
||||||
return { enable_enhancement: true, citation: true, search_info: true }
|
return { enable_enhancement: true, citation: true, search_info: true }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -777,6 +777,18 @@ export default class OpenAIProvider extends BaseOpenAIProvider {
|
|||||||
}
|
}
|
||||||
} as LLMWebSearchCompleteChunk)
|
} 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') {
|
if (assistant.model?.provider === 'perplexity') {
|
||||||
const citations = originalFinishRawChunk.citations
|
const citations = originalFinishRawChunk.citations
|
||||||
if (citations) {
|
if (citations) {
|
||||||
|
|||||||
@ -160,6 +160,7 @@ const formatCitationsFromBlock = (block: CitationMessageBlock | undefined): Cita
|
|||||||
}
|
}
|
||||||
}) || []
|
}) || []
|
||||||
break
|
break
|
||||||
|
case WebSearchSource.GROK:
|
||||||
case WebSearchSource.OPENROUTER:
|
case WebSearchSource.OPENROUTER:
|
||||||
case WebSearchSource.PERPLEXITY:
|
case WebSearchSource.PERPLEXITY:
|
||||||
formattedCitations =
|
formattedCitations =
|
||||||
|
|||||||
@ -473,7 +473,8 @@ export enum WebSearchSource {
|
|||||||
PERPLEXITY = 'perplexity',
|
PERPLEXITY = 'perplexity',
|
||||||
QWEN = 'qwen',
|
QWEN = 'qwen',
|
||||||
HUNYUAN = 'hunyuan',
|
HUNYUAN = 'hunyuan',
|
||||||
ZHIPU = 'zhipu'
|
ZHIPU = 'zhipu',
|
||||||
|
GROK = 'grok'
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WebSearchResponse = {
|
export type WebSearchResponse = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user