Merge pull request '用户后台新增 AI 模型与价格目录' (#9) from codex/member-ai-models into main
Verify control plane / verify (push) Canceled after 0s
Verify control plane / verify (push) Canceled after 0s
Reviewed-on: http://git.xhmcl.com/xhgit/webup-cloud/pulls/9
This commit was merged in pull request #9.
This commit is contained in:
commit
d04777247b
6 files changed
+233
-4
No files matched your search
@@ -179,9 +179,9 @@ public class ModelController {
|
||||
private List<Map<String, Object>> models(boolean all) {
|
||||
return db.queryForList(
|
||||
"SELECT m.*,p.name AS provider_name,p.api_type,v.id AS"
|
||||
+ " price_version_id,v.input_price,v.output_price,v.cache_read_price,v.cache_write_price"
|
||||
+ " FROM ai_models m JOIN ai_providers p ON p.id=m.provider_id JOIN"
|
||||
+ " ai_model_price_versions v ON v.id=m.current_price_version "
|
||||
+ " price_version_id,v.input_price,v.output_price,v.cache_read_price,v.cache_write_price,"
|
||||
+ " v.created_at AS price_effective_at FROM ai_models m JOIN ai_providers p ON"
|
||||
+ " p.id=m.provider_id JOIN ai_model_price_versions v ON v.id=m.current_price_version "
|
||||
+ (all ? "" : "WHERE m.enabled=TRUE AND p.enabled=TRUE ")
|
||||
+ " ORDER BY m.created_at DESC");
|
||||
}
|
||||
|
||||
@@ -78,6 +78,76 @@ class ModelApiIntegrationTest {
|
||||
assertTrue(encrypted.startsWith("v1:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void memberCatalogShowsOnlyEnabledModelsAndTheCurrentPriceVersion() throws Exception {
|
||||
UUID enabledProvider = UUID.randomUUID(), disabledProvider = UUID.randomUUID();
|
||||
for (UUID provider : List.of(enabledProvider, disabledProvider)) {
|
||||
users
|
||||
.db()
|
||||
.update(
|
||||
"INSERT INTO"
|
||||
+ " ai_providers(id,name,base_url,api_type,encrypted_key,enabled,timeout_seconds)"
|
||||
+ " VALUES (?,?, 'https://api.openai.com/v1','OPENAI','private-fixture',?,30)",
|
||||
provider,
|
||||
provider.equals(enabledProvider) ? "Visible provider" : "Disabled provider",
|
||||
provider.equals(enabledProvider));
|
||||
}
|
||||
var settings =
|
||||
json.createObjectNode()
|
||||
.put("providerId", enabledProvider.toString())
|
||||
.put("name", "Catalog model")
|
||||
.put("modelId", "visible-model")
|
||||
.put("contextLength", 8192)
|
||||
.put("maxOutput", 1024)
|
||||
.put("enabled", true)
|
||||
.put("toolsEnabled", true)
|
||||
.put("visionEnabled", true)
|
||||
.put("inputPrice", 2)
|
||||
.put("outputPrice", 8)
|
||||
.put("cacheReadPrice", 1)
|
||||
.put("cacheWritePrice", 3);
|
||||
var visibleId =
|
||||
json.readTree(
|
||||
mvc.perform(
|
||||
post("/api/admin/models")
|
||||
.header("Authorization", "Bearer " + a)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(settings.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString())
|
||||
.path("id")
|
||||
.asText();
|
||||
for (var hidden :
|
||||
List.of(
|
||||
settings.deepCopy().put("modelId", "disabled-model").put("enabled", false),
|
||||
settings.deepCopy().put("providerId", disabledProvider.toString()))) {
|
||||
mvc.perform(
|
||||
post("/api/admin/models")
|
||||
.header("Authorization", "Bearer " + a)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(hidden.toString()))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
mvc.perform(
|
||||
put("/api/admin/models/" + visibleId)
|
||||
.header("Authorization", "Bearer " + a)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(settings.put("inputPrice", 5).toString()))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
mvc.perform(get("/api/models").header("Authorization", "Bearer " + u))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(1))
|
||||
.andExpect(jsonPath("$[0].provider_name").value("Visible provider"))
|
||||
.andExpect(jsonPath("$[0].input_price").value(5))
|
||||
.andExpect(jsonPath("$[0].cache_read_price").value(1))
|
||||
.andExpect(jsonPath("$[0].price_effective_at").isNotEmpty())
|
||||
.andExpect(jsonPath("$[0].encrypted_key").doesNotExist())
|
||||
.andExpect(jsonPath("$[0].base_url").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
void ordinaryUsersCannotAdjustWallets() throws Exception {
|
||||
mvc.perform(
|
||||
|
||||
Reference in new issue
Block a user