Skip to main content

A LangChain integration for HuggingChat models

Project description

langchain_huggy

langchain_huggy is a Python package that provides an easy-to-use interface for interacting with HuggingChat models through the LangChain framework. It allows you to leverage powerful language models in your applications with minimal setup.

Available Models

langchain_huggy comes with several pre-configured models:

  1. 'meta-llama/Meta-Llama-3.1-70B-Instruct'
  2. 'CohereForAI/c4ai-command-r-plus-08-2024'
  3. 'Qwen/Qwen2.5-72B-Instruct' (default)
  4. 'meta-llama/Llama-3.2-11B-Vision-Instruct'
  5. 'NousResearch/Hermes-3-Llama-3.1-8B'
  6. 'mistralai/Mistral-Nemo-Instruct-2407'
  7. 'microsoft/Phi-3.5-mini-instruct'

You can choose any of these models when initializing the HuggingChat instance.

Installation

Install the package using pip:

pip install langchain_huggy

Quick Start

Here's a simple example to get you started:

from langchain_huggy import HuggingChat
from langchain_core.messages import HumanMessage

# Initialize the HuggingChat model
llm = HuggingChat(
    hf_email="your_huggingface_email@example.com",
    hf_password="your_huggingface_password",
    model="Qwen/Qwen2.5-72B-Instruct"  # Optional: specify a model
)

# Generate a response
response = llm.invoke("hi!")
print(response.content)

# Stream a response
llm.stream("Tell me a short story about a robot.")

# Get web Search results set web_search = True
llm.invoke("latest climate news",web_search = True)
llm.stream("Tell me a short story about a robot.",web_search = True)

Features

  • Easy integration with LangChain
  • WebSearch Hurray!!!
  • Support for multiple HuggingChat models
  • Built-in error handling and type checking

Configuration

You can configure the HuggingChat instance with the following parameters:

  • hf_email: Your HuggingFace account email
  • hf_password: Your HuggingFace account password
  • model: (Optional) Specify a particular model to use from the available models list

Available Methods

  • invoke: Generate a complete response for given input
  • generate: Generate a ChatResult object (compatible with LangChain)
  • stream: Stream the response as an iterator of message chunks
  • pstream: Print the streamed response directly to console

Viewing Available Models

You can view the list of available models at any time using:

print(llm.get_available_models)

Error Handling

The package includes built-in error handling. If you encounter any issues during streaming or generation, informative error messages will be printed to the console.

Note on Credentials

Make sure to keep your HuggingFace credentials secure. You can set them as environment variables:

export HUGGINGFACE_EMAIL="your_email@example.com"
export HUGGINGFACE_PASSWD="your_password"

Never share your credentials in public repositories or include them directly in your code.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any problems or have any questions, please open an issue on the GitHub repository.

Happy chatting with langchain_huggy!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_huggy-0.1.8.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

langchain_huggy-0.1.8-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_huggy-0.1.8.tar.gz.

File metadata

  • Download URL: langchain_huggy-0.1.8.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for langchain_huggy-0.1.8.tar.gz
Algorithm Hash digest
SHA256 ffd5ed6e552018b9115f9be0848669f9d9269c758692188d9393146e4da79d05
MD5 6e77f1f9a9a2141a414f5cacd79b4835
BLAKE2b-256 7c804b90b222b2cacb0fe8c6a5d6a44eeb93d18b75e90dff28800c53d5f7971d

See more details on using hashes here.

File details

Details for the file langchain_huggy-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: langchain_huggy-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for langchain_huggy-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fa746d7e6646fef9968c4ddd4ccd4a278225acc66145d554bd82ddffa057d607
MD5 be2a6611b4b640ee3fa26bb06784d17b
BLAKE2b-256 e92db41c04357a47a83733368429b8bf9d28ab16672174cc15c4f060e0e1acc7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page