-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sourcery Starbot ⭐ refactored mkirch/evals #2
base: main
Are you sure you want to change the base?
Conversation
assert not kwargs.get("logprobs") is None | ||
assert kwargs.get("logprobs") is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function sample_freeform
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
raise ValueError(f"Must specify a model") | ||
raise ValueError("Must specify a model") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ModelSpec.__post_init__
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
if scheme == "" or scheme == "file": | ||
if scheme in ["", "file"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function open_by_file_pattern
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
md5 = hashlib.md5((name + ":" + str((args, kwargs))).encode("utf-8")).hexdigest() | ||
md5 = hashlib.md5(f"{name}:{(args, kwargs)}".encode("utf-8")).hexdigest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function filecache
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
return [row for row in reader] | ||
return list(reader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_csv
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
if not name in self._evals: | ||
if name not in self._evals: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Registry.get_base_eval
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
# first, look for a prefix match | ||
for model_prefix, n_ctx in DICT_OF_N_CTX_BY_MODEL_NAME_PREFIX.items(): | ||
if model_name.startswith(model_prefix): | ||
return n_ctx | ||
# otherwise, look for an exact match and return None if not found | ||
return DICT_OF_N_CTX_BY_MODEL_NAME.get(model_name, None) | ||
return next( | ||
( | ||
n_ctx | ||
for model_prefix, n_ctx in DICT_OF_N_CTX_BY_MODEL_NAME_PREFIX.items() | ||
if model_name.startswith(model_prefix) | ||
), | ||
DICT_OF_N_CTX_BY_MODEL_NAME.get(model_name, None), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = ModelSpec(name=name, model=name, is_chat=(name in self.CHAT_MODELS)) | ||
return result | ||
|
||
return ModelSpec(name=name, model=name, is_chat=(name in self.CHAT_MODELS)) | ||
if name in self.api_model_ids: | ||
result = ModelSpec( | ||
return ModelSpec( | ||
name=name, | ||
model=name, | ||
is_chat=(name in self.CHAT_MODELS), | ||
n_ctx=n_ctx_from_model_name(name), | ||
) | ||
return result | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ModelResolver.resolve
refactored with the following changes:
- Inline variable that is immediately returned [×2] (
inline-immediately-returned-variable
)
print(" " + command_str) | ||
print(f" {command_str}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function main
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if idx == -1: | ||
return None | ||
return text[idx + len(answer_prompt) :] | ||
return None if idx == -1 else text[idx + len(answer_prompt) :] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_answer
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if s1 == "" or s2 == "": | ||
return s1 == s2 | ||
|
||
return s1 in s2 or s2 in s1 | ||
return s1 == s2 if s1 == "" or s2 == "" else s1 in s2 or s2 in s1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function fuzzy_match
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
return {k: v for k, v in dict(matches).items()} | ||
return dict(dict(matches)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_yesno_from_text
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
char = max(last_y, last_n)[1] | ||
return char | ||
return max(last_y, last_n)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_letter_from_data
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
return max([_f1_score(prediction, answer) for answer in answers]) | ||
return max(_f1_score(prediction, answer) for answer in answers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function f1_score
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
[evals.elsuite.utils.get_answer(sampled, ref) for ref in sample["ideal"]] | ||
evals.elsuite.utils.get_answer(sampled, ref) for ref in sample["ideal"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Includes.eval_sample
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
missing_samples = len(all_sample_metrics) - len(chosen) | ||
if missing_samples: | ||
if missing_samples := len(all_sample_metrics) - len(chosen): | ||
counts["__missing_samples__"] = missing_samples | ||
record_metrics.update({f"counts/{metric}/{k}": v for k, v in counts.items()}) | ||
if self.metaeval: | ||
metascores = [m[metric + "_metascore"] for m in all_sample_metrics if metric in m] | ||
metascores = [ | ||
m[f"{metric}_metascore"] | ||
for m in all_sample_metrics | ||
if metric in m | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ModelBasedClassify.run
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
prefix = chat_to_prefixes.get(role, role.capitalize() + ": ") | ||
prefix = chat_to_prefixes.get(role, f"{role.capitalize()}: ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function chat_prompt_to_text_prompt
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for arg in args: | ||
if arg is not None: | ||
return arg | ||
return None | ||
return next((arg for arg in args if arg is not None), None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _first_not_none
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
)
cs = self.ctx.cursor(*args, **kwargs) | ||
return cs | ||
return self.ctx.cursor(*args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SnowflakeConnection.cursor
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
num_symbols = int(len(SYMBOLS) / 2) | ||
num_symbols = len(SYMBOLS) // 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function generate_example
refactored with the following changes:
- Simplify division expressions (
simplify-division
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run: