1+ package tech .amikos .chromadb .embeddings ;
2+
3+
4+ import tech .amikos .chromadb .Constants ;
5+ import tech .amikos .chromadb .EFException ;
6+
7+ import java .util .Map ;
8+
9+ public abstract class WithParam {
10+ public abstract void apply (Map <String , Object > params ) throws EFException ;
11+
12+ public static WithParam apiKey (String apiKey ) {
13+ return new WithAPIKey (apiKey );
14+ }
15+
16+ public static WithParam apiKeyFromEnv (String apiKeyEnvVarName ) {
17+ return new WithEnvAPIKey (apiKeyEnvVarName );
18+ }
19+
20+ public static WithParam model (String model ) {
21+ return new WithModel (model );
22+ }
23+
24+ public static WithParam modelFromEnv (String modelEnvVarName ) {
25+ return new WithModelFromEnv (modelEnvVarName );
26+ }
27+
28+ public static WithParam baseAPI (String baseAPI ) {
29+ return new WithBaseAPI (baseAPI );
30+ }
31+
32+ public static WithParam defaultModel (String model ) {
33+ return new WithDefaultModel (model );
34+ }
35+
36+
37+ }
38+
39+ class WithBaseAPI extends WithParam {
40+ private final String baseAPI ;
41+
42+ public WithBaseAPI (String baseAPI ) {
43+ this .baseAPI = baseAPI ;
44+ }
45+
46+ @ Override
47+ public void apply (Map <String , Object > params ) {
48+ params .put (Constants .EF_PARAMS_BASE_API , baseAPI );
49+ }
50+ }
51+
52+ class WithModel extends WithParam {
53+ private final String model ;
54+
55+ public WithModel (String model ) {
56+ this .model = model ;
57+ }
58+
59+ @ Override
60+ public void apply (Map <String , Object > params ) {
61+ params .put (Constants .EF_PARAMS_MODEL , model );
62+ }
63+ }
64+
65+ class WithModelFromEnv extends WithParam {
66+
67+ private String modelEnvVarName = Constants .MODEL_NAME ;
68+
69+ public WithModelFromEnv (String modelEnvVarName ) {
70+ this .modelEnvVarName = modelEnvVarName ;
71+ }
72+
73+ /**
74+ * Reads MODEL_NAME from the environment
75+ */
76+ public WithModelFromEnv () {
77+ }
78+
79+ @ Override
80+ public void apply (Map <String , Object > params ) throws EFException {
81+ if (System .getenv (modelEnvVarName ) == null ) {
82+ throw new EFException ("Model not found in environment variable: " + modelEnvVarName );
83+ }
84+ params .put (Constants .EF_PARAMS_MODEL , System .getenv (modelEnvVarName ));
85+ }
86+ }
87+
88+ class WithDefaultModel extends WithParam {
89+
90+ private final String model ;
91+
92+ public WithDefaultModel (String model ) {
93+ this .model = model ;
94+ }
95+
96+ @ Override
97+ public void apply (Map <String , Object > params ) {
98+ params .put (Constants .EF_PARAMS_MODEL , model );
99+ }
100+ }
101+
102+ class WithAPIKey extends WithParam {
103+ private final String apiKey ;
104+
105+ public WithAPIKey (String apiKey ) {
106+ this .apiKey = apiKey ;
107+ }
108+
109+ @ Override
110+ public void apply (Map <String , Object > params ) {
111+ params .put (Constants .EF_PARAMS_API_KEY , apiKey );
112+ }
113+ }
114+
115+ class WithEnvAPIKey extends WithParam {
116+ private final String apiKeyEnvVarName ;
117+
118+ public WithEnvAPIKey (String apiKeyEnvVarName ) {
119+ this .apiKeyEnvVarName = apiKeyEnvVarName ;
120+ }
121+
122+ @ Override
123+ public void apply (Map <String , Object > params ) throws EFException {
124+ if (System .getenv (apiKeyEnvVarName ) == null ) {
125+ throw new EFException ("API Key not found in environment variable: " + apiKeyEnvVarName );
126+ }
127+ params .put (Constants .EF_PARAMS_API_KEY_FROM_ENV , System .getenv (apiKeyEnvVarName ));
128+ }
129+ }
0 commit comments