import type * as Provider from "./provider"
import { Flag } from "@saeeol/core/flag/flag"
import { isLing } from "@/saeeol/model-match"

export const OUTPUT_TOKEN_MAX = Flag.SAEEOL_EXPERIMENTAL_OUTPUT_TOKEN_MAX || 32_000

export function temperature(model: Provider.Model) {
  const id = model.id.toLowerCase()
  if (id.includes("qwen")) return 0.55
  if (id.includes("claude")) return undefined
  if (id.includes("gemini")) return 1.0
  if (id.includes("glm-4.6")) return 1.0
  if (id.includes("glm-4.7")) return 1.0
  if (id.includes("minimax-m2")) return 1.0
  if (id.includes("kimi-k2")) {
    if (["thinking", "k2.", "k2p", "k2-5"].some((s) => id.includes(s))) return 1.0
    return 0.6
  }
  if (isLing(model.api.id)) return 0.3
  return undefined
}

export function topP(model: Provider.Model) {
  const id = model.id.toLowerCase()
  if (id.includes("qwen")) return 1
  if (["minimax-m2", "gemini", "kimi-k2.5", "kimi-k2p5", "kimi-k2-5"].some((s) => id.includes(s))) return 0.95
  if (isLing(model.api.id)) return 0.95
  return undefined
}

export function topK(model: Provider.Model) {
  const id = model.id.toLowerCase()
  if (id.includes("minimax-m2")) { if (["m2.", "m25", "m21"].some((s) => id.includes(s))) return 40; return 20 }
  if (id.includes("gemini")) return 64
  if (isLing(model.api.id)) return 20
  return undefined
}
