Skip to content

无法正常自定义 OpenAI API 请求参数 #365

@lihaoze123

Description

@lihaoze123

类似 kimi-k2.5 的模型 temperature 参数需要强制为 1,但是源码中硬编码了 temperature 为 0.7,导致不能正常调用。

  const data = {
    model: OJBetter.chatgpt.config.model || modelDefault,
    messages: OJBetter.chatgpt.asSystemPrompt
      ? [
        {
          role: "system",
          content: prompt,
        },
        {
          role: "user",
          content: raw,
        },
      ]
      : [
        {
          role: "user",
          content: prompt,
        },
      ],
    temperature: 0.7, // 硬编码 0.7
    ...Object.assign({}, ...OJBetter.chatgpt.config.data),
  };

而解析请求体参数的函数 OJB_parseLinePairArray 无法设置需要传递 JSON 对象的参数。

  const OJB_parseLinePairArray = (val) => {                                                                             
    if (typeof val !== "string" || val.trim() === "") return [];                                                        
    return val                                                                                                          
      .split("\n")                                                                                                      
      .filter((line) => line.trim() !== "")                                                                             
      .map((line) => {                                                                                                  
        const indexOfFirstColon = line.indexOf(":");                                                                    
        const key = line.substring(0, indexOfFirstColon).trim();                                                        
        const value = line.substring(indexOfFirstColon + 1).trim();                                                     
        return { [key]: value };  // ← 值始终是字符串,会自动转义导致不能指定数字/对象                                      
      });                                                                                                               
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions