-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fallback to other saved providers if default is not there
- Loading branch information
1 parent
efe0731
commit 8a08447
Showing
3 changed files
with
128 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
app/src/store/playground/__tests__/playgroundStore.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { | ||
DEFAULT_MODEL_NAME, | ||
DEFAULT_MODEL_PROVIDER, | ||
} from "@phoenix/constants/generativeConstants"; | ||
|
||
import { | ||
_resetInstanceId, | ||
createPlaygroundInstance, | ||
getInitialInstances, | ||
} from "../playgroundStore"; | ||
import { InitialPlaygroundState } from "../types"; | ||
|
||
describe("getInitialInstances", () => { | ||
beforeEach(() => { | ||
_resetInstanceId(); | ||
}); | ||
it("should return instances from initialProps if they exist", () => { | ||
const existingInstance = { | ||
...createPlaygroundInstance(), | ||
model: { | ||
modelName: "test-model", | ||
provider: "OPENAI" as const, | ||
invocationParameters: {}, | ||
}, | ||
}; | ||
const initialProps: InitialPlaygroundState = { | ||
instances: [existingInstance], | ||
modelConfigByProvider: {}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toEqual([existingInstance]); | ||
}); | ||
|
||
it("should create a new default instance if no instances exist in initialProps and there are no saved modelConfigs", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: {}, | ||
}; | ||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].id).toBe(0); | ||
expect(instances[0].model.provider).toBe(DEFAULT_MODEL_PROVIDER); | ||
expect(instances[0].model.modelName).toBe(DEFAULT_MODEL_NAME); | ||
}); | ||
|
||
it("should use saved model config if available", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: { | ||
OPENAI: { | ||
modelName: "test-model", | ||
provider: "OPENAI", | ||
invocationParameters: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].model.provider).toBe("OPENAI"); | ||
expect(instances[0].model.modelName).toBe("test-model"); | ||
}); | ||
|
||
it("should use default model provider config if available", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: { | ||
OPENAI: { | ||
modelName: "test-model-openai", | ||
provider: "OPENAI", | ||
invocationParameters: {}, | ||
}, | ||
ANTHROPIC: { | ||
modelName: "test-model-anthropic", | ||
provider: "ANTHROPIC", | ||
invocationParameters: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].model.provider).toBe("OPENAI"); | ||
expect(instances[0].model.modelName).toBe("test-model-openai"); | ||
}); | ||
|
||
it("should use any saved config if available if the default provider config is not", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: { | ||
ANTHROPIC: { | ||
modelName: "test-model-anthropic", | ||
provider: "ANTHROPIC", | ||
invocationParameters: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].model.provider).toBe("ANTHROPIC"); | ||
expect(instances[0].model.modelName).toBe("test-model-anthropic"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters