mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: channel gateway implementation and multi-bot refactor
- Refactor channel manager with support for Sender/Receiver interfaces and hot-swappable adapters. - Implement identity routing and pre-authentication logic for inbound messages. - Update database schema to support bot pre-auth keys and extended channel session metadata. - Add Telegram and Feishu channel configuration and adapter enhancements. - Update Swagger documentation and internal handlers for channel management. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+17
-12
@@ -5,17 +5,22 @@ import { createGoogleGenerativeAI } from '@ai-sdk/google'
|
||||
import { ClientType, ModelConfig } from './types'
|
||||
|
||||
export const createModel = (model: ModelConfig) => {
|
||||
const apiKey = model.apiKey.toLowerCase().trim()
|
||||
const baseURL = model.baseUrl.toLowerCase().trim()
|
||||
const modelId = model.modelId.toLowerCase().trim()
|
||||
const clients = {
|
||||
[ClientType.OpenAI]: createOpenAI,
|
||||
[ClientType.OpenAICompatible]: createOpenAI,
|
||||
[ClientType.Anthropic]: createAnthropic,
|
||||
[ClientType.Google]: createGoogleGenerativeAI,
|
||||
const apiKey = model.apiKey.trim()
|
||||
const baseURL = model.baseUrl.trim()
|
||||
const modelId = model.modelId.trim()
|
||||
|
||||
switch (model.clientType) {
|
||||
case ClientType.OpenAI:
|
||||
case ClientType.OpenAICompatible: {
|
||||
const provider = createOpenAI({ apiKey, baseURL })
|
||||
// Use .chat() to call /chat/completions (not /responses which only OpenAI supports)
|
||||
return provider.chat(modelId)
|
||||
}
|
||||
case ClientType.Anthropic:
|
||||
return createAnthropic({ apiKey, baseURL })(modelId)
|
||||
case ClientType.Google:
|
||||
return createGoogleGenerativeAI({ apiKey, baseURL })(modelId)
|
||||
default:
|
||||
return createAiGateway({ apiKey, baseURL })(modelId)
|
||||
}
|
||||
return (clients[model.clientType] ?? createAiGateway)({
|
||||
apiKey,
|
||||
baseURL,
|
||||
})(modelId)
|
||||
}
|
||||
Reference in New Issue
Block a user