Files
AFFiNE/packages/backend/server/src/plugins/copilot/config.ts
T
DarkSky 5cbcf6f907 feat(server): add fallback model and baseurl in schema (#13375)
fix AI-398

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added support for specifying fallback models for multiple AI
providers, enhancing reliability when primary models are unavailable.
* Providers can now fetch and update their list of available models
dynamically from external APIs.
* Configuration options expanded to allow custom base URLs for certain
providers.

* **Bug Fixes**
* Improved model selection logic to use fallback models if the requested
model is not available online.

* **Chores**
* Updated backend dependencies to include authentication support for
Google services.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-08-01 07:22:48 +00:00

148 lines
3.3 KiB
TypeScript

import {
defineModuleConfig,
StorageJSONSchema,
StorageProviderConfig,
} from '../../base';
import {
AnthropicOfficialConfig,
AnthropicVertexConfig,
} from './providers/anthropic';
import type { FalConfig } from './providers/fal';
import { GeminiGenerativeConfig, GeminiVertexConfig } from './providers/gemini';
import { MorphConfig } from './providers/morph';
import { OpenAIConfig } from './providers/openai';
import { PerplexityConfig } from './providers/perplexity';
import { VertexSchema } from './providers/types';
declare global {
interface AppConfigSchema {
copilot: {
enabled: boolean;
unsplash: ConfigItem<{
key: string;
}>;
exa: ConfigItem<{
key: string;
}>;
storage: ConfigItem<StorageProviderConfig>;
providers: {
openai: ConfigItem<OpenAIConfig>;
fal: ConfigItem<FalConfig>;
gemini: ConfigItem<GeminiGenerativeConfig>;
geminiVertex: ConfigItem<GeminiVertexConfig>;
perplexity: ConfigItem<PerplexityConfig>;
anthropic: ConfigItem<AnthropicOfficialConfig>;
anthropicVertex: ConfigItem<AnthropicVertexConfig>;
morph: ConfigItem<MorphConfig>;
};
};
}
}
defineModuleConfig('copilot', {
enabled: {
desc: 'Whether to enable the copilot plugin.',
default: false,
},
'providers.openai': {
desc: 'The config for the openai provider.',
default: {
apiKey: '',
baseUrl: '',
fallback: {
text: '',
structured: '',
image: '',
embedding: '',
},
},
link: 'https://github.com/openai/openai-node',
},
'providers.fal': {
desc: 'The config for the fal provider.',
default: {
apiKey: '',
},
},
'providers.gemini': {
desc: 'The config for the gemini provider.',
default: {
apiKey: '',
baseUrl: '',
fallback: {
text: '',
structured: '',
image: '',
embedding: '',
},
},
},
'providers.geminiVertex': {
desc: 'The config for the gemini provider in Google Vertex AI.',
default: {
baseURL: '',
fallback: {
text: '',
structured: '',
image: '',
embedding: '',
},
},
schema: VertexSchema,
},
'providers.perplexity': {
desc: 'The config for the perplexity provider.',
default: {
apiKey: '',
fallback: {
text: '',
},
},
},
'providers.anthropic': {
desc: 'The config for the anthropic provider.',
default: {
apiKey: '',
fallback: {
text: '',
},
},
},
'providers.anthropicVertex': {
desc: 'The config for the anthropic provider in Google Vertex AI.',
default: {
baseURL: '',
fallback: {
text: '',
},
},
schema: VertexSchema,
},
'providers.morph': {
desc: 'The config for the morph provider.',
default: {},
},
unsplash: {
desc: 'The config for the unsplash key.',
default: {
key: '',
},
},
exa: {
desc: 'The config for the exa web search key.',
default: {
key: '',
},
},
storage: {
desc: 'The config for the storage provider.',
default: {
provider: 'fs',
bucket: 'copilot',
config: {
path: '~/.affine/storage',
},
},
schema: StorageJSONSchema,
},
});