openai API `max_completion_tokens` argument is ignored
还没有人认领这个 Issue。
评估
调研方向
查看处理 OpenAI 兼容 chat completions endpoint 的服务器代码,可能位于 llama_cpp/server/app.py 或类似文件中。找到请求参数解析的位置,以及使用 max_tokens 的位置。将其与 max_completion_tokens 应如何处理进行比较。检查 OpenAI API 规范中的参数名称。修复内容是确保读取 max_completion_tokens 并将其传递给生成逻辑。运行服务器并使用提供的客户端脚本进行测试,以验证 token 限制得到遵守。
由索引模型根据 Issue 内容生成。
描述
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- I am running the latest code. Development is very rapid so there are no tagged versions as of now.
- I carefully followed the README.md.
- I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
- I reviewed the Discussions, and have a new bug or useful enhancement to share.
Current Behavior
I'm running llama-server with following command:
python3 -m llama_cpp.server --model models/mys/ggml_llava-v1.5-13b/ggml-model-q4_k.gguf --clip_model_path models/mys/ggml_llava-v1.5-13b/mmproj-model-f16.gguf --model_alias llava-v1.5-13b-q4_k --chat_format llava-1-5 --port 10322
(models downloaded from https://huggingface.co/mys/ggml_llava-v1.5-13b/tree/main)
When I call the server using openai python package:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:10322/v1", # "http://<Your api-server IP>:port"
api_key = "sk-no-key-required"
)
chat_completion = client.chat.completions.create(
model="models/mys/ggml_llava-v1.5-13b/ggml-model-q4_k.gguf",
messages=[
{"role": "user", "content": "Write a limerick about python exceptions"}
],
max_tokens=3,
)
print(chat_completion.usage.completion_tokens) # returns 3, ok.
print(chat_completion.choices[0].finish_reason) # returns "length", ok.
chat_completion = client.chat.completions.create(
model="models/mys/ggml_llava-v1.5-13b/ggml-model-q4_k.gguf",
messages=[
{"role": "user", "content": "Write a limerick about python exceptions"}
],
max_completion_tokens=3,
)
print(chat_completion.usage.completion_tokens) # returns much more than 3 (complete answer).
print(chat_completion.choices[0].finish_reason) # returns "stop".
According to OpenAI API, max_completion_tokens argument is replacing the deprecated max_tokens argument.
It's seems that only max_tokens is not ignored by the server.
Environment and Context
llama_cpp installed with pip install llama-cpp-python[server]
print(llama_cpp.__version__): 0.3.6
print(openai.__version__): 1.59.7
- 主要语言
- Python
- 星标
- 10.6k
- 派生
- 1.5k
- 平均合并
- 23 分钟
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
abetlen/llama-cpp-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
abetlen/llama-cpp-python#2352 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
abetlen/llama-cpp-python#2211 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
abetlen/llama-cpp-python#2210 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
abetlen/llama-cpp-python#2145 ·
-
难度 1/5 1 小时以内 新手友好度 75/100
abetlen/llama-cpp-python#2135 · 4 个 reaction ·
查看 abetlen/llama-cpp-python 的全部 Issue
相似的 Issue
-
triage/confirmed
难度 2/5 1-3 小时 新手友好度 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
难度 1/5 1 小时以内 新手友好度 92/100
NousResearch/hermes-agent#118866 ·
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
apache/cloudstack#14222 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100