Spaces:
Build error
Build error
Google Vertex API support (#950)
Browse files* Added Google Vertex API support
Google Application credentials can be set via
GOOGLE_APPLICATION_CREDENTIALS = clientid.json
* Updated the readme file
* Updated the package-lock file
* Updated the package-lock file
Fixed minor issues
* Moved "@google-cloud/vertexai" to optional dependencies
* Updated for lint checker
- README.md +36 -0
- package-lock.json +145 -8
- package.json +2 -1
- src/lib/server/endpoints/endpoints.ts +4 -0
- src/lib/server/endpoints/google/endpointVertex.ts +78 -0
- src/lib/server/models.ts +2 -0
README.md
CHANGED
@@ -528,6 +528,42 @@ You can also set `"service" : "lambda"` to use a lambda instance.
|
|
528 |
|
529 |
You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.
|
530 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
### Custom endpoint authorization
|
532 |
|
533 |
#### Basic and Bearer
|
|
|
528 |
|
529 |
You can get the `accessKey` and `secretKey` from your AWS user, under programmatic access.
|
530 |
|
531 |
+
##### Google Vertex models
|
532 |
+
|
533 |
+
Chat UI can connect to the google Vertex API endpoints ([List of supported models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models)).
|
534 |
+
|
535 |
+
To enable:
|
536 |
+
|
537 |
+
1. [Select](https://console.cloud.google.com/project) or [create](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project) a Google Cloud project.
|
538 |
+
1. [Enable billing for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
|
539 |
+
1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
|
540 |
+
1. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started)
|
541 |
+
so you can access the API from your local workstation.
|
542 |
+
|
543 |
+
The service account credentials file can be imported as an environmental variable:
|
544 |
+
|
545 |
+
```env
|
546 |
+
GOOGLE_APPLICATION_CREDENTIALS = clientid.json
|
547 |
+
```
|
548 |
+
|
549 |
+
Make sure docker has access to the file. Afterwards Google Vertex endpoints can be configured as following:
|
550 |
+
|
551 |
+
```
|
552 |
+
MODELS=`[
|
553 |
+
//...
|
554 |
+
{
|
555 |
+
"name": "gemini-1.0-pro", //model-name
|
556 |
+
"displayName": "Vertex Gemini Pro 1.0",
|
557 |
+
"location": "europe-west3",
|
558 |
+
"apiEndpoint": "", //alternative api endpoint url
|
559 |
+
"endpoints" : [{
|
560 |
+
"type": "vertex"
|
561 |
+
}]
|
562 |
+
},
|
563 |
+
]`
|
564 |
+
|
565 |
+
```
|
566 |
+
|
567 |
### Custom endpoint authorization
|
568 |
|
569 |
#### Basic and Bearer
|
package-lock.json
CHANGED
@@ -74,7 +74,8 @@
|
|
74 |
"optionalDependencies": {
|
75 |
"@anthropic-ai/sdk": "^0.17.1",
|
76 |
"aws4fetch": "^1.0.17",
|
77 |
-
"openai": "^4.14.2"
|
|
|
78 |
}
|
79 |
},
|
80 |
"node_modules/@alloc/quick-lru": {
|
@@ -628,6 +629,17 @@
|
|
628 |
"node": ">=14"
|
629 |
}
|
630 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
631 |
"node_modules/@huggingface/hub": {
|
632 |
"version": "0.5.1",
|
633 |
"resolved": "https://registry.npmjs.org/@huggingface/hub/-/hub-0.5.1.tgz",
|
@@ -2679,6 +2691,14 @@
|
|
2679 |
}
|
2680 |
]
|
2681 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2682 |
"node_modules/binary-extensions": {
|
2683 |
"version": "2.2.0",
|
2684 |
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
|
@@ -2809,6 +2829,11 @@
|
|
2809 |
"node": "*"
|
2810 |
}
|
2811 |
},
|
|
|
|
|
|
|
|
|
|
|
2812 |
"node_modules/bufferutil": {
|
2813 |
"version": "4.0.7",
|
2814 |
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.7.tgz",
|
@@ -3433,6 +3458,14 @@
|
|
3433 |
"node": ">=12"
|
3434 |
}
|
3435 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3436 |
"node_modules/electron-to-chromium": {
|
3437 |
"version": "1.4.359",
|
3438 |
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.359.tgz",
|
@@ -3787,6 +3820,11 @@
|
|
3787 |
"node": ">=6"
|
3788 |
}
|
3789 |
},
|
|
|
|
|
|
|
|
|
|
|
3790 |
"node_modules/fast-deep-equal": {
|
3791 |
"version": "3.1.3",
|
3792 |
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
@@ -3993,6 +4031,55 @@
|
|
3993 |
"url": "https://github.com/sponsors/ljharb"
|
3994 |
}
|
3995 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3996 |
"node_modules/get-func-name": {
|
3997 |
"version": "2.0.2",
|
3998 |
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz",
|
@@ -4097,6 +4184,22 @@
|
|
4097 |
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==",
|
4098 |
"dev": true
|
4099 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4100 |
"node_modules/graceful-fs": {
|
4101 |
"version": "4.2.11",
|
4102 |
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
@@ -4115,6 +4218,18 @@
|
|
4115 |
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
4116 |
"dev": true
|
4117 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4118 |
"node_modules/guid-typescript": {
|
4119 |
"version": "1.0.9",
|
4120 |
"resolved": "https://registry.npmjs.org/guid-typescript/-/guid-typescript-1.0.9.tgz",
|
@@ -4460,7 +4575,6 @@
|
|
4460 |
"version": "2.0.1",
|
4461 |
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
4462 |
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
|
4463 |
-
"dev": true,
|
4464 |
"engines": {
|
4465 |
"node": ">=8"
|
4466 |
},
|
@@ -4590,6 +4704,14 @@
|
|
4590 |
"node": ">=14"
|
4591 |
}
|
4592 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4593 |
"node_modules/json-schema-traverse": {
|
4594 |
"version": "0.4.1",
|
4595 |
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
@@ -4619,6 +4741,25 @@
|
|
4619 |
"integrity": "sha512-AilxAyFOAcK5wA1+LeaySVBrHsGQvUFCDWXKpZjzaL0PqW+xfBOttn8GNtWKFWqneyMZj41MWF9Kl6iPWLwgOA==",
|
4620 |
"dev": true
|
4621 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4622 |
"node_modules/katex": {
|
4623 |
"version": "0.16.10",
|
4624 |
"resolved": "https://registry.npmjs.org/katex/-/katex-0.16.10.tgz",
|
@@ -5152,7 +5293,6 @@
|
|
5152 |
"version": "2.7.0",
|
5153 |
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
5154 |
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
5155 |
-
"optional": true,
|
5156 |
"dependencies": {
|
5157 |
"whatwg-url": "^5.0.0"
|
5158 |
},
|
@@ -5171,20 +5311,17 @@
|
|
5171 |
"node_modules/node-fetch/node_modules/tr46": {
|
5172 |
"version": "0.0.3",
|
5173 |
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
5174 |
-
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
|
5175 |
-
"optional": true
|
5176 |
},
|
5177 |
"node_modules/node-fetch/node_modules/webidl-conversions": {
|
5178 |
"version": "3.0.1",
|
5179 |
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
5180 |
-
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
5181 |
-
"optional": true
|
5182 |
},
|
5183 |
"node_modules/node-fetch/node_modules/whatwg-url": {
|
5184 |
"version": "5.0.0",
|
5185 |
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
5186 |
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
|
5187 |
-
"optional": true,
|
5188 |
"dependencies": {
|
5189 |
"tr46": "~0.0.3",
|
5190 |
"webidl-conversions": "^3.0.0"
|
|
|
74 |
"optionalDependencies": {
|
75 |
"@anthropic-ai/sdk": "^0.17.1",
|
76 |
"aws4fetch": "^1.0.17",
|
77 |
+
"openai": "^4.14.2",
|
78 |
+
"@google-cloud/vertexai": "^0.5.0"
|
79 |
}
|
80 |
},
|
81 |
"node_modules/@alloc/quick-lru": {
|
|
|
629 |
"node": ">=14"
|
630 |
}
|
631 |
},
|
632 |
+
"node_modules/@google-cloud/vertexai": {
|
633 |
+
"version": "0.5.0",
|
634 |
+
"resolved": "https://registry.npmjs.org/@google-cloud/vertexai/-/vertexai-0.5.0.tgz",
|
635 |
+
"integrity": "sha512-qIFHYTXA5UCLdm9JG+Xf1suomCXxRqa1PKdYjqXuhZsCm8mn37Rb0Tf8djlhDzuRVWyWoQTmsWpsk28ZTmbqJg==",
|
636 |
+
"dependencies": {
|
637 |
+
"google-auth-library": "^9.1.0"
|
638 |
+
},
|
639 |
+
"engines": {
|
640 |
+
"node": ">=18.0.0"
|
641 |
+
}
|
642 |
+
},
|
643 |
"node_modules/@huggingface/hub": {
|
644 |
"version": "0.5.1",
|
645 |
"resolved": "https://registry.npmjs.org/@huggingface/hub/-/hub-0.5.1.tgz",
|
|
|
2691 |
}
|
2692 |
]
|
2693 |
},
|
2694 |
+
"node_modules/bignumber.js": {
|
2695 |
+
"version": "9.1.2",
|
2696 |
+
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz",
|
2697 |
+
"integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==",
|
2698 |
+
"engines": {
|
2699 |
+
"node": "*"
|
2700 |
+
}
|
2701 |
+
},
|
2702 |
"node_modules/binary-extensions": {
|
2703 |
"version": "2.2.0",
|
2704 |
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
|
|
|
2829 |
"node": "*"
|
2830 |
}
|
2831 |
},
|
2832 |
+
"node_modules/buffer-equal-constant-time": {
|
2833 |
+
"version": "1.0.1",
|
2834 |
+
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
2835 |
+
"integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA=="
|
2836 |
+
},
|
2837 |
"node_modules/bufferutil": {
|
2838 |
"version": "4.0.7",
|
2839 |
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.7.tgz",
|
|
|
3458 |
"node": ">=12"
|
3459 |
}
|
3460 |
},
|
3461 |
+
"node_modules/ecdsa-sig-formatter": {
|
3462 |
+
"version": "1.0.11",
|
3463 |
+
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
3464 |
+
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
|
3465 |
+
"dependencies": {
|
3466 |
+
"safe-buffer": "^5.0.1"
|
3467 |
+
}
|
3468 |
+
},
|
3469 |
"node_modules/electron-to-chromium": {
|
3470 |
"version": "1.4.359",
|
3471 |
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.359.tgz",
|
|
|
3820 |
"node": ">=6"
|
3821 |
}
|
3822 |
},
|
3823 |
+
"node_modules/extend": {
|
3824 |
+
"version": "3.0.2",
|
3825 |
+
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
|
3826 |
+
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="
|
3827 |
+
},
|
3828 |
"node_modules/fast-deep-equal": {
|
3829 |
"version": "3.1.3",
|
3830 |
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
|
|
4031 |
"url": "https://github.com/sponsors/ljharb"
|
4032 |
}
|
4033 |
},
|
4034 |
+
"node_modules/gaxios": {
|
4035 |
+
"version": "6.3.0",
|
4036 |
+
"resolved": "https://registry.npmjs.org/gaxios/-/gaxios-6.3.0.tgz",
|
4037 |
+
"integrity": "sha512-p+ggrQw3fBwH2F5N/PAI4k/G/y1art5OxKpb2J2chwNNHM4hHuAOtivjPuirMF4KNKwTTUal/lPfL2+7h2mEcg==",
|
4038 |
+
"dependencies": {
|
4039 |
+
"extend": "^3.0.2",
|
4040 |
+
"https-proxy-agent": "^7.0.1",
|
4041 |
+
"is-stream": "^2.0.0",
|
4042 |
+
"node-fetch": "^2.6.9"
|
4043 |
+
},
|
4044 |
+
"engines": {
|
4045 |
+
"node": ">=14"
|
4046 |
+
}
|
4047 |
+
},
|
4048 |
+
"node_modules/gaxios/node_modules/agent-base": {
|
4049 |
+
"version": "7.1.0",
|
4050 |
+
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz",
|
4051 |
+
"integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==",
|
4052 |
+
"dependencies": {
|
4053 |
+
"debug": "^4.3.4"
|
4054 |
+
},
|
4055 |
+
"engines": {
|
4056 |
+
"node": ">= 14"
|
4057 |
+
}
|
4058 |
+
},
|
4059 |
+
"node_modules/gaxios/node_modules/https-proxy-agent": {
|
4060 |
+
"version": "7.0.4",
|
4061 |
+
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz",
|
4062 |
+
"integrity": "sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==",
|
4063 |
+
"dependencies": {
|
4064 |
+
"agent-base": "^7.0.2",
|
4065 |
+
"debug": "4"
|
4066 |
+
},
|
4067 |
+
"engines": {
|
4068 |
+
"node": ">= 14"
|
4069 |
+
}
|
4070 |
+
},
|
4071 |
+
"node_modules/gcp-metadata": {
|
4072 |
+
"version": "6.1.0",
|
4073 |
+
"resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-6.1.0.tgz",
|
4074 |
+
"integrity": "sha512-Jh/AIwwgaxan+7ZUUmRLCjtchyDiqh4KjBJ5tW3plBZb5iL/BPcso8A5DlzeD9qlw0duCamnNdpFjxwaT0KyKg==",
|
4075 |
+
"dependencies": {
|
4076 |
+
"gaxios": "^6.0.0",
|
4077 |
+
"json-bigint": "^1.0.0"
|
4078 |
+
},
|
4079 |
+
"engines": {
|
4080 |
+
"node": ">=14"
|
4081 |
+
}
|
4082 |
+
},
|
4083 |
"node_modules/get-func-name": {
|
4084 |
"version": "2.0.2",
|
4085 |
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz",
|
|
|
4184 |
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==",
|
4185 |
"dev": true
|
4186 |
},
|
4187 |
+
"node_modules/google-auth-library": {
|
4188 |
+
"version": "9.7.0",
|
4189 |
+
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.7.0.tgz",
|
4190 |
+
"integrity": "sha512-I/AvzBiUXDzLOy4iIZ2W+Zq33W4lcukQv1nl7C8WUA6SQwyQwUwu3waNmWNAvzds//FG8SZ+DnKnW/2k6mQS8A==",
|
4191 |
+
"dependencies": {
|
4192 |
+
"base64-js": "^1.3.0",
|
4193 |
+
"ecdsa-sig-formatter": "^1.0.11",
|
4194 |
+
"gaxios": "^6.1.1",
|
4195 |
+
"gcp-metadata": "^6.1.0",
|
4196 |
+
"gtoken": "^7.0.0",
|
4197 |
+
"jws": "^4.0.0"
|
4198 |
+
},
|
4199 |
+
"engines": {
|
4200 |
+
"node": ">=14"
|
4201 |
+
}
|
4202 |
+
},
|
4203 |
"node_modules/graceful-fs": {
|
4204 |
"version": "4.2.11",
|
4205 |
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
|
|
4218 |
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
4219 |
"dev": true
|
4220 |
},
|
4221 |
+
"node_modules/gtoken": {
|
4222 |
+
"version": "7.1.0",
|
4223 |
+
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-7.1.0.tgz",
|
4224 |
+
"integrity": "sha512-pCcEwRi+TKpMlxAQObHDQ56KawURgyAf6jtIY046fJ5tIv3zDe/LEIubckAO8fj6JnAxLdmWkUfNyulQ2iKdEw==",
|
4225 |
+
"dependencies": {
|
4226 |
+
"gaxios": "^6.0.0",
|
4227 |
+
"jws": "^4.0.0"
|
4228 |
+
},
|
4229 |
+
"engines": {
|
4230 |
+
"node": ">=14.0.0"
|
4231 |
+
}
|
4232 |
+
},
|
4233 |
"node_modules/guid-typescript": {
|
4234 |
"version": "1.0.9",
|
4235 |
"resolved": "https://registry.npmjs.org/guid-typescript/-/guid-typescript-1.0.9.tgz",
|
|
|
4575 |
"version": "2.0.1",
|
4576 |
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
4577 |
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
|
|
|
4578 |
"engines": {
|
4579 |
"node": ">=8"
|
4580 |
},
|
|
|
4704 |
"node": ">=14"
|
4705 |
}
|
4706 |
},
|
4707 |
+
"node_modules/json-bigint": {
|
4708 |
+
"version": "1.0.0",
|
4709 |
+
"resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz",
|
4710 |
+
"integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==",
|
4711 |
+
"dependencies": {
|
4712 |
+
"bignumber.js": "^9.0.0"
|
4713 |
+
}
|
4714 |
+
},
|
4715 |
"node_modules/json-schema-traverse": {
|
4716 |
"version": "0.4.1",
|
4717 |
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
|
|
4741 |
"integrity": "sha512-AilxAyFOAcK5wA1+LeaySVBrHsGQvUFCDWXKpZjzaL0PqW+xfBOttn8GNtWKFWqneyMZj41MWF9Kl6iPWLwgOA==",
|
4742 |
"dev": true
|
4743 |
},
|
4744 |
+
"node_modules/jwa": {
|
4745 |
+
"version": "2.0.0",
|
4746 |
+
"resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.0.tgz",
|
4747 |
+
"integrity": "sha512-jrZ2Qx916EA+fq9cEAeCROWPTfCwi1IVHqT2tapuqLEVVDKFDENFw1oL+MwrTvH6msKxsd1YTDVw6uKEcsrLEA==",
|
4748 |
+
"dependencies": {
|
4749 |
+
"buffer-equal-constant-time": "1.0.1",
|
4750 |
+
"ecdsa-sig-formatter": "1.0.11",
|
4751 |
+
"safe-buffer": "^5.0.1"
|
4752 |
+
}
|
4753 |
+
},
|
4754 |
+
"node_modules/jws": {
|
4755 |
+
"version": "4.0.0",
|
4756 |
+
"resolved": "https://registry.npmjs.org/jws/-/jws-4.0.0.tgz",
|
4757 |
+
"integrity": "sha512-KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg==",
|
4758 |
+
"dependencies": {
|
4759 |
+
"jwa": "^2.0.0",
|
4760 |
+
"safe-buffer": "^5.0.1"
|
4761 |
+
}
|
4762 |
+
},
|
4763 |
"node_modules/katex": {
|
4764 |
"version": "0.16.10",
|
4765 |
"resolved": "https://registry.npmjs.org/katex/-/katex-0.16.10.tgz",
|
|
|
5293 |
"version": "2.7.0",
|
5294 |
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
5295 |
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
|
|
5296 |
"dependencies": {
|
5297 |
"whatwg-url": "^5.0.0"
|
5298 |
},
|
|
|
5311 |
"node_modules/node-fetch/node_modules/tr46": {
|
5312 |
"version": "0.0.3",
|
5313 |
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
5314 |
+
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
|
|
|
5315 |
},
|
5316 |
"node_modules/node-fetch/node_modules/webidl-conversions": {
|
5317 |
"version": "3.0.1",
|
5318 |
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
5319 |
+
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
|
|
5320 |
},
|
5321 |
"node_modules/node-fetch/node_modules/whatwg-url": {
|
5322 |
"version": "5.0.0",
|
5323 |
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
5324 |
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
|
|
|
5325 |
"dependencies": {
|
5326 |
"tr46": "~0.0.3",
|
5327 |
"webidl-conversions": "^3.0.0"
|
package.json
CHANGED
@@ -84,6 +84,7 @@
|
|
84 |
"optionalDependencies": {
|
85 |
"@anthropic-ai/sdk": "^0.17.1",
|
86 |
"aws4fetch": "^1.0.17",
|
87 |
-
"openai": "^4.14.2"
|
|
|
88 |
}
|
89 |
}
|
|
|
84 |
"optionalDependencies": {
|
85 |
"@anthropic-ai/sdk": "^0.17.1",
|
86 |
"aws4fetch": "^1.0.17",
|
87 |
+
"openai": "^4.14.2",
|
88 |
+
"@google-cloud/vertexai": "^0.5.0"
|
89 |
}
|
90 |
}
|
src/lib/server/endpoints/endpoints.ts
CHANGED
@@ -6,6 +6,8 @@ import endpointAws, { endpointAwsParametersSchema } from "./aws/endpointAws";
|
|
6 |
import { endpointOAIParametersSchema, endpointOai } from "./openai/endpointOai";
|
7 |
import endpointLlamacpp, { endpointLlamacppParametersSchema } from "./llamacpp/endpointLlamacpp";
|
8 |
import endpointOllama, { endpointOllamaParametersSchema } from "./ollama/endpointOllama";
|
|
|
|
|
9 |
import {
|
10 |
endpointAnthropic,
|
11 |
endpointAnthropicParametersSchema,
|
@@ -39,6 +41,7 @@ export const endpoints = {
|
|
39 |
openai: endpointOai,
|
40 |
llamacpp: endpointLlamacpp,
|
41 |
ollama: endpointOllama,
|
|
|
42 |
};
|
43 |
|
44 |
export const endpointSchema = z.discriminatedUnion("type", [
|
@@ -48,5 +51,6 @@ export const endpointSchema = z.discriminatedUnion("type", [
|
|
48 |
endpointTgiParametersSchema,
|
49 |
endpointLlamacppParametersSchema,
|
50 |
endpointOllamaParametersSchema,
|
|
|
51 |
]);
|
52 |
export default endpoints;
|
|
|
6 |
import { endpointOAIParametersSchema, endpointOai } from "./openai/endpointOai";
|
7 |
import endpointLlamacpp, { endpointLlamacppParametersSchema } from "./llamacpp/endpointLlamacpp";
|
8 |
import endpointOllama, { endpointOllamaParametersSchema } from "./ollama/endpointOllama";
|
9 |
+
import endpointVertex, { endpointVertexParametersSchema } from "./google/endpointVertex";
|
10 |
+
|
11 |
import {
|
12 |
endpointAnthropic,
|
13 |
endpointAnthropicParametersSchema,
|
|
|
41 |
openai: endpointOai,
|
42 |
llamacpp: endpointLlamacpp,
|
43 |
ollama: endpointOllama,
|
44 |
+
vertex: endpointVertex,
|
45 |
};
|
46 |
|
47 |
export const endpointSchema = z.discriminatedUnion("type", [
|
|
|
51 |
endpointTgiParametersSchema,
|
52 |
endpointLlamacppParametersSchema,
|
53 |
endpointOllamaParametersSchema,
|
54 |
+
endpointVertexParametersSchema,
|
55 |
]);
|
56 |
export default endpoints;
|
src/lib/server/endpoints/google/endpointVertex.ts
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { VertexAI, HarmCategory, HarmBlockThreshold } from "@google-cloud/vertexai";
|
2 |
+
import { buildPrompt } from "$lib/buildPrompt";
|
3 |
+
import type { TextGenerationStreamOutput } from "@huggingface/inference";
|
4 |
+
import type { Endpoint } from "../endpoints";
|
5 |
+
import { z } from "zod";
|
6 |
+
|
7 |
+
export const endpointVertexParametersSchema = z.object({
|
8 |
+
weight: z.number().int().positive().default(1),
|
9 |
+
model: z.any(), // allow optional and validate against emptiness
|
10 |
+
type: z.literal("vertex"),
|
11 |
+
location: z.string().default("europe-west1"),
|
12 |
+
project: z.string(),
|
13 |
+
apiEndpoint: z.string().optional(),
|
14 |
+
});
|
15 |
+
|
16 |
+
export function endpointVertex(input: z.input<typeof endpointVertexParametersSchema>): Endpoint {
|
17 |
+
const { project, location, model, apiEndpoint } = endpointVertexParametersSchema.parse(input);
|
18 |
+
|
19 |
+
const vertex_ai = new VertexAI({
|
20 |
+
project,
|
21 |
+
location,
|
22 |
+
apiEndpoint,
|
23 |
+
});
|
24 |
+
|
25 |
+
const generativeModel = vertex_ai.getGenerativeModel({
|
26 |
+
model: model.id ?? model.name,
|
27 |
+
safety_settings: [
|
28 |
+
{
|
29 |
+
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
30 |
+
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
31 |
+
},
|
32 |
+
],
|
33 |
+
generation_config: {},
|
34 |
+
});
|
35 |
+
|
36 |
+
return async ({ messages, preprompt, continueMessage }) => {
|
37 |
+
const prompt = await buildPrompt({
|
38 |
+
messages,
|
39 |
+
continueMessage,
|
40 |
+
preprompt,
|
41 |
+
model,
|
42 |
+
});
|
43 |
+
|
44 |
+
const chat = generativeModel.startChat();
|
45 |
+
const result = await chat.sendMessageStream(prompt);
|
46 |
+
let tokenId = 0;
|
47 |
+
|
48 |
+
return (async function* () {
|
49 |
+
let generatedText = "";
|
50 |
+
|
51 |
+
for await (const data of result.stream) {
|
52 |
+
if (Array.isArray(data?.candidates) && data.candidates.length > 0) {
|
53 |
+
const firstPart = data.candidates[0].content.parts[0];
|
54 |
+
if ("text" in firstPart) {
|
55 |
+
const content = firstPart.text;
|
56 |
+
generatedText += content;
|
57 |
+
const output: TextGenerationStreamOutput = {
|
58 |
+
token: {
|
59 |
+
id: tokenId++,
|
60 |
+
text: content ?? "",
|
61 |
+
logprob: 0,
|
62 |
+
special: false,
|
63 |
+
},
|
64 |
+
generated_text: generatedText,
|
65 |
+
details: null,
|
66 |
+
};
|
67 |
+
yield output;
|
68 |
+
}
|
69 |
+
|
70 |
+
if (!data.candidates.slice(-1)[0].finishReason) break;
|
71 |
+
} else {
|
72 |
+
break;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
})();
|
76 |
+
};
|
77 |
+
}
|
78 |
+
export default endpointVertex;
|
src/lib/server/models.ts
CHANGED
@@ -128,6 +128,8 @@ const addEndpoint = (m: Awaited<ReturnType<typeof processModel>>) => ({
|
|
128 |
return endpoints.llamacpp(args);
|
129 |
case "ollama":
|
130 |
return endpoints.ollama(args);
|
|
|
|
|
131 |
default:
|
132 |
// for legacy reason
|
133 |
return endpoints.tgi(args);
|
|
|
128 |
return endpoints.llamacpp(args);
|
129 |
case "ollama":
|
130 |
return endpoints.ollama(args);
|
131 |
+
case "vertex":
|
132 |
+
return await endpoints.vertex(args);
|
133 |
default:
|
134 |
// for legacy reason
|
135 |
return endpoints.tgi(args);
|