镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

grammar from string #2

Open
Open

Description

@adrid

Regarding this comment:

grammar is not passed as string to be parsed, instead parsed llama_grammar* params, as at time of writing grammar_parser has no C api

Is there is any plan to support this? What do you think about creating simple cpp binding for this like that?

extern "C" llama_grammar * parseGrammar(const char * str) {
    grammar_parser::parse_state parsed_state = grammar_parser::parse(str);
    std::vector<const llama_grammar_element *> grammar_rules(parsed_state.c_rules());

    return llama_grammar_init(grammar_rules.data(), grammar_rules.size(), parsed_state.symbol_ids.at("root"));
}

I've tested this and after accept the token with grammar option it seems to work. I would prepare a draft if you think binding would be fine and we could check this in detail.

Activity

  1. Deins commented on Jan 18, 2024

    @Deins
    Owner

    I think that makes sense. I haven't looked into grammars yet. But for direct usage I think that should be enough. Would not mind merging it. Feel free to adjust anything as needed.
    FYI: The simplified 'Prompt' utility might or might not work. But as its still WIP, might not be worth worrying about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions