Skip to content
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!: llama.cpp - unified support for tools + refactoring #1357

Merged
merged 3 commits into from
Feb 7, 2025

Conversation

anakin87
Copy link
Member

@anakin87 anakin87 commented Feb 6, 2025

Related Issues

Proposed Changes:

  • replace the old implementation of function calling with a new one, centered on our unified Tool abstraction (breaking)
  • introduce missing to_dict/from_dict methods
  • incorporate potential tokenizer download in warm_up (instead of __init__)

How did you test it?

CI, several new tests

Checklist

@github-actions github-actions bot added integration:llama_cpp type:documentation Improvements or additions to documentation labels Feb 6, 2025
@anakin87 anakin87 changed the title feat: llama.cpp - unified support for tools feat!: llama.cpp - unified support for tools + refactoring Feb 6, 2025
@anakin87 anakin87 marked this pull request as ready for review February 6, 2025 09:02
@anakin87 anakin87 requested a review from a team as a code owner February 6, 2025 09:02
@anakin87 anakin87 requested review from vblagoje and removed request for a team February 6, 2025 09:02
Copy link
Member

@vblagoje vblagoje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks 99% there, some minor clarification needed

formatted_msg["content"] = message.tool_call_result.result

return formatted_msg
text_contents = message.texts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should externalize these next 15 or so lines of code to some util as we repeat it in many chat generators. Not now though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, this is very similar to OpenAI format.

In the past we decided to move away from a single generic conversion function:
this allows more freedom, but implies a bit of duplication.

self.model_kwargs["tokenizer"] = tokenizer

if self._model is None:
self._model = Llama(**self.model_kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait this can easily fail, no? Noone mandates that model_kwargs must be provided in init, maybe I'm off here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be safe.

(I tried not to change much the __init__. If I could start from scratch, I would have handled this differently)

In __init__ we have these assignments:

model_kwargs = model_kwargs or {}
# ...
model_kwargs.setdefault("model_path", model)  # model is mandatory init param
model_kwargs.setdefault("n_ctx", n_ctx)
model_kwargs.setdefault("n_batch", n_batch)
# ...
self.model_kwargs = model_kwargs

Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I did, this was hidden in Github and I didn't expand it. 👍

@anakin87 anakin87 requested a review from vblagoje February 7, 2025 10:39
@anakin87 anakin87 merged commit 909980b into main Feb 7, 2025
11 checks passed
@anakin87 anakin87 deleted the llamacpp-tools branch February 7, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:llama_cpp type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

llama.cpp ChatGenerator - support for Tool
2 participants