mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor(server): config system (#11081)
This commit is contained in:
@@ -45,10 +45,14 @@ import {
|
||||
UnsplashIsNotConfigured,
|
||||
} from '../../base';
|
||||
import { CurrentUser, Public } from '../../core/auth';
|
||||
import { CopilotProviderService } from './providers';
|
||||
import {
|
||||
CopilotCapability,
|
||||
CopilotProviderFactory,
|
||||
CopilotTextProvider,
|
||||
} from './providers';
|
||||
import { ChatSession, ChatSessionService } from './session';
|
||||
import { CopilotStorage } from './storage';
|
||||
import { ChatMessage, CopilotCapability, CopilotTextProvider } from './types';
|
||||
import { ChatMessage } from './types';
|
||||
import { CopilotWorkflowService, GraphExecutorState } from './workflow';
|
||||
|
||||
export interface ChatEvent {
|
||||
@@ -72,7 +76,7 @@ export class CopilotController implements BeforeApplicationShutdown {
|
||||
constructor(
|
||||
private readonly config: Config,
|
||||
private readonly chatSession: ChatSessionService,
|
||||
private readonly provider: CopilotProviderService,
|
||||
private readonly provider: CopilotProviderFactory,
|
||||
private readonly workflow: CopilotWorkflowService,
|
||||
private readonly storage: CopilotStorage
|
||||
) {}
|
||||
@@ -121,13 +125,13 @@ export class CopilotController implements BeforeApplicationShutdown {
|
||||
);
|
||||
let provider = await this.provider.getProviderByCapability(
|
||||
CopilotCapability.TextToText,
|
||||
model
|
||||
{ model }
|
||||
);
|
||||
// fallback to image to text if text to text is not available
|
||||
if (!provider && hasAttachment) {
|
||||
provider = await this.provider.getProviderByCapability(
|
||||
CopilotCapability.ImageToText,
|
||||
model
|
||||
{ model }
|
||||
);
|
||||
}
|
||||
if (!provider) {
|
||||
@@ -478,7 +482,7 @@ export class CopilotController implements BeforeApplicationShutdown {
|
||||
hasAttachment
|
||||
? CopilotCapability.ImageToImage
|
||||
: CopilotCapability.TextToImage,
|
||||
model
|
||||
{ model }
|
||||
);
|
||||
if (!provider) {
|
||||
throw new NoCopilotProviderAvailable();
|
||||
@@ -565,8 +569,8 @@ export class CopilotController implements BeforeApplicationShutdown {
|
||||
@Res() res: Response,
|
||||
@Query() params: Record<string, string>
|
||||
) {
|
||||
const { unsplashKey } = this.config.plugins.copilot || {};
|
||||
if (!unsplashKey) {
|
||||
const { key } = this.config.copilot.unsplash;
|
||||
if (!key) {
|
||||
throw new UnsplashIsNotConfigured();
|
||||
}
|
||||
|
||||
@@ -574,7 +578,7 @@ export class CopilotController implements BeforeApplicationShutdown {
|
||||
const response = await fetch(
|
||||
`https://api.unsplash.com/search/photos?${query}`,
|
||||
{
|
||||
headers: { Authorization: `Client-ID ${unsplashKey}` },
|
||||
headers: { Authorization: `Client-ID ${key}` },
|
||||
signal: this.getSignal(req),
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user