applyCompatibleKimi applies thinking config for user-defined Kimi models.
(body []byte, config thinking.ThinkingConfig)
| 96 | |
| 97 | // applyCompatibleKimi applies thinking config for user-defined Kimi models. |
| 98 | func applyCompatibleKimi(body []byte, config thinking.ThinkingConfig) ([]byte, error) { |
| 99 | if len(body) == 0 || !gjson.ValidBytes(body) { |
| 100 | body = []byte(`{}`) |
| 101 | } |
| 102 | |
| 103 | var effort string |
| 104 | switch config.Mode { |
| 105 | case thinking.ModeLevel: |
| 106 | if config.Level == "" { |
| 107 | return body, nil |
| 108 | } |
| 109 | effort = string(config.Level) |
| 110 | case thinking.ModeNone: |
| 111 | if config.Level == "" || config.Level == thinking.LevelNone { |
| 112 | return applyDisabledThinking(body) |
| 113 | } |
| 114 | if config.Level != "" { |
| 115 | effort = string(config.Level) |
| 116 | } |
| 117 | case thinking.ModeAuto: |
| 118 | effort = string(thinking.LevelAuto) |
| 119 | case thinking.ModeBudget: |
| 120 | // Convert budget to level |
| 121 | level, ok := thinking.ConvertBudgetToLevel(config.Budget) |
| 122 | if !ok { |
| 123 | return body, nil |
| 124 | } |
| 125 | effort = level |
| 126 | default: |
| 127 | return body, nil |
| 128 | } |
| 129 | |
| 130 | return applyReasoningEffort(body, effort) |
| 131 | } |
| 132 | |
| 133 | func applyReasoningEffort(body []byte, effort string) ([]byte, error) { |
| 134 | result, errDeleteThinking := sjson.DeleteBytes(body, "thinking") |
no test coverage detected