西藏巴青项目

llm.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * 大模型网关(对齐 ruoyi-ui/.env.development、vue.config.js)
  3. *
  4. * - H5 开发:请求同源 /llm-dev-proxy,由 vite devServer 转发到 LLM_PROXY_TARGET,避免 CORS 预检 OPTIONS 无 Authorization 被网关 401
  5. * - H5 生产 / App / 小程序:直连 LLM_PROXY_TARGET
  6. */
  7. export const LLM_API_KEY = 'yak_4dd329d945aa964baaee006118ef82f6'
  8. /** 真实网关根地址(与 ruoyi-ui LLM_PROXY_TARGET 一致) */
  9. export const LLM_PROXY_TARGET = 'http://harrison1.iask.in:9107'
  10. /**
  11. * H5 开发是否走 /llm-dev-proxy(需 vite.config.js 配置转发)
  12. */
  13. export const H5_LLM_USE_PROXY = true
  14. /** 开发代理路径前缀(与 ruoyi-ui VUE_APP_LLM_BASE_URL 开发值一致) */
  15. export const LLM_DEV_PROXY_PREFIX = '/llm-dev-proxy'
  16. export function getLlmBaseUrl() {
  17. const target = String(LLM_PROXY_TARGET || '').replace(/\/$/, '')
  18. // #ifdef H5
  19. if (H5_LLM_USE_PROXY && typeof import.meta !== 'undefined' && import.meta.env && import.meta.env.DEV) {
  20. return LLM_DEV_PROXY_PREFIX
  21. }
  22. // #endif
  23. return target
  24. }
  25. /** @deprecated 请使用 getLlmBaseUrl();保留兼容旧引用 */
  26. export const LLM_BASE_URL = getLlmBaseUrl()
  27. /**
  28. * 拼接大模型接口地址
  29. * @param {string} path 如 /v1/chat/completions
  30. */
  31. export function joinLlmUrl(path) {
  32. if (!path) {
  33. return getLlmBaseUrl()
  34. }
  35. if (/^https?:\/\//i.test(path)) {
  36. return path
  37. }
  38. const p = path.startsWith('/') ? path : '/' + path
  39. const base = getLlmBaseUrl().replace(/\/$/, '')
  40. return base + p
  41. }