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.2.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.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_lilypad-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 cab1693d20443a737b9e02ae36a64770d7301d9dafd6531f94ad719e6d3bd5fd
MD5 a7dfc9139e5dfb0aba8700a7236e6fb8
BLAKE2b-256 078d5fe2e7e22e6c3c72e8bc8d0f0610b118b77b216f4eacbaf2084174d1c2cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_lilypad-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3490f97f65cc80f31a771415adbbc12ff33fef606a79a705c1742a3ce76a0301
MD5 44846a44bf7fc5cf1dc2af346426a2cc
BLAKE2b-256 cb860a10fef9f11d2111f0c573270e2a4ab8956f6441f86274d6f54c5d88b4d8

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