mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00: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:
@@ -109,7 +109,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
where,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
mustSearch: visible?.value && enabled?.value,
|
||||
webSearch: visible?.value && enabled?.value,
|
||||
} as Parameters<typeof action>[0];
|
||||
// @ts-expect-error TODO(@Peng): maybe fix this
|
||||
stream = await action(options);
|
||||
|
||||
@@ -199,7 +199,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
host,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
mustSearch: visible?.value && enabled?.value,
|
||||
webSearch: visible?.value && enabled?.value,
|
||||
} as Parameters<typeof action>[0];
|
||||
|
||||
const content = ctx.get().content;
|
||||
|
||||
@@ -133,7 +133,7 @@ declare global {
|
||||
interface ChatOptions extends AITextActionOptions {
|
||||
sessionId?: string;
|
||||
isRootSession?: boolean;
|
||||
mustSearch?: boolean;
|
||||
webSearch?: boolean;
|
||||
reasoning?: boolean;
|
||||
contexts?: {
|
||||
docs: AIDocContextOption[];
|
||||
|
||||
@@ -560,7 +560,7 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
|
||||
isRootSession: this.isRootSession,
|
||||
where: this.trackOptions.where,
|
||||
control: this.trackOptions.control,
|
||||
mustSearch: this._isNetworkActive,
|
||||
webSearch: this._isNetworkActive,
|
||||
reasoning: this._isReasoningActive,
|
||||
});
|
||||
|
||||
|
||||
@@ -351,17 +351,20 @@ export class CopilotClient {
|
||||
sessionId,
|
||||
messageId,
|
||||
reasoning,
|
||||
webSearch,
|
||||
signal,
|
||||
}: {
|
||||
sessionId: string;
|
||||
messageId?: string;
|
||||
reasoning?: boolean;
|
||||
webSearch?: boolean;
|
||||
signal?: AbortSignal;
|
||||
}) {
|
||||
let url = `/api/copilot/chat/${sessionId}`;
|
||||
const queryString = this.paramsToQueryString({
|
||||
messageId,
|
||||
reasoning,
|
||||
webSearch,
|
||||
});
|
||||
if (queryString) {
|
||||
url += `?${queryString}`;
|
||||
@@ -376,10 +379,12 @@ export class CopilotClient {
|
||||
sessionId,
|
||||
messageId,
|
||||
reasoning,
|
||||
webSearch,
|
||||
}: {
|
||||
sessionId: string;
|
||||
messageId?: string;
|
||||
reasoning?: boolean;
|
||||
webSearch?: boolean;
|
||||
},
|
||||
endpoint = 'stream'
|
||||
) {
|
||||
@@ -387,6 +392,7 @@ export class CopilotClient {
|
||||
const queryString = this.paramsToQueryString({
|
||||
messageId,
|
||||
reasoning,
|
||||
webSearch,
|
||||
});
|
||||
if (queryString) {
|
||||
url += `?${queryString}`;
|
||||
|
||||
@@ -20,6 +20,7 @@ export type TextToTextOptions = {
|
||||
isRootSession?: boolean;
|
||||
postfix?: (text: string) => string;
|
||||
reasoning?: boolean;
|
||||
webSearch?: boolean;
|
||||
};
|
||||
|
||||
export type ToImageOptions = TextToTextOptions & {
|
||||
@@ -115,6 +116,7 @@ export function textToText({
|
||||
workflow = false,
|
||||
postfix,
|
||||
reasoning,
|
||||
webSearch,
|
||||
}: TextToTextOptions) {
|
||||
let messageId: string | undefined;
|
||||
|
||||
@@ -135,6 +137,7 @@ export function textToText({
|
||||
sessionId,
|
||||
messageId,
|
||||
reasoning,
|
||||
webSearch,
|
||||
},
|
||||
workflow ? 'workflow' : undefined
|
||||
);
|
||||
@@ -195,6 +198,7 @@ export function textToText({
|
||||
sessionId,
|
||||
messageId,
|
||||
reasoning,
|
||||
webSearch,
|
||||
});
|
||||
})(),
|
||||
]);
|
||||
|
||||
@@ -82,7 +82,7 @@ export function setupAIProvider(
|
||||
|
||||
//#region actions
|
||||
AIProvider.provide('chat', async options => {
|
||||
const { input, contexts, mustSearch } = options;
|
||||
const { input, contexts, webSearch } = options;
|
||||
|
||||
const sessionId = await createSession({
|
||||
promptName: 'Chat With AFFiNE AI',
|
||||
@@ -96,7 +96,7 @@ export function setupAIProvider(
|
||||
params: {
|
||||
docs: contexts?.docs,
|
||||
files: contexts?.files,
|
||||
searchMode: mustSearch ? 'MUST' : 'CAN',
|
||||
searchMode: webSearch ? 'MUST' : 'CAN',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user