method in config-yaml to parse proxy model name
This commit is contained in:
parent
f908cb159f
commit
860fb83906
3 changed files with 63 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ export * from "./load/merge.js";
|
|||
export * from "./load/proxySecretResolution.js";
|
||||
export * from "./load/typeGuards.js";
|
||||
export * from "./load/unroll.js";
|
||||
export * from "./modelName.js";
|
||||
export * from "./registryClient.js";
|
||||
export * from "./schemas/data/index.js";
|
||||
export * from "./schemas/index.js";
|
||||
|
|
|
|||
43
packages/config-yaml/src/modelName.test.ts
Normal file
43
packages/config-yaml/src/modelName.test.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { parseProxyModelName } from "./modelName.js";
|
||||
|
||||
describe("parseProxyModelName", () => {
|
||||
it("parses a basic model name correctly", () => {
|
||||
const result = parseProxyModelName("owner/package/provider/model");
|
||||
expect(result).toEqual({
|
||||
ownerSlug: "owner",
|
||||
packageSlug: "package",
|
||||
provider: "provider",
|
||||
model: "model",
|
||||
});
|
||||
});
|
||||
|
||||
it("handles model names with slashes in the model part", () => {
|
||||
const result = parseProxyModelName(
|
||||
"owner/package/provider/model/with/slashes",
|
||||
);
|
||||
expect(result).toEqual({
|
||||
ownerSlug: "owner",
|
||||
packageSlug: "package",
|
||||
provider: "provider",
|
||||
model: "model/with/slashes",
|
||||
});
|
||||
});
|
||||
|
||||
it("throws an error for invalid model formats (missing provider)", () => {
|
||||
expect(() => {
|
||||
parseProxyModelName("owner/package");
|
||||
}).toThrow("Invalid model format");
|
||||
});
|
||||
|
||||
it("throws an error for invalid model formats (missing model)", () => {
|
||||
expect(() => {
|
||||
parseProxyModelName("owner/package/provider");
|
||||
}).toThrow("Invalid model format");
|
||||
});
|
||||
|
||||
it("throws an error for empty string", () => {
|
||||
expect(() => {
|
||||
parseProxyModelName("");
|
||||
}).toThrow("Invalid model format");
|
||||
});
|
||||
});
|
||||
19
packages/config-yaml/src/modelName.ts
Normal file
19
packages/config-yaml/src/modelName.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export interface ProxyModelName {
|
||||
ownerSlug: string;
|
||||
packageSlug: string;
|
||||
provider: string;
|
||||
model: string;
|
||||
}
|
||||
|
||||
export function parseProxyModelName(modelName: string): ProxyModelName {
|
||||
const parts = modelName.split("/");
|
||||
|
||||
const [ownerSlug, packageSlug, provider, ...modelParts] = parts;
|
||||
const model = modelParts.join("/");
|
||||
|
||||
if (!provider || !model) {
|
||||
throw new Error("Invalid model format");
|
||||
}
|
||||
|
||||
return { provider, model, ownerSlug, packageSlug };
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue