mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(core): add web search tool and reasoning params (#11912)
Close [AI-60](https://linear.app/affine-design/issue/AI-60). ### What changed? - Add Exa web search tool - Add reasoning params
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,
|
||||
networkSearch: visible?.value && enabled?.value,
|
||||
mustSearch: visible?.value && enabled?.value,
|
||||
} as Parameters<typeof action>[0];
|
||||
// @ts-expect-error TODO(@Peng): maybe fix this
|
||||
stream = await action(options);
|
||||
|
||||
@@ -196,7 +196,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
host,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
networkSearch: visible?.value && enabled?.value,
|
||||
mustSearch: 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;
|
||||
networkSearch?: boolean;
|
||||
mustSearch?: boolean;
|
||||
contexts?: {
|
||||
docs: AIDocContextOption[];
|
||||
files: AIFileContextOption[];
|
||||
|
||||
@@ -544,7 +544,7 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
|
||||
isRootSession: this.isRootSession,
|
||||
where: this.trackOptions.where,
|
||||
control: this.trackOptions.control,
|
||||
networkSearch: this._isNetworkActive,
|
||||
mustSearch: this._isNetworkActive,
|
||||
});
|
||||
|
||||
for await (const text of stream) {
|
||||
|
||||
@@ -82,28 +82,22 @@ export function setupAIProvider(
|
||||
|
||||
//#region actions
|
||||
AIProvider.provide('chat', async options => {
|
||||
const { input, contexts, attachments, networkSearch, retry } = options;
|
||||
const disableSearch =
|
||||
!!contexts?.files.length ||
|
||||
!!contexts?.docs.length ||
|
||||
!!attachments?.length;
|
||||
const promptName =
|
||||
networkSearch && !disableSearch
|
||||
? 'Search With AFFiNE AI'
|
||||
: 'Chat With AFFiNE AI';
|
||||
const { input, contexts, mustSearch } = options;
|
||||
|
||||
const sessionId = await createSession({
|
||||
promptName,
|
||||
promptName: 'Chat With AFFiNE AI',
|
||||
...options,
|
||||
});
|
||||
if (!retry) {
|
||||
await AIProvider.session?.updateSession(sessionId, promptName);
|
||||
}
|
||||
return textToText({
|
||||
...options,
|
||||
client,
|
||||
sessionId,
|
||||
content: input,
|
||||
params: contexts,
|
||||
params: {
|
||||
docs: contexts?.docs,
|
||||
files: contexts?.files,
|
||||
searchMode: mustSearch ? 'MUST' : 'CAN',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
type Signal,
|
||||
} from '@blocksuite/affine/shared/utils';
|
||||
import { LiveData, Service } from '@toeverything/infra';
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import type { FeatureFlagService } from '../../feature-flag';
|
||||
import type { GlobalStateService } from '../../storage';
|
||||
@@ -42,9 +41,7 @@ export class AINetworkSearchService extends Service {
|
||||
this.featureFlagService.flags.enable_ai_network_search.$;
|
||||
|
||||
private readonly _enabled$ = LiveData.from(
|
||||
this.globalStateService.globalState
|
||||
.watch<boolean>(AI_NETWORK_SEARCH_KEY)
|
||||
.pipe(map(v => (v === undefined ? true : v))),
|
||||
this.globalStateService.globalState.watch<boolean>(AI_NETWORK_SEARCH_KEY),
|
||||
undefined
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user