Skip to main content

ChatLilypad

ChatLilypad is a powerful and customizable chat model built on the LangChain framework. It integrates seamlessly with the Lilypad API, extending the functionality of traditional chat models through tool binding, structured output, and workflow integration. This module empowers developers to create dynamic, intelligent conversational agents tailored to their unique needs.

Overview

ChatLilypad is designed to facilitate intelligent, scalable conversations by combining a custom chat model with external tools via the Lilypad API. The model supports structured responses, tool binding, and graph and workflow integration while providing high configurability for advanced use cases.

Features

  • Lilypad Chat Model: Dynamically generates responses using the Lilypad API.
  • Tool Integration: Connects external tools to expand conversational capabilities.
  • High Configurability: Allows developers to modify parameters like temperature, API endpoints, and tool configurations.
  • Structured Output: Delivers organized, schema-defined responses for improved validation.
  • Error Handling: Incorporates fallback mechanisms for API connectivity and parsing issues.
  • Extendable Design: Built on LangChain, enabling modular development and scalability.

Setup

Prerequisites

To use ChatLilypad, ensure you have:

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

Dependencies

Required Python packages:

  • requests: For HTTP API communication.
  • json: For data serialization and deserialization.
  • pydantic: For data validation and model schema definitions.
  • langchain_core: Core classes and functionality for chat models.

Install all dependencies:

pip install requests pydantic langchain-core

Installation

To install the ChatLilypad module:

pip install langchain-lilypad

Usage

Initializing the Model

Import and initialize ChatLilypad with your Lilypad API key and the model name:

from langchain_lilypad import ChatLilypad

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

Generating Responses

Send a list of messages to the model to generate intelligent responses:

from langchain_core.messages import BaseMessage

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

response = lilypad_model.invoke(messages)
print({"messages": [response]})

Customization

Adjusting Temperature

Control the randomness of responses by modifying the temperature parameter:

lilypad_model.temperature = 0.8

Changing the API Endpoint

Connect to a custom API endpoint by updating the api_url:

lilypad_model.api_url = "https://new-api-endpoint.com"

Tool Integration

Tooling enhances ChatLilypad's capabilities by enabling seamless integration with external APIs and resources.

Supported Models

Currently, only the following models support tooling:

  • llama3.1:8b
  • qwen2.5:7b
  • qwen2.5-coder:7b
  • phi4-mini:3.8b
  • mistral:7b

Defining and Binding Tools

Tools can be defined and dynamically bound to the model. 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:
    """Performs accurate web searches based on user input."""
    return search.invoke(webprompt)

lilypad_model = lilypad_model.bind_tools([websearch])

Once bound, tools enable enhanced interaction during conversations.

Structured Output

ChatLilypad supports structured output for organized and schema-compliant responses.

Defining Structured Output

Define structured schemas using Pydantic models:

from pydantic import BaseModel, Field
from typing import Optional

class Joke(BaseModel):
    """Joke to tell user."""
    setup: str = Field(description="The setup of the joke")
    punchline: str = Field(description="The punchline of the joke")
    rating: Optional[int] = Field(default=None, description="How funny the joke is (1-10)")

Example Usage

Bind the structured schema to the model:

structured_llm = lilypad_model.with_structured_output(Joke)
response = structured_llm.invoke("Tell me a joke")
print(response)

This ensures that generated responses conform to the Joke schema, improving validation and usability.

License

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

Metadata

Release files for langchain-lilypad 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-lilypad 0.1.4
File Size Uploaded
langchain_lilypad-0.1.4.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-lilypad 0.1.4
File Interpreter ABI Platform
langchain_lilypad-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / langchain_lilypad-0.1.4.tar.gz

Download URL langchain_lilypad-0.1.4.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e65a79da3d8912d7242da6729684af60c2584bb5b4ef47588bd345a2840e5726
BLAKE2b-256 checksum
How to use checksums
54b0ef3bc14de596957be1d53b5807d1b647adb8a70d73b55241227d32a38ec2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / langchain_lilypad-0.1.4-py3-none-any.whl

Download URL langchain_lilypad-0.1.4-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41b7fff2bf0697a0e181f1d2ca66e68d855b929d4bd1bf7106b626480d9d5e23
BLAKE2b-256 checksum
How to use checksums
a325a731925610854ebf3f265d528e031ea6fa10420e42babec670a8ebbb30ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page