QwenLM / Qwen-Agent

Agent framework and applications built upon Qwen2, featuring Function Calling, Code Interpreter, RAG, and Chrome extension.
https://pypi.org/project/qwen-agent/
Other
2.51k stars 249 forks source link

请教一下如何加入一些生成的额外参数 #202

Open EvilCalf opened 2 weeks ago

EvilCalf commented 2 weeks ago

例如length_penalty这些

JianxinMa commented 2 weeks ago

类似readme里的例子,加在llm cfg的generate_cfg字段:

# Step 2: Configure the LLM you are using.
llm_cfg = {
    # Use the model service provided by DashScope:
    'model': 'qwen-max',
    'model_server': 'dashscope',
    # 'api_key': 'YOUR_DASHSCOPE_API_KEY',
    # It will use the `DASHSCOPE_API_KEY' environment variable if 'api_key' is not set here.

    # Use a model service compatible with the OpenAI API, such as vLLM or Ollama:
    # 'model': 'Qwen2-7B-Chat',
    # 'model_server': 'http://localhost:8000/v1',  # base_url, also known as api_base
    # 'api_key': 'EMPTY',

    # (Optional) LLM hyperparameters for generation:
    'generate_cfg': {
        'top_p': 0.8
    }
}

比如上面的例子就加入了top_p这个额外生成参数。类似地加个 length_penalty 即可,会传递给openai api、dashscope api。

EvilCalf commented 2 weeks ago

这样好像不行,我服务是VLLM起的,但是在到openai框架create函数的地方,就不行了,TypeError: Completions.create() got an unexpected keyword argument 'length_penalty',这个貌似是直接给的变量,没有给在额外参数里,openai的也没有这个参数

JianxinMa commented 2 weeks ago

这样好像不行,我服务是VLLM起的,但是在到openai框架create函数的地方,就不行了,TypeError: Completions.create() got an unexpected keyword argument 'length_penalty',这个貌似是直接给的变量,没有给在额外参数里,openai的也没有这个参数

那可以类似这里的代码 https://github.com/QwenLM/Qwen-Agent/blob/main/qwen_agent/llm/oai.py#L55 将这个额外参数放在 extra_body 里传给vllm

EvilCalf commented 1 week ago

好的,那我必须手动在这个参数list里面加入,对吧