mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 02:20:10 +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.
33 lines
882 B
TypeScript
33 lines
882 B
TypeScript
import type { MinimalModel, MinimalProvider } from '../types'
|
|
import type { RuleSet } from './types'
|
|
|
|
export const startsWith =
|
|
(prefix: string) =>
|
|
<M extends MinimalModel>(model: M) =>
|
|
model.id.toLowerCase().startsWith(prefix.toLowerCase())
|
|
|
|
export const endpointIs =
|
|
(type: string) =>
|
|
<M extends MinimalModel>(model: M) =>
|
|
model.endpoint_type === type
|
|
|
|
/**
|
|
* 解析模型对应的Provider
|
|
* @param ruleSet 规则集对象
|
|
* @param model 模型对象
|
|
* @param provider 原始provider对象
|
|
* @returns 解析出的provider对象
|
|
*/
|
|
export function provider2Provider<
|
|
M extends MinimalModel,
|
|
R extends MinimalProvider,
|
|
P extends R = R
|
|
>(ruleSet: RuleSet<M, R>, model: M, provider: P): P {
|
|
for (const rule of ruleSet.rules) {
|
|
if (rule.match(model)) {
|
|
return rule.provider(provider) as P
|
|
}
|
|
}
|
|
return ruleSet.fallbackRule(provider) as P
|
|
}
|