Conversation
| "--version", | ||
| action="version", | ||
| version="%(prog)s " + version.VERSION, | ||
| version=f"%(prog)s {version.VERSION}", |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| if base_query: | ||
| query = "%s&%s" % (base_query, query) | ||
| query = f"{base_query}&{query}" |
There was a problem hiding this comment.
Function _build_api_url refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| s = requests.Session() | ||
| proxies = _requests_proxies_arg(openai.proxy) | ||
| if proxies: | ||
| if proxies := _requests_proxies_arg(openai.proxy): |
There was a problem hiding this comment.
Function _make_session refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| str += "/%s" % (info["version"],) | ||
| str += f'/{info["version"]}' | ||
| if info["url"]: | ||
| str += " (%s)" % (info["url"],) | ||
| str += f' ({info["url"]})' |
There was a problem hiding this comment.
Function APIRequestor.format_app_info refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| user_agent = "OpenAI/v1 PythonBindings/%s" % (version.VERSION,) | ||
| user_agent = f"OpenAI/v1 PythonBindings/{version.VERSION}" | ||
| if openai.app_info: | ||
| user_agent += " " + self.format_app_info(openai.app_info) | ||
| user_agent += f" {self.format_app_info(openai.app_info)}" |
There was a problem hiding this comment.
Function APIRequestor.request_headers refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| if resp.status_code == 200: | ||
| return resp.content | ||
| else: | ||
| return None | ||
| return resp.content if resp.status_code == 200 else None |
There was a problem hiding this comment.
Function FineTune._download_file_from_public_url refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| "[%s] %s" | ||
| % ( | ||
| datetime.datetime.fromtimestamp(event["created_at"]), | ||
| event["message"], | ||
| ) | ||
| f'[{datetime.datetime.fromtimestamp(event["created_at"])}] {event["message"]}' |
There was a problem hiding this comment.
Function FineTune._stream_events refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| precision = dict() | ||
| recall = dict() | ||
| average_precision = dict() | ||
| precision = {} | ||
| recall = {} | ||
| average_precision = {} |
There was a problem hiding this comment.
Function plot_multiclass_precision_recall refactored with the following changes:
- Replace
dict()with{}[×3] (dict-literal) - Move assignment closer to its usage within a block [×3] (
move-assign-in-block) - Merge append into list declaration [×3] (
merge-list-append)
| distances = [ | ||
| return [ | ||
| distance_metrics[distance_metric](query_embedding, embedding) | ||
| for embedding in embeddings | ||
| ] | ||
| return distances |
There was a problem hiding this comment.
Function distances_from_embeddings refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| "label": labels if labels else empty_list, | ||
| "string": ["<br>".join(tr.wrap(string, width=30)) for string in strings] | ||
| "label": labels or empty_list, | ||
| "string": [ | ||
| "<br>".join(tr.wrap(string, width=30)) for string in strings | ||
| ] | ||
| if strings | ||
| else empty_list, | ||
| } | ||
| ) | ||
| chart = px.scatter( | ||
| return px.scatter( |
There was a problem hiding this comment.
Function chart_from_components refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| "label": labels if labels else empty_list, | ||
| "string": ["<br>".join(tr.wrap(string, width=30)) for string in strings] | ||
| "label": labels or empty_list, | ||
| "string": [ | ||
| "<br>".join(tr.wrap(string, width=30)) for string in strings | ||
| ] | ||
| if strings | ||
| else empty_list, | ||
| } | ||
| ) | ||
| chart = px.scatter_3d( | ||
| return px.scatter_3d( |
There was a problem hiding this comment.
Function chart_from_components_3D refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| reduce_value = ( | ||
| type(self), # callable | ||
| ( # args | ||
| return ( | ||
| type(self), | ||
| ( | ||
| self.get("id", None), | ||
| self.api_key, | ||
| self.api_version, | ||
| self.api_type, | ||
| self.organization, | ||
| ), | ||
| dict(self), # state | ||
| dict(self), | ||
| ) | ||
| return reduce_value |
There was a problem hiding this comment.
Function OpenAIObject.__reduce__ refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# callable
# state
# args
| if stream: | ||
| assert not isinstance(response, OpenAIResponse) # must be an iterator | ||
| return ( | ||
| util.convert_to_openai_object( | ||
| line, | ||
| api_key, | ||
| self.api_version, | ||
| self.organization, | ||
| plain_old_data=plain_old_data, | ||
| ) | ||
| for line in response | ||
| ) | ||
| else: | ||
| if not stream: |
There was a problem hiding this comment.
Function OpenAIObject.request refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if stream: | ||
| assert not isinstance(response, OpenAIResponse) # must be an iterator | ||
| return ( | ||
| util.convert_to_openai_object( | ||
| line, | ||
| api_key, | ||
| self.api_version, | ||
| self.organization, | ||
| plain_old_data=plain_old_data, | ||
| ) | ||
| for line in response | ||
| ) | ||
| else: | ||
| if not stream: |
There was a problem hiding this comment.
Function OpenAIObject.arequest refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| ident_parts.append("id=%s" % (self.get("id"),)) | ||
|
|
||
| unicode_repr = "<%s at %s> JSON: %s" % ( | ||
| " ".join(ident_parts), | ||
| hex(id(self)), | ||
| str(self), | ||
| ) | ||
| ident_parts.append(f'id={self.get("id")}') | ||
|
|
||
| return unicode_repr | ||
| return f'<{" ".join(ident_parts)} at {hex(id(self))}> JSON: {str(self)}' |
There was a problem hiding this comment.
Function OpenAIObject.__repr__ refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| [ | ||
| remediation | ||
| for remediation in optional_remediations | ||
| if remediation.optional_msg is not None | ||
| or remediation.necessary_msg is not None | ||
| ] | ||
| remediation | ||
| for remediation in optional_remediations | ||
| if remediation.optional_msg is not None | ||
| or remediation.necessary_msg is not None | ||
| ) | ||
| any_necessary_applied = any( | ||
| [ | ||
| remediation | ||
| for remediation in optional_remediations | ||
| if remediation.necessary_msg is not None | ||
| ] | ||
| remediation | ||
| for remediation in optional_remediations | ||
| if remediation.necessary_msg is not None |
There was a problem hiding this comment.
Function apply_validators refactored with the following changes:
- Replace unneeded comprehension with generator [×2] (
comprehension-to-generator)
| show_individual_warnings = ( | ||
| False if id is None and n_fine_tunes is None else True | ||
| ) | ||
| show_individual_warnings = id is not None or n_fine_tunes is not None |
There was a problem hiding this comment.
Function WandbLogger.sync refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| wandb_run = cls._get_wandb_run(run_path) | ||
| if wandb_run: | ||
| if wandb_run := cls._get_wandb_run(run_path): |
There was a problem hiding this comment.
Function WandbLogger._log_fine_tune refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| @classmethod | ||
| def _get_url(cls, action): | ||
| return cls.class_url() + f"/{action}" | ||
| return f"{cls.class_url()}/{action}" |
There was a problem hiding this comment.
Function Audio._get_url refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| files: List[Any] = [] | ||
| data = { | ||
| "model": model, | ||
| **params, | ||
| } | ||
| files.append(("file", (filename, file, "application/octet-stream"))) | ||
| files: List[Any] = [("file", (filename, file, "application/octet-stream"))] |
There was a problem hiding this comment.
Function Audio._prepare_request refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Merge append into list declaration (
merge-list-append)
| ) | ||
|
|
||
| scale_settings = kwargs.get("scale_settings", None) | ||
| scale_settings = kwargs.get("scale_settings") |
There was a problem hiding this comment.
Function Deployment._check_create refactored with the following changes:
- Replace
dict.get(x, None)withdict.get(x)(remove-none-from-default-get)
| timeout = kwargs.pop("timeout", None) | ||
|
|
||
| user_provided_encoding_format = kwargs.get("encoding_format", None) | ||
| user_provided_encoding_format = kwargs.get("encoding_format") |
There was a problem hiding this comment.
Function Embedding.create refactored with the following changes:
- Replace
dict.get(x, None)withdict.get(x)(remove-none-from-default-get)
| timeout = kwargs.pop("timeout", None) | ||
|
|
||
| user_provided_encoding_format = kwargs.get("encoding_format", None) | ||
| user_provided_encoding_format = kwargs.get("encoding_format") |
There was a problem hiding this comment.
Function Embedding.acreate refactored with the following changes:
- Replace
dict.get(x, None)withdict.get(x)(remove-none-from-default-get)
| return self.request( | ||
| "post", | ||
| self.instance_url() + "/generate", | ||
| f"{self.instance_url()}/generate", |
There was a problem hiding this comment.
Function Engine.generate refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return await self.arequest( | ||
| "post", | ||
| self.instance_url() + "/generate", | ||
| f"{self.instance_url()}/generate", |
There was a problem hiding this comment.
Function Engine.agenerate refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| url = "/%s%s?api-version=%s" % (cls.azure_api_prefix, base, api_version) | ||
| url = f"/{cls.azure_api_prefix}{base}?api-version={api_version}" | ||
| elif typed_api_type == ApiType.OPEN_AI: | ||
| url = cls.class_url() | ||
| else: | ||
| raise error.InvalidAPIType("Unsupported API type %s" % api_type) | ||
| raise error.InvalidAPIType(f"Unsupported API type {api_type}") |
There was a problem hiding this comment.
Function CreateableAPIResource.__prepare_create_requestor refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| url = "/%s%s/%s?api-version=%s" % ( | ||
| cls.azure_api_prefix, | ||
| base, | ||
| extn, | ||
| api_version, | ||
| ) | ||
| url = f"/{cls.azure_api_prefix}{base}/{extn}?api-version={api_version}" | ||
| elif typed_api_type == ApiType.OPEN_AI: | ||
| url = "%s/%s" % (base, extn) | ||
| url = f"{base}/{extn}" | ||
| else: | ||
| raise error.InvalidAPIType("Unsupported API type %s" % api_type) | ||
| raise error.InvalidAPIType(f"Unsupported API type {api_type}") |
There was a problem hiding this comment.
Function DeletableAPIResource.__prepare_delete refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring)
| return "/%s/%s/%s/%s?api-version=%s" % ( | ||
| cls.azure_api_prefix, | ||
| cls.azure_deployments_prefix, | ||
| extn, | ||
| base, | ||
| api_version, | ||
| ) | ||
| return f"/{cls.azure_api_prefix}/{cls.azure_deployments_prefix}/{extn}/{base}?api-version={api_version}" | ||
|
|
||
| elif typed_api_type == ApiType.OPEN_AI: | ||
| if engine is None: | ||
| return "/%s" % (base) | ||
| return f"/{base}" | ||
|
|
||
| extn = quote_plus(engine) | ||
| return "/engines/%s/%s" % (extn, base) | ||
| return f"/engines/{extn}/{base}" | ||
|
|
||
| else: | ||
| raise error.InvalidAPIType("Unsupported API type %s" % api_type) | ||
| raise error.InvalidAPIType(f"Unsupported API type {api_type}") |
There was a problem hiding this comment.
Function EngineAPIResource.class_url refactored with the following changes:
- Replace interpolated string formatting with f-string [×4] (
replace-interpolation-with-fstring)
| model = params.get("model", None) | ||
| model = params.get("model") |
There was a problem hiding this comment.
Function EngineAPIResource.__prepare_create_request refactored with the following changes:
- Replace
dict.get(x, None)withdict.get(x)(remove-none-from-default-get) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| url = "/%s/%s/%s/%s/%s?api-version=%s" % ( | ||
| self.azure_api_prefix, | ||
| self.azure_deployments_prefix, | ||
| self.engine, | ||
| base, | ||
| extn, | ||
| api_version, | ||
| ) | ||
| url = f"/{self.azure_api_prefix}/{self.azure_deployments_prefix}/{self.engine}/{base}/{extn}?api-version={api_version}" | ||
| params_connector = "&" | ||
|
|
||
| elif self.typed_api_type == ApiType.OPEN_AI: | ||
| base = self.class_url(self.engine, self.api_type, self.api_version) | ||
| url = "%s/%s" % (base, extn) | ||
| url = f"{base}/{extn}" | ||
|
|
||
| else: | ||
| raise error.InvalidAPIType("Unsupported API type %s" % self.api_type) | ||
| raise error.InvalidAPIType(f"Unsupported API type {self.api_type}") | ||
|
|
||
| timeout = self.get("timeout") | ||
| if timeout is not None: | ||
| timeout = quote_plus(str(timeout)) | ||
| url += params_connector + "timeout={}".format(timeout) | ||
| url += f"{params_connector}timeout={timeout}" |
There was a problem hiding this comment.
Function EngineAPIResource.instance_url refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!