|
1 | 1 | import {
|
2 | 2 | DEFAULT_LLM_PRIORITY,
|
| 3 | + DEFAULT_MODEL, |
| 4 | + getValidLanguageModelName, |
| 5 | + isCoreLanguageModel, |
3 | 6 | isFreeModel,
|
4 | 7 | LANGUAGE_MODEL_SERVICES,
|
5 | 8 | LANGUAGE_MODELS,
|
| 9 | + LanguageService, |
6 | 10 | LLM_COST,
|
| 11 | + LLMServicesAvailable, |
7 | 12 | model2vendor,
|
8 | 13 | OLLAMA_PREFIX,
|
9 | 14 | SERVICES,
|
@@ -83,4 +88,64 @@ describe("llm", () => {
|
83 | 88 | expect(prio.includes(v)).toBe(true);
|
84 | 89 | }
|
85 | 90 | });
|
| 91 | + |
| 92 | + test("getting valid language model", () => { |
| 93 | + const selectable_llms = [...USER_SELECTABLE_LANGUAGE_MODELS]; |
| 94 | + const notAvailable = selectable_llms.pop(); |
| 95 | + |
| 96 | + function getModel(model: LanguageService, disabled?: LanguageService) { |
| 97 | + const allEnabled = LANGUAGE_MODEL_SERVICES.reduce((acc, svc) => { |
| 98 | + acc[svc] = disabled !== svc; |
| 99 | + return acc; |
| 100 | + }, {}) as LLMServicesAvailable; |
| 101 | + return getValidLanguageModelName({ |
| 102 | + model, |
| 103 | + filter: allEnabled, |
| 104 | + ollama: ["phi3"], |
| 105 | + custom_openai: ["bar"], |
| 106 | + selectable_llms, |
| 107 | + }); |
| 108 | + } |
| 109 | + |
| 110 | + // meaningless name |
| 111 | + expect(getModel("foobar")).toEqual(DEFAULT_MODEL); |
| 112 | + expect(getModel("baz-delta99")).toEqual(DEFAULT_MODEL); |
| 113 | + // gpt 3.5 is disabled |
| 114 | + expect(getModel("gpt-3.5-turbo")).toEqual(DEFAULT_MODEL); |
| 115 | + // not available |
| 116 | + expect( |
| 117 | + typeof notAvailable === "string" && isCoreLanguageModel(notAvailable), |
| 118 | + ).toBe(true); |
| 119 | + if (typeof notAvailable === "string") { |
| 120 | + expect(getModel(notAvailable)).toEqual(DEFAULT_MODEL); |
| 121 | + } |
| 122 | + // not disabled |
| 123 | + expect(getModel("mistral-large-latest")).toEqual("mistral-large-latest"); |
| 124 | + expect(getModel("gpt-4")).toEqual("gpt-4"); |
| 125 | + expect(getModel(DEFAULT_MODEL)).toEqual(DEFAULT_MODEL); |
| 126 | + expect(getModel("mistral-medium-latest")).toEqual(DEFAULT_MODEL); |
| 127 | + expect(getModel("mistral-large-latest")).toEqual("mistral-large-latest"); |
| 128 | + expect(getModel("claude-3-haiku-8k")).toEqual("claude-3-haiku-8k"); |
| 129 | + // anthropic service disabled |
| 130 | + expect(getModel("claude-3-haiku-8k", "anthropic")).toEqual(DEFAULT_MODEL); |
| 131 | + // ollama |
| 132 | + expect(getModel("ollama-foo")).toEqual(DEFAULT_MODEL); |
| 133 | + expect(getModel("ollama-phi3")).toEqual("ollama-phi3"); |
| 134 | + // openai api |
| 135 | + expect(getModel("custom_openai-foo")).toEqual(DEFAULT_MODEL); |
| 136 | + expect(getModel("custom_openai-bar")).toEqual("custom_openai-bar"); |
| 137 | + // user models: there are no further checks |
| 138 | + expect(getModel("user-custom_openai-foo")).toEqual( |
| 139 | + "user-custom_openai-foo", |
| 140 | + ); |
| 141 | + expect(getModel("user-openai-gpt-3.5-turbo")).toEqual( |
| 142 | + "user-openai-gpt-3.5-turbo", |
| 143 | + ); |
| 144 | + // it's ok to use a model if disabled by the admin, since it's their key |
| 145 | + expect(getModel("user-anthropic-claude-3-haiku-8k", "anthropic")).toEqual( |
| 146 | + "user-anthropic-claude-3-haiku-8k", |
| 147 | + ); |
| 148 | + // meaningless user service |
| 149 | + expect(getModel("user-baz-delta99")).toEqual(DEFAULT_MODEL); |
| 150 | + }); |
86 | 151 | });
|
0 commit comments