Conversation
|
|
||
| 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)
| abs_url = "%s%s" % (self.api_base, url) | ||
| abs_url = f"{self.api_base}{url}" | ||
| headers = self._validate_headers(supplied_headers) | ||
|
|
||
| data = None | ||
| if method == "get" or method == "delete": | ||
| if method in ["get", "delete"]: |
There was a problem hiding this comment.
Function APIRequestor.request_raw refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons) - Simplify if expression by using or (
or-if-exp-identity)
| "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)
| 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)
| self._callback(self._progress) | ||
| except Exception as e: # catches exception from the callback | ||
| raise CancelledError("The upload was cancelled: {}".format(e)) | ||
| raise CancelledError(f"The upload was cancelled: {e}") |
There was a problem hiding this comment.
Function BufferReader.read refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| for ac in additional_columns: | ||
| dups = [c for c in additional_columns if ac in c] | ||
| if len(dups) > 0: | ||
| if dups: |
There was a problem hiding this comment.
Function additional_column_validator refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
| if suffix_option == " ->": | ||
| if df.prompt.str.contains("\n").any(): | ||
| continue | ||
| if suffix_option == " ->" and df.prompt.str.contains("\n").any(): | ||
| continue |
There was a problem hiding this comment.
Function common_prompt_suffix_validator refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| if ft_type == "open-ended generation" or ft_type == "classification": | ||
| if ft_type in ["open-ended generation", "classification"]: |
There was a problem hiding this comment.
Function common_completion_suffix_validator refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if remediation.optional_msg is not None: | ||
| if accept_suggestion(input_text, auto_accept): | ||
| df = remediation.optional_fn(df) | ||
| optional_applied = True | ||
| if remediation.optional_msg is not None and accept_suggestion( | ||
| input_text, auto_accept | ||
| ): | ||
| df = remediation.optional_fn(df) | ||
| optional_applied = True |
There was a problem hiding this comment.
Function apply_optional_remediation refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| pos_class = None | ||
| if n_classes == 2: | ||
| pos_class = df.completion.value_counts().index[0] | ||
| pos_class = df.completion.value_counts().index[0] if n_classes == 2 else None |
There was a problem hiding this comment.
Function get_classification_hyperparams refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
| 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 self.request("post", self.instance_url() + "/search", params) | ||
| return self.request("post", f"{self.instance_url()}/search", params) | ||
| else: | ||
| raise InvalidAPIType("Unsupported API type %s" % self.api_type) | ||
| raise InvalidAPIType(f"Unsupported API type {self.api_type}") |
There was a problem hiding this comment.
Function Engine.search refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| "Engine.embeddings is deprecated, use Embedding.create", DeprecationWarning | ||
| ) | ||
| return self.request("post", self.instance_url() + "/embeddings", params) | ||
| return self.request("post", f"{self.instance_url()}/embeddings", params) |
There was a problem hiding this comment.
Function Engine.embeddings 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 File.create refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| url = "/%s%s/%s/content?api-version=%s" % ( | ||
| cls.azure_api_prefix, | ||
| base, | ||
| id, | ||
| api_version, | ||
| ) | ||
| url = f"/{cls.azure_api_prefix}{base}/{id}/content?api-version={api_version}" | ||
| elif typed_api_type == ApiType.OPEN_AI: | ||
| url = f"{cls.class_url()}/{id}/content" | ||
| 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 File.download refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.12%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
| url = "/%s%s/%s/cancel?api-version=%s" % ( | ||
| cls.azure_api_prefix, | ||
| base, | ||
| extn, | ||
| api_version, | ||
| ) | ||
| url = f"/{cls.azure_api_prefix}{base}/{extn}/cancel?api-version={api_version}" | ||
| elif typed_api_type == ApiType.OPEN_AI: | ||
| url = "%s/%s/cancel" % (base, extn) | ||
| url = f"{base}/{extn}/cancel" | ||
| 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 FineTune.cancel refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring)
| url = "/%s%s/%s/events?stream=true&api-version=%s" % ( | ||
| cls.azure_api_prefix, | ||
| base, | ||
| extn, | ||
| api_version, | ||
| ) | ||
| url = f"/{cls.azure_api_prefix}{base}/{extn}/events?stream=true&api-version={api_version}" | ||
| elif typed_api_type == ApiType.OPEN_AI: | ||
| url = "%s/%s/events?stream=true" % (base, extn) | ||
| url = f"{base}/{extn}/events?stream=true" | ||
| 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 FineTune.stream_events refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring)
| @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 Image._get_url refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| files: List[Any] = [] | ||
| for key, value in params.items(): | ||
| files.append((key, (None, value))) | ||
| files: List[Any] = [(key, (None, value)) for key, value in params.items()] |
There was a problem hiding this comment.
Function Image.create_variation refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| files: List[Any] = [] | ||
| for key, value in params.items(): | ||
| files.append((key, (None, value))) | ||
| files.append(("image", ("image", image, "application/octet-stream"))) | ||
| files.append(("mask", ("mask", mask, "application/octet-stream"))) | ||
|
|
||
| files: List[Any] = [(key, (None, value)) for key, value in params.items()] | ||
| files.extend( | ||
| ( | ||
| ("image", ("image", image, "application/octet-stream")), | ||
| ("mask", ("mask", mask, "application/octet-stream")), | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Function Image.create_edit refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend) - Convert for loop into list comprehension (
list-comprehension)
| 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)
| 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 ListableAPIResource.list refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| ): | ||
| if resource_plural is None: | ||
| resource_plural = "%ss" % resource | ||
| resource_plural = f"{resource}s" |
There was a problem hiding this comment.
Function nested_resource_class_methods refactored with the following changes:
- Replace interpolated string formatting with f-string [×11] (
replace-interpolation-with-fstring)
| @classmethod | ||
| def modify(cls, sid, **params): | ||
| url = "%s/%s" % (cls.class_url(), quote_plus(sid)) | ||
| url = f"{cls.class_url()}/{quote_plus(sid)}" |
There was a problem hiding this comment.
Function UpdateableAPIResource.modify refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| def test_engine_search_url_composition_default() -> None: | ||
| engine = Engine(id="test_id") | ||
| assert engine.api_type == None | ||
| assert engine.api_type is None |
There was a problem hiding this comment.
Function test_engine_search_url_composition_default refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
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!