Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Nil pointer dereference when using function calling and a chat_message template #1046

Open
mtharrison opened this issue Sep 13, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@mtharrison
Copy link

mtharrison commented Sep 13, 2023

LocalAI version:
Mac ARM native built

Environment, CPU architecture, OS, and Version:
Darwin M-YPDW3RKWDM 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

Describe the bug
When using a chat_message template and function calling I get a nil pointer dereference when templating the function_call message because Content is not set.

The panic occurs here: https://github.com/go-skynet/LocalAI/blob/master/api/openai/chat.go#L142 as for an assistant message with function call the content may be nil.

I think Content for the template should be set to the marshalled function call as per the code here: https://github.com/go-skynet/LocalAI/blob/master/api/openai/chat.go#L163-L172

To Reproduce
Try functional calling example with only a chat_message template

Expected behavior
Content in the chat_message template should be JSON stringified version of the function call.

I have a working fix on a branch, however I think to add a test I need to update the models_fixtures too. I'll give it a try.

@mtharrison mtharrison added the bug Something isn't working label Sep 13, 2023
@localai-bot
Copy link
Contributor

⚠️⚠️⚠️⚠️⚠️

Hi! I'm a bot running with LocalAI ( a crazy experiment of @mudler ) - please beware that I might hallucinate sometimes!

but.... I can also be funny or helpful 😸 and I can provide generally speaking good tips or places where to look after in the documentation or in the code based on what you wrote in the issue.

Don't engage in conversation with me,
I don't support (yet) replying!

⚠️⚠️⚠️⚠️⚠️

Thank you for providing the context and issue description. It seems like there is a bug in the LocalAI code that causes a nil pointer dereference when templating a function call message with a chat_message template. The fix would be to set the Content field in the template to the marshalled version of the function call, as per the code you mentioned.
To reproduce the issue, you can try creating a functional calling example with only a chat_message template and see if it triggers the nil pointer dereference error. If you have a working fix on a branch, you can submit a pull request to the LocalAI repository with your changes and explain the issue and the fix in the accompanying comment.
If you need further assistance or have any questions, feel free to ask!

Sources:

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants