-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(python backend): function call upgrade #368
feat(python backend): function call upgrade #368
Conversation
Changing few definations to fit OpenAI inference as new variables do not go well. Implementing the detection of funcion call type request by the existance of tool attribute, as function call request need to be specifically processed.
Modifying request classification logics, as mistake flags are leading to fault classification results.
- Add support for function calls in non-stream mode within the chatmode. - Update relevant modules and functions to handle non-stream responses. - Ensure compatibility with existing chatmode functionalities. Commit footprint: - Modify files: completion.py
Correct the data format to ensure compatibility with the OpenAI API. Update relevant modules and functions in completion.py. Details: Modify files: completion.py
This commit includes the implementation of a non-streaming function call process. It covers the entire workflow for invoking functions in a single call. The code has been simply passed the functional tests, but the content still need to be improved. Update relevant modules and functions in completion.py. Details: Modify files: completion.py Modify functions: eval_rwkv, chat_template, chat_with_tools,
I decided to move the directory structure from routes to backend-python because it aligns better with our project organization. This change won't impact existing functionality, but it will make the code clearer and easier to maintain. Details: Modify directory: tests Modify files: function_call.py
…cture Create postprocess_response function for text post-processing. Restore function rwkv_eval. Implement generation of tool_calls id. Details: Modify file(s): function_call.py
Add a file to test the ability to evaluate postprocess_response functions and post-process string functions. Details: Add file(s): tests/postprocss_response.py
Correct the data format to ensure compatibility with the OpenAI API, according to OpenAI API Reference docs. Update relevant modules and functions in completion.py. Details: Modify file(s): schema.py
035fca2
to
0d06082
Compare
Remove a data check field because it was already validated when it was passed in. Fix attribute name "logprobs". Details: Modify file(s): completion.py
Modify the post-processing method of the string to match the inference results of the Mobius model. Synchronously modify the test file. Details: Modify File(s): completion.py, postprocess_response.py
Refactor the sinthesis method of append_message. Refactor the sinthesis method of tools_text. Details: Modify File(s): completion.py
eb89837 做了一些调整,现在function_call测试脚本能够跑通 |
参考 eb89837#diff-4e4a05876ad4fc0cfe0ed3cbdc219a3859cb0518161d9e959d52820520c87227R452, 只有当匹配到tool_call( 开始,确认AI进行了函数调用时,才返回null并开始tool_calls响应,同时stream发送函数名称。若ai回复出现了4个及以上的换行符,或累计字符串长度超过了40,或累计字符串长度超过30且没有出现过
以及等于号替换为冒号 总体而言设想的stream流程没什么问题,只是不用立即返回一个content: null,而是确认找到函数名时再一同返回 |
Add a file for testing server-side completion stream transmission. Details: Add file(s): tests/function_call_stream.py
…ol calls. Create a draft of the stream_response_gen function, where I will implement generating a streaming function call later. Details: Modified File(s): completion.py
Adjust the print function. The current streaming test is still a draft because it is now testing choices[0].delta.content instead of choices[0].delta.tool_calls. Details: Modifiy File(s): tests/function_call_stream.py
Add an asynchronous generator that handles function call requests. The generator passes the test of distinguishing the non-function call response that is produced in the result of the inference. However, the functionality associated with function calls has not been tested. Details: Modify File(s): completion.py
我最新的 Commit c4b9c4e 尝试实现了 stream 模式下处理并响应包含 tools 的用户请求
需要测试的情况:
我本地难以测试这些情况, 做调试及修 bug 的工作辛苦了。 |
远程资源没有,我这边也是自己的电脑跑的😂 |
我得后天再进行测试,明天周末休息一下吧😆 |
Use black formatter to change the code format, and these changes do not affect the operation of the code Remove unnecessary library. Details: Modify File(s): completion.py
测试下来有一些问题, stream模式跑不通, 我在做调整 |
做了一些调整: 现在stream模式的function call已经能够跑通: 3df4302 不过简单粗暴的等于号替换为冒号存在问题, 需要改为栈的方式处理 |
Modify the comments in the code to match the code content. This will not have an impact on functionality. Details: Modify File(s): completion.py
调整 stream 模式辛苦了。 |
先转为正式PR提交吧,还有一些小细节我改一下 |
非常感谢这么多天的工作! |
* add function_call.py * feat(backend): add wip annotation * feat(backend): Synchronized Files * feat(Backend): detect function call request Changing few definations to fit OpenAI inference as new variables do not go well. Implementing the detection of funcion call type request by the existance of tool attribute, as function call request need to be specifically processed. * fix(Backend): detect function call request Modifying request classification logics, as mistake flags are leading to fault classification results. * feat(Backend): Implement function call in non-stream mode for chatmode - Add support for function calls in non-stream mode within the chatmode. - Update relevant modules and functions to handle non-stream responses. - Ensure compatibility with existing chatmode functionalities. Commit footprint: - Modify files: completion.py * fix(Backend): Fix OpenAI API data format compatibility Correct the data format to ensure compatibility with the OpenAI API. Update relevant modules and functions in completion.py. Details: Modify files: completion.py * feat(Backend): Implement non-streaming function call process This commit includes the implementation of a non-streaming function call process. It covers the entire workflow for invoking functions in a single call. The code has been simply passed the functional tests, but the content still need to be improved. Update relevant modules and functions in completion.py. Details: Modify files: completion.py Modify functions: eval_rwkv, chat_template, chat_with_tools, * fix(Backend): Move directory structure from routes to backend-python I decided to move the directory structure from routes to backend-python because it aligns better with our project organization. This change won't impact existing functionality, but it will make the code clearer and easier to maintain. Details: Modify directory: tests Modify files: function_call.py * fix(Backend): Update Prompts to Mobius example and refactor code structure Create postprocess_response function for text post-processing. Restore function rwkv_eval. Implement generation of tool_calls id. Details: Modify file(s): function_call.py * test(Backend): Add postprocss_response.py for tests Add a file to test the ability to evaluate postprocess_response functions and post-process string functions. Details: Add file(s): tests/postprocss_response.py * fix(Backend): Fix OpenAI API data format compatibility Correct the data format to ensure compatibility with the OpenAI API, according to OpenAI API Reference docs. Update relevant modules and functions in completion.py. Details: Modify file(s): schema.py * perf(Backend): Modify some attributes. Remove a data check field because it was already validated when it was passed in. Fix attribute name "logprobs". Details: Modify file(s): completion.py * fix(Backend): Fix postprocess_response funciton. Modify the post-processing method of the string to match the inference results of the Mobius model. Synchronously modify the test file. Details: Modify File(s): completion.py, postprocess_response.py * refactor(Backend): Refactor two places related to prompt word synthesis. Refactor the sinthesis method of append_message. Refactor the sinthesis method of tools_text. Details: Modify File(s): completion.py * 修正一些小细节使function_call工作正常 * test(Backend): Add function_call_stream.py Add a file for testing server-side completion stream transmission. Details: Add file(s): tests/function_call_stream.py * chore(Backend): Add a function to generate streaming responses for tool calls. Create a draft of the stream_response_gen function, where I will implement generating a streaming function call later. Details: Modified File(s): completion.py * fix(Backend): Adjust the output format of the streaming test file. Adjust the print function. The current streaming test is still a draft because it is now testing choices[0].delta.content instead of choices[0].delta.tool_calls. Details: Modifiy File(s): tests/function_call_stream.py * feat(Backend): Try to implement streaming function calls Add an asynchronous generator that handles function call requests. The generator passes the test of distinguishing the non-function call response that is produced in the result of the inference. However, the functionality associated with function calls has not been tested. Details: Modify File(s): completion.py * style(Backend): Change some format Use black formatter to change the code format, and these changes do not affect the operation of the code Remove unnecessary library. Details: Modify File(s): completion.py * stream function call细节调整 * docs(Backend): Modify comments in the code. Modify the comments in the code to match the code content. This will not have an impact on functionality. Details: Modify File(s): completion.py --------- Co-authored-by: josc146 <josStorer@outlook.com>
This is a draft pull request to showcase the progress of my work on the function calling.