MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / applyUserDefinedModel

Function applyUserDefinedModel

internal/thinking/apply.go:322–384  ·  view source on GitHub ↗

applyUserDefinedModel applies thinking configuration for user-defined models without ThinkingSupport validation.

(body []byte, modelInfo *registry.ModelInfo, fromFormat, toFormat string, suffixResult SuffixResult)

Source from the content-addressed store, hash-verified

320// applyUserDefinedModel applies thinking configuration for user-defined models
321// without ThinkingSupport validation.
322func applyUserDefinedModel(body []byte, modelInfo *registry.ModelInfo, fromFormat, toFormat string, suffixResult SuffixResult) ([]byte, error) {
323 // Get model ID for logging
324 modelID := ""
325 if modelInfo != nil {
326 modelID = modelInfo.ID
327 } else {
328 modelID = suffixResult.ModelName
329 }
330
331 // Get config: suffix priority over body
332 var config ThinkingConfig
333 if suffixResult.HasSuffix {
334 config = parseSuffixToConfig(suffixResult.RawSuffix, toFormat, modelID)
335 log.WithFields(log.Fields{
336 "provider": toFormat,
337 "model": modelID,
338 "mode": config.Mode,
339 "budget": config.Budget,
340 "level": config.Level,
341 }).Debug("thinking: config from model suffix |")
342 } else {
343 config = extractThinkingConfig(body, fromFormat)
344 if !hasThinkingConfig(config) && fromFormat != toFormat {
345 config = extractThinkingConfig(body, toFormat)
346 }
347 if hasThinkingConfig(config) {
348 log.WithFields(log.Fields{
349 "provider": toFormat,
350 "model": modelID,
351 "mode": config.Mode,
352 "budget": config.Budget,
353 "level": config.Level,
354 }).Debug("thinking: original config from request |")
355 }
356 }
357
358 if !hasThinkingConfig(config) {
359 log.WithFields(log.Fields{
360 "model": modelID,
361 "provider": toFormat,
362 }).Debug("thinking: user-defined model, passthrough (no config) |")
363 return body, nil
364 }
365
366 applier := GetProviderApplier(toFormat)
367 if applier == nil {
368 log.WithFields(log.Fields{
369 "model": modelID,
370 "provider": toFormat,
371 }).Debug("thinking: user-defined model, passthrough (unknown provider) |")
372 return body, nil
373 }
374
375 config = normalizeUserDefinedConfig(config, fromFormat, toFormat)
376 log.WithFields(log.Fields{
377 "provider": toFormat,
378 "model": modelID,
379 "mode": config.Mode,

Callers 1

ApplyThinkingFunction · 0.85

Calls 6

parseSuffixToConfigFunction · 0.85
extractThinkingConfigFunction · 0.85
hasThinkingConfigFunction · 0.85
GetProviderApplierFunction · 0.85
ApplyMethod · 0.65

Tested by

no test coverage detected