Skip to content

Commit 1b62801

Browse files
author
ochafik
committed
fix editorconfig lints
1 parent ab25e3f commit 1b62801

File tree

17 files changed

+114
-106
lines changed

17 files changed

+114
-106
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ indent_style = tab
3030
[examples/cvector-generator/*.txt]
3131
trim_trailing_whitespace = unset
3232
insert_final_newline = unset
33+
34+
[{tests/chat/templates/*.jinja,tests/chat/goldens/*.txt}]
35+
indent_style = unset
36+
indent_size = unset
37+
end_of_line = unset
38+
charset = unset
39+
trim_trailing_whitespace = unset
40+
insert_final_newline = unset

common/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ bool llama_chat_verify_template(const std::string & tmpl, bool use_jinja) {
15161516
nullptr,
15171517
tmpl.c_str(),
15181518
chat,
1519-
1,
1519+
1,
15201520
/* add_ass= */ true,
15211521
/* buffer= */ nullptr,
15221522
/* length= */ 0,

common/common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ class llama_antiprompts {
624624
f = f->fail;
625625
}
626626

627-
child.fail = (f == &root && f->children.find(c) == f->children.end())
627+
child.fail = (f == &root && f->children.find(c) == f->children.end())
628628
? &root : &f->children[c];
629629

630630
if (child.fail->output != -1) {
@@ -654,7 +654,7 @@ class llama_antiprompts {
654654
},
655655
stop_words,
656656
grammar_trigger_words
657-
);
657+
);
658658
}
659659

660660
void build(const std::function<std::vector<llama_token>(const std::string)> & tokenizer, const std::vector<std::string> & stop_words, const std::vector<std::string> & grammar_trigger_words) {
@@ -708,7 +708,7 @@ class llama_antiprompts {
708708
MatchResult findFirstMatch(const std::string& text, size_t offset = 0) {
709709
TrieNode* current = &root;
710710
MatchResult partialMatch{std::string::npos, "", true, 0, false};
711-
711+
712712
for (size_t i = offset; i < text.length(); ++i) {
713713
char c = text[i];
714714
while (current != &root && current->children.find(c) == current->children.end()) {
@@ -736,12 +736,12 @@ class llama_antiprompts {
736736
partialMatch.is_grammar_trigger = false;
737737
}
738738
}
739-
739+
740740
// If we've found a partial match and haven't returned a full match, return the partial match
741741
if (partialMatch.pos != std::string::npos) {
742742
return partialMatch;
743743
}
744-
744+
745745
return {std::string::npos, "", false, 0, false};
746746
}
747747
};

common/minja.hpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Value : public std::enable_shared_from_this<Value> {
4848
}
4949
return Value();
5050
}
51-
51+
5252
bool empty() {
5353
return args.empty() && kwargs.empty();
5454
}
@@ -61,7 +61,7 @@ class Value : public std::enable_shared_from_this<Value> {
6161
}
6262
}
6363
};
64-
64+
6565
using CallableType = std::function<Value(const std::shared_ptr<Context> &, Arguments &)>;
6666
using FilterType = std::function<Value(const std::shared_ptr<Context> &, Arguments &)>;
6767

@@ -143,7 +143,7 @@ class Value : public std::enable_shared_from_this<Value> {
143143
} else if (is_boolean()) {
144144
out << (this->to_bool() ? "True" : "False");
145145
} else if (is_string()) {
146-
dump_string(primitive_, out, string_quote);
146+
dump_string(primitive_, out, string_quote);
147147
} else {
148148
out << primitive_.dump();
149149
}
@@ -175,7 +175,7 @@ class Value : public std::enable_shared_from_this<Value> {
175175
primitive_ = v;
176176
}
177177
}
178-
178+
179179
std::vector<Value> keys() {
180180
if (!object_) throw std::runtime_error("Value is not an object: " + dump());
181181
std::vector<Value> res;
@@ -267,7 +267,7 @@ class Value : public std::enable_shared_from_this<Value> {
267267
if (is_string()) return !get<std::string>().empty();
268268
if (is_array()) return !empty();
269269
return true;
270-
}
270+
}
271271

272272
bool operator<(const Value & other) const {
273273
if (is_null())
@@ -369,7 +369,7 @@ class Value : public std::enable_shared_from_this<Value> {
369369
if (!contains(key)) return default_value;
370370
return at(key).get<T>();
371371
}
372-
372+
373373
template <typename T>
374374
T get() const {
375375
if (is_primitive()) return primitive_.get<T>();
@@ -730,7 +730,7 @@ class TemplateNode {
730730
Location location_;
731731
protected:
732732
virtual void do_render(std::ostringstream & out, const std::shared_ptr<Context> & context) const = 0;
733-
733+
734734
public:
735735
TemplateNode(const Location & location) : location_(location) {}
736736
void render(std::ostringstream & out, const std::shared_ptr<Context> & context) const {
@@ -817,7 +817,7 @@ class ForNode : public TemplateNode {
817817
ForNode(const Location & location, std::vector<std::string> && var_names, std::unique_ptr<Expression> && iterable,
818818
std::unique_ptr<Expression> && condition, std::unique_ptr<TemplateNode> && body, bool recursive, std::unique_ptr<TemplateNode> && else_body)
819819
: TemplateNode(location), var_names(var_names), iterable(std::move(iterable)), condition(std::move(condition)), body(std::move(body)), recursive(recursive), else_body(std::move(else_body)) {}
820-
820+
821821
void do_render(std::ostringstream & out, const std::shared_ptr<Context> & context) const override {
822822
// https://jinja.palletsprojects.com/en/3.0.x/templates/#for
823823

@@ -920,7 +920,7 @@ class MacroNode : public TemplateNode {
920920
auto & arg_name = arg.first;
921921
auto it = named_param_positions.find(arg_name);
922922
if (it == named_param_positions.end()) throw std::runtime_error("Unknown parameter name for macro " + name->get_name() + ": " + arg_name);
923-
923+
924924
call_context->set(arg_name, arg.second);
925925
param_set[it->second] = true;
926926
}
@@ -1098,7 +1098,7 @@ class BinaryOpExpr : public Expression {
10981098
: Expression(location), left(std::move(l)), right(std::move(r)), op(o) {}
10991099
Value do_evaluate(const std::shared_ptr<Context> & context) const override {
11001100
auto l = left->evaluate(context);
1101-
1101+
11021102
auto do_eval = [&](const Value & l) -> Value {
11031103
if (op == Op::Is || op == Op::IsNot) {
11041104
auto t = dynamic_cast<VariableExpr*>(right.get());
@@ -1297,7 +1297,7 @@ class Parser {
12971297
std::shared_ptr<std::string> template_str;
12981298
CharIterator start, end, it;
12991299
Options options;
1300-
1300+
13011301
Parser(const std::shared_ptr<std::string>& template_str, const Options & options) : template_str(template_str), options(options) {
13021302
if (!template_str) throw std::runtime_error("Template string is null");
13031303
start = it = this->template_str->begin();
@@ -1326,7 +1326,7 @@ class Parser {
13261326
case 'b': result += '\b'; break;
13271327
case 'f': result += '\f'; break;
13281328
case '\\': result += '\\'; break;
1329-
default:
1329+
default:
13301330
if (*it == quote) {
13311331
result += quote;
13321332
} else {
@@ -1562,7 +1562,7 @@ class Parser {
15621562
if (!identifier) throw std::runtime_error("Expected identifier after 'is' keyword");
15631563

15641564
return nonstd_make_unique<BinaryOpExpr>(
1565-
left->location,
1565+
left->location,
15661566
std::move(left), std::move(identifier),
15671567
negated ? BinaryOpExpr::Op::IsNot : BinaryOpExpr::Op::Is);
15681568
}
@@ -1588,7 +1588,7 @@ class Parser {
15881588
if (consumeToken("(").empty()) throw std::runtime_error("Expected opening parenthesis in param list");
15891589

15901590
Expression::Parameters result;
1591-
1591+
15921592
while (it != end) {
15931593
if (!consumeToken(")").empty()) {
15941594
return result;
@@ -1622,7 +1622,7 @@ class Parser {
16221622
if (consumeToken("(").empty()) throw std::runtime_error("Expected opening parenthesis in call args");
16231623

16241624
Expression::Arguments result;
1625-
1625+
16261626
while (it != end) {
16271627
if (!consumeToken(")").empty()) {
16281628
return result;
@@ -1655,7 +1655,7 @@ class Parser {
16551655
static std::regex ident_regex(R"((?!not|is|and|or|del)[a-zA-Z_]\w*)");
16561656
auto location = get_location();
16571657
auto ident = consumeToken(ident_regex);
1658-
if (ident.empty())
1658+
if (ident.empty())
16591659
return nullptr;
16601660
return nonstd_make_unique<VariableExpr>(location, ident);
16611661
}
@@ -1699,7 +1699,7 @@ class Parser {
16991699
}
17001700
return left;
17011701
}
1702-
1702+
17031703
std::unique_ptr<Expression> parseMathMulDiv() {
17041704
auto left = parseMathUnaryPlusMinus();
17051705
if (!left) throw std::runtime_error("Expected left side of 'math mul/div' expression");
@@ -1709,9 +1709,9 @@ class Parser {
17091709
while (!(op_str = consumeToken(mul_div_tok)).empty()) {
17101710
auto right = parseMathUnaryPlusMinus();
17111711
if (!right) throw std::runtime_error("Expected right side of 'math mul/div' expression");
1712-
auto op = op_str == "*" ? BinaryOpExpr::Op::Mul
1713-
: op_str == "**" ? BinaryOpExpr::Op::MulMul
1714-
: op_str == "/" ? BinaryOpExpr::Op::Div
1712+
auto op = op_str == "*" ? BinaryOpExpr::Op::Mul
1713+
: op_str == "**" ? BinaryOpExpr::Op::MulMul
1714+
: op_str == "/" ? BinaryOpExpr::Op::Div
17151715
: op_str == "//" ? BinaryOpExpr::Op::DivDiv
17161716
: BinaryOpExpr::Op::Mod;
17171717
left = nonstd_make_unique<BinaryOpExpr>(get_location(), std::move(left), std::move(right), op);
@@ -1741,14 +1741,14 @@ class Parser {
17411741
auto op_str = consumeToken(unary_plus_minus_tok);
17421742
auto expr = parseValueExpression();
17431743
if (!expr) throw std::runtime_error("Expected expr of 'unary plus/minus' expression");
1744-
1744+
17451745
if (!op_str.empty()) {
17461746
auto op = op_str == "+" ? UnaryOpExpr::Op::Plus : UnaryOpExpr::Op::Minus;
17471747
return nonstd_make_unique<UnaryOpExpr>(get_location(), std::move(expr), op);
17481748
}
17491749
return expr;
17501750
}
1751-
1751+
17521752
std::unique_ptr<Expression> parseValueExpression() {
17531753
auto parseValue = [&]() -> std::unique_ptr<Expression> {
17541754
auto location = get_location();
@@ -1774,7 +1774,7 @@ class Parser {
17741774
};
17751775

17761776
auto value = parseValue();
1777-
1777+
17781778
while (it != end && consumeSpaces() && peekSymbols({ "[", "." })) {
17791779
if (!consumeToken("[").empty()) {
17801780
std::unique_ptr<Expression> index;
@@ -1797,7 +1797,7 @@ class Parser {
17971797
}
17981798
if (!index) throw std::runtime_error("Empty index in subscript");
17991799
if (consumeToken("]").empty()) throw std::runtime_error("Expected closing bracket in subscript");
1800-
1800+
18011801
value = nonstd_make_unique<SubscriptExpr>(value->location, std::move(value), std::move(index));
18021802
} else if (!consumeToken(".").empty()) {
18031803
auto identifier = parseIdentifier();
@@ -1825,10 +1825,10 @@ class Parser {
18251825

18261826
std::unique_ptr<Expression> parseBracedExpressionOrArray() {
18271827
if (consumeToken("(").empty()) return nullptr;
1828-
1828+
18291829
auto expr = parseExpression();
18301830
if (!expr) throw std::runtime_error("Expected expression in braced expression");
1831-
1831+
18321832
if (!consumeToken(")").empty()) {
18331833
return expr; // Drop the parentheses
18341834
}
@@ -1851,7 +1851,7 @@ class Parser {
18511851

18521852
std::unique_ptr<Expression> parseArray() {
18531853
if (consumeToken("[").empty()) return nullptr;
1854-
1854+
18551855
std::vector<std::unique_ptr<Expression>> elements;
18561856
if (!consumeToken("]").empty()) {
18571857
return nonstd_make_unique<ArrayExpr>(get_location(), std::move(elements));
@@ -1876,7 +1876,7 @@ class Parser {
18761876

18771877
std::unique_ptr<Expression> parseDictionary() {
18781878
if (consumeToken("{").empty()) return nullptr;
1879-
1879+
18801880
std::vector<std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>> elements;
18811881
if (!consumeToken("}").empty()) {
18821882
return nonstd_make_unique<DictExpr>(get_location(), std::move(elements));
@@ -1892,7 +1892,7 @@ class Parser {
18921892
};
18931893

18941894
parseKeyValuePair();
1895-
1895+
18961896
while (it != end) {
18971897
if (!consumeToken(",").empty()) {
18981898
parseKeyValuePair();
@@ -1950,15 +1950,15 @@ class Parser {
19501950
static std::regex text_regex(R"([\s\S\n]*?($|(?=\{\{|\{%|\{#)))");
19511951
static std::regex expr_close_regex(R"([\s\n]*([-~])?\}\})");
19521952
static std::regex block_close_regex(R"([\s\n]*([-~])?%\})");
1953-
1953+
19541954
TemplateTokenVector tokens;
19551955
std::vector<std::string> group;
19561956
std::string text;
1957-
1957+
19581958
try {
19591959
while (it != end) {
19601960
auto location = get_location();
1961-
1961+
19621962
if (!(group = consumeTokenGroups(comment_tok, SpaceHandling::Keep)).empty()) {
19631963
auto pre_space = parsePreSpace(group[1]);
19641964
auto content = group[2];
@@ -1985,7 +1985,7 @@ class Parser {
19851985
};
19861986

19871987
if ((keyword = consumeToken(block_keyword_tok)).empty()) throw std::runtime_error("Expected block keyword");
1988-
1988+
19891989
if (keyword == "if") {
19901990
auto condition = parseExpression();
19911991
if (!condition) throw std::runtime_error("Expected condition in if block");
@@ -2019,7 +2019,7 @@ class Parser {
20192019
condition = parseExpression();
20202020
}
20212021
auto recursive = !consumeToken(recursive_tok).empty();
2022-
2022+
20232023
auto post_space = parseBlockClose();
20242024
tokens.push_back(nonstd_make_unique<ForTemplateToken>(location, pre_space, post_space, std::move(varnames), std::move(iterable), std::move(condition), recursive));
20252025
} else if (keyword == "endfor") {
@@ -2034,7 +2034,7 @@ class Parser {
20342034
if (!(group = consumeTokenGroups(namespaced_var_regex)).empty()) {
20352035
ns = group[1];
20362036
var_names.push_back(group[2]);
2037-
2037+
20382038
if (consumeToken("=").empty()) throw std::runtime_error("Expected equals sign in set block");
20392039

20402040
value = parseExpression();
@@ -2115,7 +2115,7 @@ class Parser {
21152115
} else if (auto text_token = dynamic_cast<TextTemplateToken*>(token.get())) {
21162116
SpaceHandling pre_space = (it - 1) != begin ? (*(it - 2))->post_space : SpaceHandling::Keep;
21172117
SpaceHandling post_space = it != end ? (*it)->pre_space : SpaceHandling::Keep;
2118-
2118+
21192119
auto text = text_token->text;
21202120
if (pre_space == SpaceHandling::Strip) {
21212121
static std::regex leading_space_regex(R"(^(\s|\r|\n)+)");
@@ -2131,7 +2131,7 @@ class Parser {
21312131
static std::regex trailing_last_line_space_regex(R"((^|\n)[ \t]*$)");
21322132
text = std::regex_replace(text, trailing_last_line_space_regex, "$1");
21332133
}
2134-
2134+
21352135
if (it == end && !options.keep_trailing_newline) {
21362136
static std::regex r(R"([\n\r]$)");
21372137
text = std::regex_replace(text, r, ""); // Strip one trailing newline
@@ -2473,7 +2473,7 @@ inline std::shared_ptr<Context> Context::builtins() {
24732473
int64_t start = param_set[0] ? startEndStep[0] : 0;
24742474
int64_t end = startEndStep[1];
24752475
int64_t step = param_set[2] ? startEndStep[2] : 1;
2476-
2476+
24772477
auto res = Value::array();
24782478
if (step > 0) {
24792479
for (int64_t i = start; i < end; i += step) {

common/sampling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ bool gpt_sampler_trigger_grammar(const struct llama_model * model, gpt_sampler *
147147
llama_sampler_accept_str(gsmpl->grmr, trigger.c_str());
148148
return true;
149149
}
150-
150+
151151
struct gpt_sampler * gpt_sampler_init(const struct llama_model * model, const struct gpt_sampler_params & params) {
152152
llama_sampler_chain_params lparams = llama_sampler_chain_default_params();
153153

0 commit comments

Comments
 (0)