Skip to content
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

Fix issue with get_cookies from nodriver in OpenaiChat #2495

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

hlohaus
Copy link
Collaborator

@hlohaus hlohaus commented Dec 18, 2024

No description provided.

@hlohaus hlohaus merged commit 43deaec into xtekky:main Dec 18, 2024
1 check passed
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Review for Pull Request: Fix issue with get_cookies from nodriver in OpenaiChat

Summary

Thank you, H Lohaus, for your contribution to the project! This pull request addresses an issue with the get_cookies function in the OpenaiChat provider, enhancing the handling of cookies when using the nodriver option. The changes made are well-structured and improve the overall functionality.

Changes

  • Added checks for has_nodriver and has_curl_cffi to ensure proper handling of arguments and cookies.
  • Improved the get_models and create_async_generator methods to handle cases where nodriver is not available.
  • Updated the login method to yield a login URL if required, enhancing user experience.
  • Refactored the get_cookies function to streamline cookie retrieval.

Code Quality

  • The code is clean and follows the project's coding standards.
  • The use of conditional checks for has_nodriver and has_curl_cffi is a good practice to ensure compatibility.
  • The addition of comments would further enhance readability, especially in complex sections.

Suggestions

  • Consider adding unit tests to cover the new functionality introduced in this pull request. This will help ensure that future changes do not break the intended behavior.
  • A brief description in the pull request description would be helpful for reviewers to understand the context of the changes.

Conclusion

Overall, this is a solid contribution that improves the functionality of the OpenaiChat provider. Thank you again for your hard work and dedication to enhancing this project!

Looking forward to your future contributions!

get_running_loop(check_nested=True)
args = get_args_from_nodriver(cls.url)
cls._args = asyncio.run(args)
elif not has_curl_cffi:

Choose a reason for hiding this comment

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

The condition elif not has_curl_cffi: should be reconsidered. If has_nodriver is false, it may be more appropriate to handle the case where neither has_nodriver nor has_curl_cffi is available.

try:
raise_for_status(response)
except ResponseStatusError:
cls._args = None
raise
return cls.models

Choose a reason for hiding this comment

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

Returning cls.models in the exception handling block may lead to unexpected behavior. Consider whether this is the intended outcome.

@@ -62,10 +66,10 @@
**kwargs
) -> AsyncResult:
if cls._args is None:
try:
if has_nodriver:
cls._args = await get_args_from_nodriver(cls.url, proxy, timeout, cookies)

Choose a reason for hiding this comment

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

The try-except block should be structured to handle the case where has_nodriver is false. This could lead to unhandled exceptions if get_args_from_nodriver fails.

@@ -76,10 +77,13 @@ def create_completion(
cls._access_token, cls._cookies = readHAR(cls.url)
except NoValidHarFileError as h:
debug.log(f"Copilot: {h}")
try:
if has_nodriver:
login_url = os.environ.get("G4F_LOGIN_URL")

Choose a reason for hiding this comment

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

Consider providing a default URL or handling the case where G4F_LOGIN_URL is not set to avoid a potential None or empty string causing issues in the login process.

if has_nodriver:
login_url = os.environ.get("G4F_LOGIN_URL")
if login_url:
yield f"[Login to {cls.label}]({login_url})\n\n"

Choose a reason for hiding this comment

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

Ensure that the generated markdown link from login_url is safe and cannot be exploited by inserting unintended markdown syntax or URLs (e.g., checking that the URL is well-formed and valid).

@@ -116,6 +117,8 @@
font-weight: 500;
background-color: rgba(0, 0, 0, 0.5);
color: var(--colour-3);
border: var(--colour-1) 1px solid;

Choose a reason for hiding this comment

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

The addition of border: var(--colour-1) 1px solid; could potentially lead to visual inconsistencies if --colour-1 is not defined properly. Verify that this variable is set and used consistently throughout the stylesheet.

@@ -116,6 +117,8 @@
font-weight: 500;
background-color: rgba(0, 0, 0, 0.5);
color: var(--colour-3);
border: var(--colour-1) 1px solid;
border-radius: var(--border-radius-1);

Choose a reason for hiding this comment

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

The addition of border-radius: var(--border-radius-1); should be checked to ensure that --border-radius-1 is defined. If not, it may cause unexpected rendering issues.

@@ -826,6 +825,9 @@
.count_total {
padding-left: 98px;
}
body:not(.white) .gradient{

Choose a reason for hiding this comment

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

The new rule body:not(.white) .gradient { display: block; } should be reviewed to confirm that it does not conflict with other styles. Ensure that the intended behavior is clear and does not introduce layout issues.

@@ -601,6 +601,7 @@ const ask_gpt = async (message_id, message_index = -1, regenerate = false, provi
api_key: api_key,
ignored: ignored,
}, files, message_id);
if (content_map.inner.dataset.timeout) clearTimeout(content_map.inner.dataset.timeout);

Choose a reason for hiding this comment

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

Consider checking if content_map.inner is defined before accessing dataset.timeout to avoid potential runtime errors.

}
let cursorDiv = message_el.querySelector(".cursor");

Choose a reason for hiding this comment

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

The variable cursorDiv is declared twice in this scope. Remove the first declaration to avoid redundancy.

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.

1 participant