Skip to content

Conversation

ParthSareen
Copy link
Member

@ParthSareen ParthSareen commented Feb 13, 2025

  • added support for context manager protocol
  • added explicit .close() method to manage clients

Previously a ResourceWarning was getting thrown:

<sys>:0: ResourceWarning: unclosed <socket.socket fd=3, family=2, type=1, proto=6, laddr=('127.0.0.1', 57073), raddr=('127.0.0.1', 11434)>

This can now be prevented with the client.close() method or by using Python's context manager protocol.
Users can now also use client with context manager protocol as:

with Client() as client:
    messages = [
      {
        'role': 'user',
        'content': 'Why is the sky blue?',
      },
    ]

    response = client.chat('llama3.2', messages=messages)
    print(response['message']['content'])

Closes: #441

@ParthSareen ParthSareen force-pushed the parth/client-resource-cleanup branch from 37c7817 to 1a047b0 Compare February 14, 2025 06:28
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.

Unable to close connections
2 participants