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

Even lazier imports #598

Merged
merged 2 commits into from
Nov 11, 2024
Merged

Even lazier imports #598

merged 2 commits into from
Nov 11, 2024

Conversation

billytrend-cohere
Copy link
Collaborator

@billytrend-cohere billytrend-cohere commented Nov 7, 2024

This PR introduces streaming support for the Chat API, allowing it to generate text responses to user messages and stream them down token by token. The changes are as follows:

  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.types module.
  • The ChatDebugEvent class is imported into the cohere.types.__init__ module.
  • The DebugStreamedChatResponse class is imported into the cohere.types.streamed_chat_response module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.types.chat_debug_event module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.__init__ module.
  • The DebugStreamedChatResponse class is added to the cohere.types.streamed_chat_response module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.types.chat_debug_event module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and DebugStreamedChatResponse classes are added to the cohere.v2.client module.
  • The ChatDebugEvent and

Copy link

@jasonozuzu-cohere jasonozuzu-cohere left a comment

Choose a reason for hiding this comment

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

This all works but a slightly more efficient way of doing this would be to cache the import in globals, so something like:

def lazy_safemaker():
  try:
   if 'sagemaker' not in globals():
        try:
            import sagemaker as sage
        except ImportError:
            raise ImportError("sagemaker is not available. Please install it with 'pip install sagemaker'.")
        globals()['sagemaker'] = sage
    return globals()['sagemaker']

This will ensure that you aren't reimporting for every usage of the method, although I think Python handles double imports under the hood so feel free to ignore this - can be merged as is

@billytrend-cohere billytrend-cohere merged commit 9c1e66d into main Nov 11, 2024
4 checks passed
@billytrend-cohere billytrend-cohere deleted the lazify branch November 11, 2024 16:37
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.

2 participants