Skip to content

Commit f6e7469

Browse files
committed
Fix for when API_KEY is not needed
1 parent e54040d commit f6e7469

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/server/api/utils/models.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,19 @@ def get_client(model_config: dict, oci_config: schema.OracleCloudSettings, giska
9999
k: full_model_config.get(k) for k in ["frequency_penalty", "presence_penalty", "top_p", "streaming"]
100100
}
101101
if provider != "oci":
102-
client = init_chat_model(
103-
model_provider="openai" if provider == "openai_compatible" else provider,
104-
model=full_model_config["id"],
105-
base_url=full_model_config["url"],
106-
api_key=full_model_config["api_key"] or "not_required",
107-
temperature=full_model_config["temperature"],
108-
max_tokens=full_model_config["max_completion_tokens"],
102+
kwargs = {
103+
"model_provider": "openai" if provider == "openai_compatible" else provider,
104+
"model": full_model_config["id"],
105+
"base_url": full_model_config["url"],
106+
"temperature": full_model_config["temperature"],
107+
"max_tokens": full_model_config["max_completion_tokens"],
109108
**common_params,
110-
)
109+
}
110+
111+
if full_model_config.get("api_key"): # only add if present
112+
kwargs["api_key"] = full_model_config["api_key"]
113+
114+
client = init_chat_model(**kwargs)
111115
else:
112116
client = ChatOCIGenAI(
113117
model_id=full_model_config["id"],
@@ -122,12 +126,14 @@ def get_client(model_config: dict, oci_config: schema.OracleCloudSettings, giska
122126

123127
if full_model_config["type"] == "embed" and not giskard:
124128
if provider != "oci":
125-
client = init_embeddings(
126-
provider="openai" if provider == "openai_compatible" else provider,
127-
model=full_model_config["id"],
128-
base_url=full_model_config["url"],
129-
api_key=full_model_config["api_key"] or "not_required",
130-
)
129+
kwargs = {
130+
"provider": "openai" if provider == "openai_compatible" else provider,
131+
"model": full_model_config["id"],
132+
"base_url": full_model_config["url"],
133+
}
134+
if full_model_config.get("api_key"): # only add if set
135+
kwargs["api_key"] = full_model_config["api_key"]
136+
client = init_embeddings(**kwargs)
131137
else:
132138
client = OCIGenAIEmbeddings(
133139
model_id=full_model_config["id"],

0 commit comments

Comments
 (0)