Arsalaan Ahmed commited on
Commit
e002642
·
unverified ·
1 Parent(s): 93c2a6e

feat: added hyperbolic llm models (#943)

Browse files

* Added Hyperbolic Models

* Fix: Fixed problem in connecting with hyperbolic models

* added dynamic models for hyperbolic

* removed logs

.env.example CHANGED
@@ -51,6 +51,12 @@ OPENAI_LIKE_API_KEY=
51
  # Get your Together API Key
52
  TOGETHER_API_KEY=
53
 
 
 
 
 
 
 
54
  # Get your Mistral API Key by following these instructions -
55
  # https://console.mistral.ai/api-keys/
56
  # You only need this environment variable set if you want to use Mistral models
 
51
  # Get your Together API Key
52
  TOGETHER_API_KEY=
53
 
54
+ # You only need this environment variable set if you want to use Hyperbolic models
55
+ #Get your Hyperbolics API Key at https://app.hyperbolic.xyz/settings
56
+ #baseURL="https://api.hyperbolic.xyz/v1/chat/completions"
57
+ HYPERBOLIC_API_KEY=
58
+ HYPERBOLIC_API_BASE_URL=
59
+
60
  # Get your Mistral API Key by following these instructions -
61
  # https://console.mistral.ai/api-keys/
62
  # You only need this environment variable set if you want to use Mistral models
app/lib/modules/llm/providers/hyperbolic.ts ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { BaseProvider } from '~/lib/modules/llm/base-provider';
2
+ import type { ModelInfo } from '~/lib/modules/llm/types';
3
+ import type { IProviderSetting } from '~/types/model';
4
+ import type { LanguageModelV1 } from 'ai';
5
+ import { createOpenAI } from '@ai-sdk/openai';
6
+
7
+ export default class HyperbolicProvider extends BaseProvider {
8
+ name = 'Hyperbolic';
9
+ getApiKeyLink = 'https://hyperbolic.xyz/settings';
10
+
11
+ config = {
12
+ apiTokenKey: 'HYPERBOLIC_API_KEY',
13
+ };
14
+
15
+ staticModels: ModelInfo[] = [
16
+ {
17
+ name: 'Qwen/Qwen2.5-Coder-32B-Instruct',
18
+ label: 'Qwen 2.5 Coder 32B Instruct',
19
+ provider: 'Hyperbolic',
20
+ maxTokenAllowed: 8192,
21
+ },
22
+ {
23
+ name: 'Qwen/Qwen2.5-72B-Instruct',
24
+ label: 'Qwen2.5-72B-Instruct',
25
+ provider: 'Hyperbolic',
26
+ maxTokenAllowed: 8192,
27
+ },
28
+ {
29
+ name: 'deepseek-ai/DeepSeek-V2.5',
30
+ label: 'DeepSeek-V2.5',
31
+ provider: 'Hyperbolic',
32
+ maxTokenAllowed: 8192,
33
+ },
34
+ {
35
+ name: 'Qwen/QwQ-32B-Preview',
36
+ label: 'QwQ-32B-Preview',
37
+ provider: 'Hyperbolic',
38
+ maxTokenAllowed: 8192,
39
+ },
40
+ {
41
+ name: 'Qwen/Qwen2-VL-72B-Instruct',
42
+ label: 'Qwen2-VL-72B-Instruct',
43
+ provider: 'Hyperbolic',
44
+ maxTokenAllowed: 8192,
45
+ },
46
+ ];
47
+
48
+ async getDynamicModels(
49
+ apiKeys?: Record<string, string>,
50
+ settings?: IProviderSetting,
51
+ serverEnv: Record<string, string> = {},
52
+ ): Promise<ModelInfo[]> {
53
+ try {
54
+ const { baseUrl: fetchBaseUrl, apiKey } = this.getProviderBaseUrlAndKey({
55
+ apiKeys,
56
+ providerSettings: settings,
57
+ serverEnv,
58
+ defaultBaseUrlKey: '',
59
+ defaultApiTokenKey: 'HYPERBOLIC_API_KEY',
60
+ });
61
+ const baseUrl = fetchBaseUrl || 'https://api.hyperbolic.xyz/v1';
62
+
63
+ if (!baseUrl || !apiKey) {
64
+ return [];
65
+ }
66
+
67
+ const response = await fetch(`${baseUrl}/models`, {
68
+ headers: {
69
+ Authorization: `Bearer ${apiKey}`,
70
+ },
71
+ });
72
+
73
+ const res = (await response.json()) as any;
74
+
75
+ const data = res.data.filter((model: any) => model.object === 'model' && model.supports_chat);
76
+
77
+ return data.map((m: any) => ({
78
+ name: m.id,
79
+ label: `${m.id} - context ${m.context_length ? Math.floor(m.context_length / 1000) + 'k' : 'N/A'}`,
80
+ provider: this.name,
81
+ maxTokenAllowed: m.context_length || 8000,
82
+ }));
83
+ } catch (error: any) {
84
+ console.error('Error getting Hyperbolic models:', error.message);
85
+ return [];
86
+ }
87
+ }
88
+
89
+ getModelInstance(options: {
90
+ model: string;
91
+ serverEnv: Env;
92
+ apiKeys?: Record<string, string>;
93
+ providerSettings?: Record<string, IProviderSetting>;
94
+ }): LanguageModelV1 {
95
+ const { model, serverEnv, apiKeys, providerSettings } = options;
96
+
97
+ const { apiKey } = this.getProviderBaseUrlAndKey({
98
+ apiKeys,
99
+ providerSettings: providerSettings?.[this.name],
100
+ serverEnv: serverEnv as any,
101
+ defaultBaseUrlKey: '',
102
+ defaultApiTokenKey: 'HYPERBOLIC_API_KEY',
103
+ });
104
+
105
+ if (!apiKey) {
106
+ console.log(`Missing configuration for ${this.name} provider`);
107
+ throw new Error(`Missing configuration for ${this.name} provider`);
108
+ }
109
+
110
+ const openai = createOpenAI({
111
+ baseURL: 'https://api.hyperbolic.xyz/v1/',
112
+ apiKey,
113
+ });
114
+
115
+ return openai(model);
116
+ }
117
+ }
app/lib/modules/llm/registry.ts CHANGED
@@ -13,6 +13,7 @@ import OpenAIProvider from './providers/openai';
13
  import PerplexityProvider from './providers/perplexity';
14
  import TogetherProvider from './providers/together';
15
  import XAIProvider from './providers/xai';
 
16
 
17
  export {
18
  AnthropicProvider,
@@ -21,6 +22,7 @@ export {
21
  GoogleProvider,
22
  GroqProvider,
23
  HuggingFaceProvider,
 
24
  MistralProvider,
25
  OllamaProvider,
26
  OpenAIProvider,
 
13
  import PerplexityProvider from './providers/perplexity';
14
  import TogetherProvider from './providers/together';
15
  import XAIProvider from './providers/xai';
16
+ import HyperbolicProvider from './providers/hyperbolic';
17
 
18
  export {
19
  AnthropicProvider,
 
22
  GoogleProvider,
23
  GroqProvider,
24
  HuggingFaceProvider,
25
+ HyperbolicProvider,
26
  MistralProvider,
27
  OllamaProvider,
28
  OpenAIProvider,
package.json CHANGED
@@ -76,6 +76,7 @@
76
  "ai": "^4.0.13",
77
  "date-fns": "^3.6.0",
78
  "diff": "^5.2.0",
 
79
  "file-saver": "^2.0.5",
80
  "framer-motion": "^11.12.0",
81
  "ignore": "^6.0.2",
 
76
  "ai": "^4.0.13",
77
  "date-fns": "^3.6.0",
78
  "diff": "^5.2.0",
79
+ "dotenv": "^16.4.7",
80
  "file-saver": "^2.0.5",
81
  "framer-motion": "^11.12.0",
82
  "ignore": "^6.0.2",
pnpm-lock.yaml CHANGED
@@ -149,6 +149,9 @@ importers:
149
  diff:
150
  specifier: ^5.2.0
151
  version: 5.2.0
 
 
 
152
  file-saver:
153
  specifier: ^2.0.5
154
  version: 2.0.5
@@ -2901,8 +2904,8 @@ packages:
2901
  resolution: {integrity: sha512-IGBwjF7tNk3cwypFNH/7bfzBcgSCbaMOD3GsaY1AU/JRrnHnYgEM0+9kQt52iZxjNsjBtJYtao146V+f8jFZNw==}
2902
  engines: {node: '>=10'}
2903
 
2904
2905
- resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==}
2906
  engines: {node: '>=12'}
2907
 
2908
@@ -7246,7 +7249,7 @@ snapshots:
7246
  chalk: 4.1.2
7247
  chokidar: 3.6.0
7248
  cross-spawn: 7.0.6
7249
- dotenv: 16.4.5
7250
  es-module-lexer: 1.5.4
7251
  esbuild: 0.17.6
7252
  esbuild-plugins-node-modules-polyfill: 1.6.8([email protected])
@@ -8450,7 +8453,7 @@ snapshots:
8450
 
8451
8452
 
8453
8454
 
8455
8456
 
@@ -11957,4 +11960,4 @@ snapshots:
11957
 
11958
11959
 
11960
 
149
  diff:
150
  specifier: ^5.2.0
151
  version: 5.2.0
152
+ dotenv:
153
+ specifier: ^16.4.7
154
+ version: 16.4.7
155
  file-saver:
156
  specifier: ^2.0.5
157
  version: 2.0.5
 
2904
  resolution: {integrity: sha512-IGBwjF7tNk3cwypFNH/7bfzBcgSCbaMOD3GsaY1AU/JRrnHnYgEM0+9kQt52iZxjNsjBtJYtao146V+f8jFZNw==}
2905
  engines: {node: '>=10'}
2906
 
2907
2908
+ resolution: {integrity: sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==}
2909
  engines: {node: '>=12'}
2910
 
2911
 
7249
  chalk: 4.1.2
7250
  chokidar: 3.6.0
7251
  cross-spawn: 7.0.6
7252
+ dotenv: 16.4.7
7253
  es-module-lexer: 1.5.4
7254
  esbuild: 0.17.6
7255
  esbuild-plugins-node-modules-polyfill: 1.6.8([email protected])
 
8453
 
8454
8455
 
8456
8457
 
8458
8459
 
 
11960
 
11961
11962
 
11963