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

community[patch]: Add grammar support for node-llama-cpp LLM #5310

Merged
merged 11 commits into from
May 10, 2024

Conversation

Shaydesh
Copy link
Contributor

@Shaydesh Shaydesh commented May 7, 2024

Hello, I am attempting to add a configuration to langchainjs node-llama-cpp implementation that will make it respond in a specific format like JSON or a list. This is a functionality that the python langchain has for llama. The functionality for this is documented here: https://withcatai.github.io/node-llama-cpp/guide/grammar .

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 7, 2024
Copy link

vercel bot commented May 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2024 7:38pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview May 10, 2024 7:38pm

Copy link
Member

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

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

This looks really good! I left one comment, and I believe you'll need to run yarn format && yarn lint:fix to resolve any prettier/eslint issues.

Also, if you could add an integration test for this that would be much appreciated!

Please re-request my review once those changes have been pushed so I can get this merged

Comment on lines 78 to 84
this.jsonSchema = inputs?.jsonSchema;
this.gbnf = inputs?.gbnf;
this._model = createLlamaModel(inputs);
this._context = createLlamaContext(this._model, inputs);
this._session = createLlamaSession(this._context);
this._jsonSchema = createLlamaJsonSchemaGrammar(this.jsonSchema);
this._gbnf = createCustomGrammar(this.gbnf);
Copy link
Member

Choose a reason for hiding this comment

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

Can we drop this.jsonSchema and this.gbnf since they appear to only be used inside this constructor?

Suggested change
this.jsonSchema = inputs?.jsonSchema;
this.gbnf = inputs?.gbnf;
this._model = createLlamaModel(inputs);
this._context = createLlamaContext(this._model, inputs);
this._session = createLlamaSession(this._context);
this._jsonSchema = createLlamaJsonSchemaGrammar(this.jsonSchema);
this._gbnf = createCustomGrammar(this.gbnf);
this._model = createLlamaModel(inputs);
this._context = createLlamaContext(this._model, inputs);
this._session = createLlamaSession(this._context);
this._jsonSchema = createLlamaJsonSchemaGrammar(inputs?.jsonSchema);
this._gbnf = createCustomGrammar(inputs?.gbnf);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will do this! Thank you for responding. Sorry I didn't see your comments before my last update.

@bracesproul bracesproul added the in progress PRs that are in progress but not ready to merge label May 7, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 7, 2024
Copy link
Member

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

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

lgtm! One more question, could this be applied to the chat model integration too? I'll merge this now, but it would be great to get it in for chat models too since those are more widely used.

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label May 10, 2024
@dosubot dosubot bot removed the size:L This PR changes 100-499 lines, ignoring generated files. label May 10, 2024
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases in progress PRs that are in progress but not ready to merge lgtm PRs that are ready to be merged as-is size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants