THUDM / ChatGLM3

ChatGLM3 series: Open Bilingual Chat LLMs | 开源双语对话语言模型
Apache License 2.0
13.19k stars 1.52k forks source link

运行 api_server.py , 请求返回异常 #1265

Closed hanqingwu closed 1 month ago

hanqingwu commented 1 month ago

System Info / 系統信息

python3.9

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

Reproduction / 复现过程

1 运行 api_server.py
2.curl -X POST "http://127.0.0.1:8000/v1/chat/completions" -H "Content-Type: application/json" -d "{\"model\": \"chatglm3-6b\", \"messages\": [{\"role\": \"system\", \"content\": \"我 希望您能够充当代码解释器,澄清代码的语法和语义。代码是\n\"}, {\"role\": \"user\", \"content\": \"def get_aaa()\"}], \"stream\": true, \"max_tokens\": 2000, \"temperature\": 0.8, \"top_p\": 0.8}"

  1. 返回
    
    data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":"\n 这是一个简单的","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":" Python","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":" ","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":"函数","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":",","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":"其","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":"名称","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":"是","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":" `","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: {"model":"chatglm3-6b","id":"","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":"get","function_call":null},"finish_reason":null,"index":0}],"created":1718268037}

data: data: 这是一个简单的 Python 函数,其名称是 get_aaa。让我们逐步分析这个代码: data: data: 1. def 关键字用于定义一个函数。get_aaa 是这个函数的名称。 data: 2. (): 这是一个冒号,它表示函数的开始。 data: 3. 在函数内部,没有语句或表达式,只有一个空括号 ()。通常,在这个位置你可能会看到函数体,它包含一系列语句或表达式来定义和执行函数的功能。但是,目前函数只是一个空函数名。 data: data: 因此,get_aaa() 是一个尚未实现的功能,它可能需要更多的代码来完成。例如,你可以在这个函数内部添加一些语句或表达式来实现预期的功能。下面是一个简单的示例,该示例将函数 name 改为 "Hello, World!": data: data: python data: def get_aaa(): data: name = "World" data: print(f"Hello, {name}!") data: data: get_aaa() # This will print "Hello, World!" data: data: data: 然而,目前这个函数只是一个空函数名,你需要在其中添加具体的功能。



### Expected behavior / 期待表现

返回的所有数据应该统一格式 
hanqingwu commented 1 month ago

原因找到了, 是有这段处理

def contains_custom_function(value: str) -> bool:
    """
    Determine whether 'function_call' according to a special function prefix.

    For example, the functions defined in "tools_using_demo/tool_register.py" are all "get_xxx" and start with "get_"

    [Note] This is not a rigorous judgment method, only for reference.

    :param value:
    :return:
    """
    return value and 'get_' in value
zRzRzRzRzRzRzR commented 1 month ago

因为这个代码解释器不是工具,所以返回的不是这个,GLM-4代码就统一了