uses explicitly set keyprovider rather than inferring via requested model

This commit is contained in:
nai-degen 2024-02-27 10:56:40 -06:00
parent 627559b729
commit bd15728743
5 changed files with 11 additions and 11 deletions

View File

@ -23,16 +23,16 @@ export const addKey: HPMRequestCallback = (proxyReq, req) => {
}
if (req.inboundApi === req.outboundApi) {
assignedKey = keyPool.get(req.body.model);
assignedKey = keyPool.get(req.body.model, req.service);
} else {
switch (req.outboundApi) {
// If we are translating between API formats we may need to select a model
// for the user, because the provided model is for the inbound API.
case "anthropic":
assignedKey = keyPool.get("claude-v1");
assignedKey = keyPool.get("claude-v1", req.service);
break;
case "openai-text":
assignedKey = keyPool.get("gpt-3.5-turbo-instruct");
assignedKey = keyPool.get("gpt-3.5-turbo-instruct", req.service);
break;
case "openai":
throw new Error(
@ -43,7 +43,7 @@ export const addKey: HPMRequestCallback = (proxyReq, req) => {
case "mistral-ai":
throw new Error("Mistral AI should never be translated");
case "openai-image":
assignedKey = keyPool.get("dall-e-3");
assignedKey = keyPool.get("dall-e-3", req.service);
break;
default:
assertNever(req.outboundApi);
@ -106,7 +106,7 @@ export const addKeyForEmbeddingsRequest: HPMRequestCallback = (
req.body = { input: req.body.input, model: "text-embedding-ada-002" };
const key = keyPool.get("text-embedding-ada-002") as OpenAIKey;
const key = keyPool.get("text-embedding-ada-002", "openai") as OpenAIKey;
req.key = key;
req.log.info(

View File

@ -16,7 +16,7 @@ export const addAzureKey: RequestPreprocessor = (req) => {
? req.body.model
: `azure-${req.body.model}`;
req.key = keyPool.get(model);
req.key = keyPool.get(model, "azure");
req.body.model = model;
// Handles the sole Azure API deviation from the OpenAI spec (that I know of)

View File

@ -13,7 +13,7 @@ export const addGoogleAIKey: RequestPreprocessor = (req) => {
}
const model = req.body.model;
req.key = keyPool.get(model);
req.key = keyPool.get(model, "google-ai");
req.log.info(
{ key: req.key.hash, model },

View File

@ -14,7 +14,7 @@ const AMZ_HOST =
* request object in place to fix the path.
*/
export const signAwsRequest: RequestPreprocessor = async (req) => {
req.key = keyPool.get("anthropic.claude-v2");
req.key = keyPool.get("anthropic.claude-v2", "aws");
const { model, stream } = req.body;
req.isStreaming = stream === true || stream === "true";

View File

@ -41,9 +41,9 @@ export class KeyPool {
this.scheduleRecheck();
}
public get(model: Model): Key {
const service = this.getServiceForModel(model);
return this.getKeyProvider(service).get(model);
public get(model: Model, service?: LLMService): Key {
const queryService = service || this.getServiceForModel(model);
return this.getKeyProvider(queryService).get(model);
}
public list(): Omit<Key, "key">[] {