Leon4gr45 commited on
Commit
55815d1
·
verified ·
1 Parent(s): 85d3055

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. lib/ai/provider-manager.ts +2 -29
lib/ai/provider-manager.ts CHANGED
@@ -1,15 +1,11 @@
1
  import { appConfig } from '@/config/app.config';
2
- import { createAnthropic } from '@ai-sdk/anthropic';
3
  import { createOpenAI } from '@ai-sdk/openai';
4
- import { createGoogleGenerativeAI } from '@ai-sdk/google';
5
 
6
- type ProviderName = 'openai' | 'anthropic' | 'google' | 'helmholtz';
7
 
8
  // Client function type returned by @ai-sdk providers
9
  export type ProviderClient =
10
- | ReturnType<typeof createOpenAI>
11
- | ReturnType<typeof createAnthropic>
12
- | ReturnType<typeof createGoogleGenerativeAI>;
13
 
14
  export interface ProviderResolution {
15
  client: ProviderClient;
@@ -31,11 +27,6 @@ function getEnvDefaults(provider: ProviderName): { apiKey?: string; baseURL?: st
31
  switch (provider) {
32
  case 'openai':
33
  return { apiKey: process.env.OPENAI_API_KEY, baseURL: process.env.OPENAI_BASE_URL };
34
- case 'anthropic':
35
- // Default Anthropic base URL mirrors existing routes
36
- return { apiKey: process.env.ANTHROPIC_API_KEY, baseURL: process.env.ANTHROPIC_BASE_URL || 'https://api.anthropic.com/v1' };
37
- case 'google':
38
- return { apiKey: process.env.GEMINI_API_KEY, baseURL: process.env.GEMINI_BASE_URL };
39
  case 'helmholtz':
40
  return { apiKey: process.env.BLABLADOR_API_KEY, baseURL: 'https://api.helmholtz-blablador.fz-juelich.de/v1' };
41
  default:
@@ -57,12 +48,6 @@ function getOrCreateClient(provider: ProviderName, apiKey?: string, baseURL?: st
57
  case 'openai':
58
  client = createOpenAI({ apiKey: effective.apiKey || getEnvDefaults('openai').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('openai').baseURL });
59
  break;
60
- case 'anthropic':
61
- client = createAnthropic({ apiKey: effective.apiKey || getEnvDefaults('anthropic').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('anthropic').baseURL });
62
- break;
63
- case 'google':
64
- client = createGoogleGenerativeAI({ apiKey: effective.apiKey || getEnvDefaults('google').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('google').baseURL });
65
- break;
66
  case 'helmholtz':
67
  client = createOpenAI({ apiKey: effective.apiKey || getEnvDefaults('helmholtz').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('helmholtz').baseURL });
68
  break;
@@ -84,25 +69,13 @@ export function getProviderForModel(modelId: string): ProviderResolution {
84
  }
85
 
86
  // 2) Fallback logic based on prefixes and special cases
87
- const isAnthropic = modelId.startsWith('anthropic/');
88
  const isOpenAI = modelId.startsWith('openai/');
89
- const isGoogle = modelId.startsWith('google/');
90
-
91
- if (isAnthropic) {
92
- const client = getOrCreateClient('anthropic');
93
- return { client, actualModel: modelId.replace('anthropic/', '') };
94
- }
95
 
96
  if (isOpenAI) {
97
  const client = getOrCreateClient('openai');
98
  return { client, actualModel: modelId.replace('openai/', '') };
99
  }
100
 
101
- if (isGoogle) {
102
- const client = getOrCreateClient('google');
103
- return { client, actualModel: modelId.replace('google/', '') };
104
- }
105
-
106
  // Default: use Helmholtz with modelId as-is
107
  const client = getOrCreateClient('helmholtz');
108
  return { client, actualModel: modelId };
 
1
  import { appConfig } from '@/config/app.config';
 
2
  import { createOpenAI } from '@ai-sdk/openai';
 
3
 
4
+ type ProviderName = 'openai' | 'helmholtz';
5
 
6
  // Client function type returned by @ai-sdk providers
7
  export type ProviderClient =
8
+ | ReturnType<typeof createOpenAI>;
 
 
9
 
10
  export interface ProviderResolution {
11
  client: ProviderClient;
 
27
  switch (provider) {
28
  case 'openai':
29
  return { apiKey: process.env.OPENAI_API_KEY, baseURL: process.env.OPENAI_BASE_URL };
 
 
 
 
 
30
  case 'helmholtz':
31
  return { apiKey: process.env.BLABLADOR_API_KEY, baseURL: 'https://api.helmholtz-blablador.fz-juelich.de/v1' };
32
  default:
 
48
  case 'openai':
49
  client = createOpenAI({ apiKey: effective.apiKey || getEnvDefaults('openai').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('openai').baseURL });
50
  break;
 
 
 
 
 
 
51
  case 'helmholtz':
52
  client = createOpenAI({ apiKey: effective.apiKey || getEnvDefaults('helmholtz').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('helmholtz').baseURL });
53
  break;
 
69
  }
70
 
71
  // 2) Fallback logic based on prefixes and special cases
 
72
  const isOpenAI = modelId.startsWith('openai/');
 
 
 
 
 
 
73
 
74
  if (isOpenAI) {
75
  const client = getOrCreateClient('openai');
76
  return { client, actualModel: modelId.replace('openai/', '') };
77
  }
78
 
 
 
 
 
 
79
  // Default: use Helmholtz with modelId as-is
80
  const client = getOrCreateClient('helmholtz');
81
  return { client, actualModel: modelId };