Skip to main content

The module defines a custom chat model that interacts with the Lilypad API to generate conversational responses and bind tools for enhanced functionality, with mechanisms for parsing tool calls and customizing message payloads.

Project description

ChatLilypad

ChatLilypad is a customizable chat model built on the LangChain framework. It connects seamlessly to the Lilypad API and extends the functionality of traditional chat models by offering tool binding capabilities. This module empowers developers to create dynamic, intelligent conversational agents tailored to their needs.

Table of Contents

  1. Overview
  2. Features
  3. Getting Started
  4. Dependencies
  5. Usage
  6. Customization
  7. License

Overview

ChatLilypad is designed to facilitate robust and scalable conversations by integrating a custom chat model with external tools using the Lilypad API. It supports tool binding, dynamic message formatting, and response generation while allowing developers to extend its capabilities to meet specific application requirements.

Features

  • Custom Chat Model: Uses Lilypad API to generate responses dynamically.
  • Tool Binding: Allows integration of external tools to enhance conversational capabilities.
  • High Configurability: Supports custom model parameters like temperature, tool configurations, and API endpoints.
  • Error Handling: Graceful fallback mechanisms for API connectivity or response parsing failures.
  • Extendable: Built on LangChain to support further modular development.

Getting Started

Prerequisites

To use ChatLilypad, ensure you have the following installed:

  • Python 3.8+
  • Pip (Python package manager)
  • API key for the Lilypad API

Dependencies

The following Python packages are required:

  • requests: For making HTTP API calls.
  • json: For JSON serialization and deserialization.
  • pydantic: For data validation and model properties.
  • langchain_core: Provides the base classes and functionality for chat models.

You can install all dependencies by running:

pip install requests pydantic langchain-core

Installation

pip install langchain-lilypad 

Usage

Here's a quick example of how to use ChatLilypad in your Python application:

Step 1: Import the Class

from langchain_lilypad import ChatLilypad

Step 2: Initialize the Model

Provide your Lilypad API key and model name:

lilypad_model = ChatLilypad(
    model_name="your_model_name",
    api_key="your_api_key"
)

Available Models:

  • "deepscaler:1.5b"
  • "gemma3:4b"
  • "llama3.1:8b"
  • "llava:7b"
  • "mistral:7b"
  • "openthinker:7b"
  • "phi4-mini:3.8b"
  • "deepseek-r1:7b"
  • "phi4:14b"
  • "qwen2.5:7b"
  • "qwen2.5-coder:7b"

Step 3: Bind Tools (Optional)

You can enhance the chat model by binding external tools. For example:

from langchain_community.tools import DuckDuckGoSearchResults
from langchain_core.tools import tool

search = DuckDuckGoSearchResults(safesearch = "strict", max_results = 10)

@tool
def websearch(webprompt:str) -> str:
    """This tool allows users to perform accurate and targeted internet searches for specific terms or phrases. It activates whenever the user explicitly requests a web search, seeks real-time or updated information, or mentions terms like 'search,' 'latest,' or 'current' related to the desired topic."""
    res = search.invoke(webprompt)
    return res

lilypad_model = lilypad_model.bind_tools([sample_tool])

Step 4: Generate Responses

Send a list of messages to generate a response:

from langchain_core.messages import BaseMessage

messages = [
    BaseMessage(type="human", content="Tell me a joke!"),
]

response = lilypad_model.invoke(messages)

print({"messages": [response]})

Customization

The ChatLilypad class can be customized in the following ways:

  1. Adjusting Temperature: Modify the temperature parameter to control randomness in responses.

    lilypad_model.temperature = 0.8
    
  2. Changing API Endpoint: Update the api_url to connect to a different API endpoint.

    lilypad_model.api_url = "https://new-api-endpoint.com"
    
  3. Adding Tools: Use the bind_tools method to integrate external tools dynamically.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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_lilypad-0.1.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_lilypad-0.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_lilypad-0.1.1.tar.gz.

File metadata

  • Download URL: langchain_lilypad-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for langchain_lilypad-0.1.1.tar.gz
Algorithm Hash digest
SHA256 57cfc427fd5da3cfd78e74bc62742a7a947cab0930a9df245ef6adf3887c0448
MD5 2ae3a98aaf9096fc0220a4f2bae1d436
BLAKE2b-256 b481ab4abe1349a17b643cd2ca608f14f36c4a5a8e39db4dbaca96373ae3b282

See more details on using hashes here.

File details

Details for the file langchain_lilypad-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_lilypad-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aae9a5973c9959dec845a3cbb19da566f7b54a7f44f143720b2e055d432f5e3c
MD5 ce5bb9e0695203be5b29fe3bb2933792
BLAKE2b-256 e27eeb78b589dd8dbb3e7a5d8a24713565ad4b1a1f1dce56134a3e2ea39703c4

See more details on using hashes here.

Supported by

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