-
Notifications
You must be signed in to change notification settings - Fork 39
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 Amm1rr/Free-Chatbot-API #3
Conversation
930de57
to
e46b504
Compare
url = "http://localhost:8000/" + ai | ||
url = f"http://localhost:8000/{ai}" |
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.
Lines 19-31
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
headers={ | ||
"Content-Type": "application/json", | ||
"Authorization": f"Bearer ", | ||
}, | ||
headers={"Content-Type": "application/json", "Authorization": "Bearer "}, |
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.
Lines 54-131
refactored with the following changes:
- Replace f-string with no interpolated values with string [×2] (
remove-redundant-fstring
) - Remove unreachable code (
remove-unreachable-code
)
This removes the following comments ( why? ):
# print(f"{data}\n\n")
# Hide API key from Rich traceback.
if arg1.upper() == "TRUE": | ||
stream = True | ||
else: | ||
stream = False | ||
|
||
stream = arg1.upper() == "TRUE" |
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.
Lines 19-23
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if arg1.upper() == "TRUE": | ||
stream = True | ||
else: | ||
stream = False | ||
|
||
stream = arg1.upper() == "TRUE" |
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.
Lines 18-65
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if arg1.upper() == "TRUE": | ||
stream = True | ||
else: | ||
stream = False | ||
stream = arg1.upper() == "TRUE" |
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.
Lines 10-13
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
return False | ||
return response.json() if response.status_code == 200 else False |
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 Client.upload_attachment
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if response.status_code == 200: | ||
return True | ||
else: | ||
return False | ||
return response.status_code == 200 |
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 Client.rename_chat
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
# answer = {f"answer": "You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument."}["answer"] | ||
answer = f"You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument." | ||
# print(answer) | ||
return answer | ||
|
||
return f"You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument." |
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 ask_gpt
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
This removes the following comments ( why? ):
# print(answer)
# answer = {f"answer": "You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument."}["answer"]
f"Error": f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
"Error": f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
} | ||
|
||
print(response_error) | ||
return response_error | ||
# raise ValueError( | ||
# f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
# ) | ||
# raise ValueError( | ||
# f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
# ) |
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 ask_gptClaude
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
f"Error": f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
"Error": f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
} | ||
|
||
print(response_error) | ||
return response_error | ||
# raise ValueError( | ||
# f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
# ) | ||
# raise ValueError( | ||
# f"You should set 'COOKIE' in '{CONFIG_FILE_NAME}' file for the Bard or send it as an argument." | ||
# ) |
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 ask_claude
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# print(response)
# answer = {f"answer": "You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument."}["answer"] | ||
answer = f"You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument." | ||
# print(answer) | ||
return answer | ||
|
||
return f"You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument." |
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 ask_chatgpt
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# print(answer)
# answer = {f"answer": "You should set ACCESS_TOKEN in {CONFIG_FILE_NAME} file or send it as an argument."}["answer"]
for i in range(10): | ||
for _ in range(10): |
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 fake_data_streamer_OLD
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for i in range(10): | ||
for _ in range(10): |
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 fake_data_streamer
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if not session_id: | ||
return False | ||
if session_id.lower() == "none": | ||
return False | ||
|
||
return True | ||
return False if not session_id else session_id.lower() != "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 IsSession
refactored with the following changes:
- Lift code into else after jump in control flow [×2] (
reintroduce-else
) - Replace if statement with if expression [×2] (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
filtered_cookies = [ | ||
cookie for cookie in cookies if sessionName.lower() in cookie.name.lower() | ||
] | ||
|
||
result = None | ||
if filtered_cookies: | ||
result = filtered_cookies[-1].value | ||
|
||
return result | ||
return ( | ||
filtered_cookies[-1].value | ||
if ( | ||
filtered_cookies := [ | ||
cookie | ||
for cookie in cookies | ||
if sessionName.lower() in cookie.name.lower() | ||
] | ||
) | ||
else 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 get_Cookie
refactored with the following changes:
- Move setting of default value for variable into
else
branch (introduce-default-else
) - Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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
master
branch, then run: