mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 22:52:08 +08:00
- Added provider API host formatting utilities to handle differences between Cherry Studio and AI SDK. - Introduced functions for formatting provider API hosts, including support for Azure OpenAI and Vertex AI. - Created a simple API key rotator for managing API key rotation. - Developed shared provider initialization and mapping utilities for resolving provider IDs. - Implemented AI SDK configuration utilities for converting Cherry Studio providers to AI SDK configurations. - Added support for various providers including OpenRouter, Google Vertex AI, and Amazon Bedrock. - Enhanced error handling and logging in the unified messages service for better debugging. - Introduced functions for streaming and generating unified messages using AI SDK.
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
/**
|
|
* NewAPI规则集
|
|
*/
|
|
import type { MinimalModel, MinimalProvider, ProviderType } from '../types'
|
|
import { endpointIs, provider2Provider } from './helper'
|
|
import type { RuleSet } from './types'
|
|
|
|
const NEWAPI_RULES: RuleSet = {
|
|
rules: [
|
|
{
|
|
match: endpointIs('anthropic'),
|
|
provider: (provider) => {
|
|
return {
|
|
...provider,
|
|
type: 'anthropic' as ProviderType
|
|
}
|
|
}
|
|
},
|
|
{
|
|
match: endpointIs('gemini'),
|
|
provider: (provider) => {
|
|
return {
|
|
...provider,
|
|
type: 'gemini' as ProviderType
|
|
}
|
|
}
|
|
},
|
|
{
|
|
match: endpointIs('openai-response'),
|
|
provider: (provider) => {
|
|
return {
|
|
...provider,
|
|
type: 'openai-response' as ProviderType
|
|
}
|
|
}
|
|
},
|
|
{
|
|
match: (model) => endpointIs('openai')(model) || endpointIs('image-generation')(model),
|
|
provider: (provider) => {
|
|
return {
|
|
...provider,
|
|
type: 'openai' as ProviderType
|
|
}
|
|
}
|
|
}
|
|
],
|
|
fallbackRule: (provider) => provider
|
|
}
|
|
|
|
export const newApiResolverCreator = <P extends MinimalProvider>(model: MinimalModel, provider: P): P =>
|
|
provider2Provider<MinimalModel, MinimalProvider, P>(NEWAPI_RULES, model, provider)
|