|
1 | | -/* |
2 | | - * Copyright 2024-2026 the original author or authors. |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * https://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
15 | | - */ |
16 | | -package com.alibaba.cloud.ai.dataagent.mapper; |
17 | | - |
18 | | -import com.alibaba.cloud.ai.dataagent.entity.ModelConfig; |
19 | | -import org.apache.ibatis.annotations.*; |
20 | | - |
21 | | -import java.util.List; |
22 | | - |
23 | | -@Mapper |
24 | | -public interface ModelConfigMapper { |
25 | | - |
26 | | - @Select(""" |
27 | | - SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted FROM model_config WHERE is_deleted = 0 ORDER BY created_time DESC |
28 | | - """) |
29 | | - List<ModelConfig> findAll(); |
30 | | - |
31 | | - @Select(""" |
32 | | - SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted FROM model_config WHERE id = #{id} AND is_deleted = 0 |
33 | | - """) |
34 | | - ModelConfig findById(Integer id); |
35 | | - |
36 | | - @Select("SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted FROM model_config WHERE model_type = #{modelType} AND is_active = 1 AND is_deleted = 0 LIMIT 1") |
37 | | - ModelConfig selectActiveByType(@Param("modelType") String modelType); |
38 | | - |
39 | | - @Update("UPDATE model_config SET is_active = 0 WHERE model_type = #{modelType} AND id != #{currentId} AND is_deleted = 0") |
40 | | - void deactivateOthers(@Param("modelType") String modelType, @Param("currentId") Integer currentId); |
41 | | - |
42 | | - @Select(""" |
43 | | - <script> |
44 | | - SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted FROM model_config |
45 | | - <where> |
46 | | - is_deleted = 0 |
47 | | - <if test='provider != null and provider != ""'> |
48 | | - AND provider = #{provider} |
49 | | - </if> |
50 | | - <if test='keyword != null and keyword != ""'> |
51 | | - AND (provider LIKE CONCAT('%', #{keyword}, '%') |
52 | | - OR base_url LIKE CONCAT('%', #{keyword}, '%') |
53 | | - OR model_name LIKE CONCAT('%', #{keyword}, '%')) |
54 | | - </if> |
55 | | - <if test='isActive != null'> |
56 | | - AND is_active = #{isActive} |
57 | | - </if> |
58 | | - <if test='maxTokens != null'> |
59 | | - AND max_tokens = #{maxTokens} |
60 | | - </if> |
61 | | - <if test='modelType != null'> |
62 | | - AND model_type = #{modelType} |
63 | | - </if> |
64 | | - </where> |
65 | | - ORDER BY created_time DESC |
66 | | - </script> |
67 | | - """) |
68 | | - List<ModelConfig> findByConditions(@Param("provider") String provider, @Param("keyword") String keyword, |
69 | | - @Param("isActive") Boolean isActive, @Param("maxTokens") Integer maxTokens, |
70 | | - @Param("modelType") String modelType); |
71 | | - |
72 | | - @Insert(""" |
73 | | - INSERT INTO model_config (provider, base_url, api_key, model_name, temperature, is_active, max_tokens, model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted) |
74 | | - VALUES (#{provider}, #{baseUrl}, #{apiKey}, #{modelName}, #{temperature}, #{isActive}, #{maxTokens}, #{modelType}, #{completionsPath}, #{embeddingsPath}, NOW(), NOW(), 0) |
75 | | - """) |
76 | | - @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") |
77 | | - int insert(ModelConfig modelConfig); |
78 | | - |
79 | | - @Update(""" |
80 | | - <script> |
81 | | - UPDATE model_config |
82 | | - <trim prefix="SET" suffixOverrides=","> |
83 | | - <if test='provider != null'>provider = #{provider},</if> |
84 | | - <if test='baseUrl != null'>base_url = #{baseUrl},</if> |
85 | | - <if test='apiKey != null'>api_key = #{apiKey},</if> |
86 | | - <if test='modelName != null'>model_name = #{modelName},</if> |
87 | | - <if test='temperature != null'>temperature = #{temperature},</if> |
88 | | - <if test='isActive != null'>is_active = #{isActive},</if> |
89 | | - <if test='maxTokens != null'>max_tokens = #{maxTokens},</if> |
90 | | - <if test='modelType != null'>model_type = #{modelType},</if> |
91 | | - <if test='completionsPath != null'>completions_path = #{completionsPath},</if> |
92 | | - <if test='embeddingsPath != null'>embeddings_path = #{embeddingsPath},</if> |
93 | | - <if test='isDeleted != null'>is_deleted = #{isDeleted},</if> |
94 | | - updated_time = NOW() |
95 | | - </trim> |
96 | | - WHERE id = #{id} |
97 | | - </script> |
98 | | - """) |
99 | | - int updateById(ModelConfig modelConfig); |
100 | | - |
101 | | - @Update(""" |
102 | | - UPDATE model_config SET is_deleted = 1 WHERE id = #{id} |
103 | | - """) |
104 | | - int deleteById(Integer id); |
105 | | - |
106 | | -} |
| 1 | +/* |
| 2 | + * Copyright 2024-2026 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.alibaba.cloud.ai.dataagent.mapper; |
| 17 | + |
| 18 | +import com.alibaba.cloud.ai.dataagent.entity.ModelConfig; |
| 19 | +import org.apache.ibatis.annotations.*; |
| 20 | + |
| 21 | +import java.util.List; |
| 22 | + |
| 23 | +@Mapper |
| 24 | +public interface ModelConfigMapper { |
| 25 | + |
| 26 | + @Select(""" |
| 27 | + SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, |
| 28 | + model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted, |
| 29 | + proxy_enabled, proxy_host, proxy_port, proxy_username, proxy_password |
| 30 | + FROM model_config WHERE is_deleted = 0 ORDER BY created_time DESC |
| 31 | + """) |
| 32 | + List<ModelConfig> findAll(); |
| 33 | + |
| 34 | + @Select(""" |
| 35 | + SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, |
| 36 | + model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted, |
| 37 | + proxy_enabled, proxy_host, proxy_port, proxy_username, proxy_password |
| 38 | + FROM model_config WHERE id = #{id} AND is_deleted = 0 |
| 39 | + """) |
| 40 | + ModelConfig findById(Integer id); |
| 41 | + |
| 42 | + @Select(""" |
| 43 | + SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, |
| 44 | + model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted, |
| 45 | + proxy_enabled, proxy_host, proxy_port, proxy_username, proxy_password |
| 46 | + FROM model_config WHERE model_type = #{modelType} AND is_active = 1 AND is_deleted = 0 LIMIT 1 |
| 47 | + """) |
| 48 | + ModelConfig selectActiveByType(@Param("modelType") String modelType); |
| 49 | + |
| 50 | + @Update("UPDATE model_config SET is_active = 0 WHERE model_type = #{modelType} AND id != #{currentId} AND is_deleted = 0") |
| 51 | + void deactivateOthers(@Param("modelType") String modelType, @Param("currentId") Integer currentId); |
| 52 | + |
| 53 | + @Select(""" |
| 54 | + <script> |
| 55 | + SELECT id, provider, base_url, api_key, model_name, temperature, is_active, max_tokens, |
| 56 | + model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted, |
| 57 | + proxy_enabled, proxy_host, proxy_port, proxy_username, proxy_password |
| 58 | + FROM model_config |
| 59 | + <where> |
| 60 | + is_deleted = 0 |
| 61 | + <if test='provider != null and provider != ""'> |
| 62 | + AND provider = #{provider} |
| 63 | + </if> |
| 64 | + <if test='keyword != null and keyword != ""'> |
| 65 | + AND (provider LIKE CONCAT('%', #{keyword}, '%') |
| 66 | + OR base_url LIKE CONCAT('%', #{keyword}, '%') |
| 67 | + OR model_name LIKE CONCAT('%', #{keyword}, '%')) |
| 68 | + </if> |
| 69 | + <if test='isActive != null'> |
| 70 | + AND is_active = #{isActive} |
| 71 | + </if> |
| 72 | + <if test='maxTokens != null'> |
| 73 | + AND max_tokens = #{maxTokens} |
| 74 | + </if> |
| 75 | + <if test='modelType != null'> |
| 76 | + AND model_type = #{modelType} |
| 77 | + </if> |
| 78 | + </where> |
| 79 | + ORDER BY created_time DESC |
| 80 | + </script> |
| 81 | + """) |
| 82 | + List<ModelConfig> findByConditions(@Param("provider") String provider, @Param("keyword") String keyword, |
| 83 | + @Param("isActive") Boolean isActive, @Param("maxTokens") Integer maxTokens, |
| 84 | + @Param("modelType") String modelType); |
| 85 | + |
| 86 | + @Insert(""" |
| 87 | + INSERT INTO model_config (provider, base_url, api_key, model_name, temperature, is_active, max_tokens, |
| 88 | + model_type, completions_path, embeddings_path, created_time, updated_time, is_deleted, |
| 89 | + proxy_enabled, proxy_host, proxy_port, proxy_username, proxy_password) |
| 90 | + VALUES (#{provider}, #{baseUrl}, #{apiKey}, #{modelName}, #{temperature}, #{isActive}, #{maxTokens}, |
| 91 | + #{modelType}, #{completionsPath}, #{embeddingsPath}, NOW(), NOW(), 0, |
| 92 | + #{proxyEnabled}, #{proxyHost}, #{proxyPort}, #{proxyUsername}, #{proxyPassword}) |
| 93 | + """) |
| 94 | + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") |
| 95 | + int insert(ModelConfig modelConfig); |
| 96 | + |
| 97 | + @Update(""" |
| 98 | + <script> |
| 99 | + UPDATE model_config |
| 100 | + <trim prefix="SET" suffixOverrides=","> |
| 101 | + <if test='provider != null'>provider = #{provider},</if> |
| 102 | + <if test='baseUrl != null'>base_url = #{baseUrl},</if> |
| 103 | + <if test='apiKey != null'>api_key = #{apiKey},</if> |
| 104 | + <if test='modelName != null'>model_name = #{modelName},</if> |
| 105 | + <if test='temperature != null'>temperature = #{temperature},</if> |
| 106 | + <if test='isActive != null'>is_active = #{isActive},</if> |
| 107 | + <if test='maxTokens != null'>max_tokens = #{maxTokens},</if> |
| 108 | + <if test='modelType != null'>model_type = #{modelType},</if> |
| 109 | + <if test='completionsPath != null'>completions_path = #{completionsPath},</if> |
| 110 | + <if test='embeddingsPath != null'>embeddings_path = #{embeddingsPath},</if> |
| 111 | + <if test='isDeleted != null'>is_deleted = #{isDeleted},</if> |
| 112 | + <if test='proxyEnabled != null'>proxy_enabled = #{proxyEnabled},</if> |
| 113 | + <if test='proxyHost != null'>proxy_host = #{proxyHost},</if> |
| 114 | + <if test='proxyPort != null'>proxy_port = #{proxyPort},</if> |
| 115 | + <if test='proxyUsername != null'>proxy_username = #{proxyUsername},</if> |
| 116 | + <if test='proxyPassword != null'>proxy_password = #{proxyPassword},</if> |
| 117 | + updated_time = NOW() |
| 118 | + </trim> |
| 119 | + WHERE id = #{id} |
| 120 | + </script> |
| 121 | + """) |
| 122 | + int updateById(ModelConfig modelConfig); |
| 123 | + |
| 124 | + @Update(""" |
| 125 | + UPDATE model_config SET is_deleted = 1 WHERE id = #{id} |
| 126 | + """) |
| 127 | + int deleteById(Integer id); |
| 128 | + |
| 129 | +} |
0 commit comments