mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 19:46:32 +08:00
refactor(core): use the websearch parameters passed in by the front-end (#11989)
Support [AI-60](https://linear.app/affine-design/issue/AI-60). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated naming conventions for the web search tool to ensure consistency across AI chat features. - Simplified internal handling of web search tool options for a more streamlined experience. - Unified parameter naming from "mustSearch" to "webSearch" across AI chat inputs and actions. - **Chores** - Removed unused configuration options related to web search from prompt settings. - Added support for enabling or disabling web search via new parameters in chat requests. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -178,8 +178,8 @@ export class OpenAIProvider
|
||||
}
|
||||
}
|
||||
|
||||
private getToolUse(options: CopilotChatOptions = {}) {
|
||||
if (options.webSearch) {
|
||||
private getTools(options: CopilotChatOptions) {
|
||||
if (options?.webSearch) {
|
||||
return {
|
||||
web_search_preview: openai.tools.webSearchPreview(),
|
||||
};
|
||||
@@ -224,6 +224,7 @@ export class OpenAIProvider
|
||||
providerOptions: {
|
||||
openai: options.user ? { user: options.user } : {},
|
||||
},
|
||||
tools: this.getTools(options),
|
||||
});
|
||||
|
||||
return text.trim();
|
||||
@@ -245,18 +246,16 @@ export class OpenAIProvider
|
||||
|
||||
const [system, msgs] = await chatToGPTMessage(messages);
|
||||
|
||||
const modelInstance = options.webSearch
|
||||
? this.#instance.responses(model)
|
||||
: this.#instance(model, {
|
||||
structuredOutputs: Boolean(options.jsonMode),
|
||||
user: options.user,
|
||||
});
|
||||
const modelInstance = this.#instance(model, {
|
||||
structuredOutputs: Boolean(options.jsonMode),
|
||||
user: options.user,
|
||||
});
|
||||
|
||||
const { fullStream } = streamText({
|
||||
model: modelInstance,
|
||||
system,
|
||||
messages: msgs,
|
||||
tools: this.getToolUse(options),
|
||||
tools: this.getTools(options),
|
||||
frequencyPenalty: options.frequencyPenalty || 0,
|
||||
presencePenalty: options.presencePenalty || 0,
|
||||
temperature: options.temperature || 0,
|
||||
|
||||
Reference in New Issue
Block a user