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:
akumatus
2025-04-28 07:49:54 +00:00
committed by Yue Wu
parent e366f69707
commit cf5574caf6
12 changed files with 51 additions and 32 deletions
@@ -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,