Skip to content

Sourcery refactored main branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Mar 31, 2023

Branch main refactored 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 main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from PeterParkette March 31, 2023 12:40
Copy link
Copy Markdown
Author

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment thread openai/_openai_scripts.py
"--version",
action="version",
version="%(prog)s " + version.VERSION,
version=f"%(prog)s {version.VERSION}",
Copy link
Copy Markdown
Author

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:

Comment thread openai/api_requestor.py

if base_query:
query = "%s&%s" % (base_query, query)
query = f"{base_query}&{query}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _build_api_url refactored with the following changes:

Comment thread openai/api_requestor.py
s = requests.Session()
proxies = _requests_proxies_arg(openai.proxy)
if proxies:
if proxies := _requests_proxies_arg(openai.proxy):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _make_session refactored with the following changes:

Comment thread openai/api_requestor.py
Comment on lines -143 to +144
str += "/%s" % (info["version"],)
str += f'/{info["version"]}'
if info["url"]:
str += " (%s)" % (info["url"],)
str += f' ({info["url"]})'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function APIRequestor.format_app_info refactored with the following changes:

Comment thread openai/api_requestor.py
Comment on lines -397 to +398
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)}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function APIRequestor.request_headers refactored with the following changes:

Comment thread openai/cli.py
Comment on lines -346 to +341
if resp.status_code == 200:
return resp.content
else:
return None
return resp.content if resp.status_code == 200 else None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FineTune._download_file_from_public_url refactored with the following changes:

Comment thread openai/cli.py
Comment on lines -539 to +531
"[%s] %s"
% (
datetime.datetime.fromtimestamp(event["created_at"]),
event["message"],
)
f'[{datetime.datetime.fromtimestamp(event["created_at"])}] {event["message"]}'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FineTune._stream_events refactored with the following changes:

Comment on lines -85 to +87
precision = dict()
recall = dict()
average_precision = dict()
precision = {}
recall = {}
average_precision = {}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function plot_multiclass_precision_recall refactored with the following changes:

Comment on lines -153 to -157
distances = [
return [
distance_metrics[distance_metric](query_embedding, embedding)
for embedding in embeddings
]
return distances
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function distances_from_embeddings refactored with the following changes:

Comment on lines -203 to +208
"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(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function chart_from_components refactored with the following changes:

Comment on lines -238 to +244
"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(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function chart_from_components_3D refactored with the following changes:

Comment thread openai/openai_object.py
Comment on lines -91 to -102
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OpenAIObject.__reduce__ refactored with the following changes:

This removes the following comments ( why? ):

# callable
# state
# args

Comment thread openai/openai_object.py
Comment on lines -189 to +188
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:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OpenAIObject.request refactored with the following changes:

Comment thread openai/openai_object.py
Comment on lines -240 to +238
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:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OpenAIObject.arequest refactored with the following changes:

Comment thread openai/openai_object.py
Comment on lines -269 to +268
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)}'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OpenAIObject.__repr__ refactored with the following changes:

Comment thread openai/validators.py
Comment on lines -811 to +815
[
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function apply_validators refactored with the following changes:

Comment thread openai/wandb_logger.py
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function WandbLogger.sync refactored with the following changes:

Comment thread openai/wandb_logger.py
Comment on lines -124 to +122
wandb_run = cls._get_wandb_run(run_path)
if wandb_run:
if wandb_run := cls._get_wandb_run(run_path):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function WandbLogger._log_fine_tune refactored with the following changes:

@classmethod
def _get_url(cls, action):
return cls.class_url() + f"/{action}"
return f"{cls.class_url()}/{action}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Audio._get_url refactored with the following changes:

Comment on lines -35 to +39
files: List[Any] = []
data = {
"model": model,
**params,
}
files.append(("file", (filename, file, "application/octet-stream")))
files: List[Any] = [("file", (filename, file, "application/octet-stream"))]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Audio._prepare_request refactored with the following changes:

)

scale_settings = kwargs.get("scale_settings", None)
scale_settings = kwargs.get("scale_settings")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Deployment._check_create refactored with the following changes:

timeout = kwargs.pop("timeout", None)

user_provided_encoding_format = kwargs.get("encoding_format", None)
user_provided_encoding_format = kwargs.get("encoding_format")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Embedding.create refactored with the following changes:

timeout = kwargs.pop("timeout", None)

user_provided_encoding_format = kwargs.get("encoding_format", None)
user_provided_encoding_format = kwargs.get("encoding_format")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Embedding.acreate refactored with the following changes:

return self.request(
"post",
self.instance_url() + "/generate",
f"{self.instance_url()}/generate",
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Engine.generate refactored with the following changes:

return await self.arequest(
"post",
self.instance_url() + "/generate",
f"{self.instance_url()}/generate",
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Engine.agenerate refactored with the following changes:

Comment on lines -31 to +35
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}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CreateableAPIResource.__prepare_create_requestor refactored with the following changes:

Comment on lines -22 to +26
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}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DeletableAPIResource.__prepare_delete refactored with the following changes:

Comment on lines -45 to +55
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}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function EngineAPIResource.class_url refactored with the following changes:

Comment on lines -75 to +69
model = params.get("model", None)
model = params.get("model")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function EngineAPIResource.__prepare_create_request refactored with the following changes:

Comment on lines -275 to +279
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}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function EngineAPIResource.instance_url refactored with the following changes:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants