MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / applySync

Function applySync

web/src/pages/Setting/Ratio/UpstreamRatioSync.js:224–290  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

222 }, [setResolutions]);
223
224 const applySync = async () => {
225 const currentRatios = {
226 ModelRatio: JSON.parse(props.options.ModelRatio || '{}'),
227 CompletionRatio: JSON.parse(props.options.CompletionRatio || '{}'),
228 CacheRatio: JSON.parse(props.options.CacheRatio || '{}'),
229 ModelPrice: JSON.parse(props.options.ModelPrice || '{}'),
230 };
231
232 const conflicts = [];
233
234 const getLocalBillingCategory = (model) => {
235 if (currentRatios.ModelPrice[model] !== undefined) return 'price';
236 if (currentRatios.ModelRatio[model] !== undefined ||
237 currentRatios.CompletionRatio[model] !== undefined ||
238 currentRatios.CacheRatio[model] !== undefined) return 'ratio';
239 return null;
240 };
241
242 const findSourceChannel = (model, ratioType, value) => {
243 if (differences[model] && differences[model][ratioType]) {
244 const upMap = differences[model][ratioType].upstreams || {};
245 const entry = Object.entries(upMap).find(([_, v]) => v === value);
246 if (entry) return entry[0];
247 }
248 return t('未知');
249 };
250
251 Object.entries(resolutions).forEach(([model, ratios]) => {
252 const localCat = getLocalBillingCategory(model);
253 const newCat = 'model_price' in ratios ? 'price' : 'ratio';
254
255 if (localCat && localCat !== newCat) {
256 const currentDesc = localCat === 'price'
257 ? `${t('固定价格')} : ${currentRatios.ModelPrice[model]}`
258 : `${t('模型倍率')} : ${currentRatios.ModelRatio[model] ?? '-'}\n${t('补全倍率')} : ${currentRatios.CompletionRatio[model] ?? '-'}`;
259
260 let newDesc = '';
261 if (newCat === 'price') {
262 newDesc = `${t('固定价格')} : ${ratios['model_price']}`;
263 } else {
264 const newModelRatio = ratios['model_ratio'] ?? '-';
265 const newCompRatio = ratios['completion_ratio'] ?? '-';
266 newDesc = `${t('模型倍率')} : ${newModelRatio}\n${t('补全倍率')} : ${newCompRatio}`;
267 }
268
269 const channels = Object.entries(ratios)
270 .map(([rt, val]) => findSourceChannel(model, rt, val))
271 .filter((v, idx, arr) => arr.indexOf(v) === idx)
272 .join(', ');
273
274 conflicts.push({
275 channel: channels,
276 model,
277 current: currentDesc,
278 newVal: newDesc,
279 });
280 }
281 });

Callers

nothing calls this directly

Calls 3

getLocalBillingCategoryFunction · 0.85
findSourceChannelFunction · 0.85
tFunction · 0.70

Tested by

no test coverage detected