@@ -12,6 +12,7 @@ import JSON5 from "json5";
12
12
import type { EmbeddingModel } from "$lib/types/EmbeddingModel" ;
13
13
import { collections } from "./database" ;
14
14
import { ObjectId } from "mongodb" ;
15
+ import { encrypt } from "$lib/utils/encryption" ;
15
16
16
17
const modelConfig = z . object ( {
17
18
/** Used as an identifier in DB */
@@ -44,6 +45,29 @@ const rawEmbeddingModelJSON =
44
45
45
46
const embeddingModelsRaw = z . array ( modelConfig ) . parse ( JSON5 . parse ( rawEmbeddingModelJSON ) ) ;
46
47
48
+ const encryptEndpoints = ( endpoints : z . infer < typeof modelConfig > [ "endpoints" ] ) =>
49
+ endpoints . map ( ( endpoint ) => {
50
+ switch ( endpoint . type ) {
51
+ case "openai" :
52
+ return {
53
+ ...endpoint ,
54
+ apiKey : encrypt ( endpoint . apiKey ) ,
55
+ } ;
56
+ case "tei" :
57
+ return {
58
+ ...endpoint ,
59
+ authorization : endpoint . authorization && encrypt ( endpoint . authorization ) ,
60
+ } ;
61
+ case "hfapi" :
62
+ return {
63
+ ...endpoint ,
64
+ authorization : endpoint . authorization && encrypt ( endpoint . authorization ) ,
65
+ } ;
66
+ default :
67
+ return endpoint ;
68
+ }
69
+ } ) ;
70
+
47
71
const embeddingModels = embeddingModelsRaw . map ( ( rawEmbeddingModel ) => {
48
72
const embeddingModel : EmbeddingModel = {
49
73
name : rawEmbeddingModel . name ,
@@ -57,7 +81,7 @@ const embeddingModels = embeddingModelsRaw.map((rawEmbeddingModel) => {
57
81
_id : new ObjectId ( ) ,
58
82
createdAt : new Date ( ) ,
59
83
updatedAt : new Date ( ) ,
60
- endpoints : rawEmbeddingModel . endpoints ,
84
+ endpoints : encryptEndpoints ( rawEmbeddingModel . endpoints ) ,
61
85
} ;
62
86
63
87
return embeddingModel ;
@@ -79,7 +103,6 @@ export const getEmbeddingEndpoint = async (embeddingModel: EmbeddingModel) => {
79
103
for ( const endpoint of embeddingModel . endpoints ) {
80
104
if ( random < endpoint . weight ) {
81
105
const args = { ...endpoint , model : embeddingModel } ;
82
- console . log ( args . type ) ;
83
106
84
107
switch ( args . type ) {
85
108
case "tei" :
0 commit comments