Skip to main content

SDK for integrating purchased graphs from the lmsystems marketplace.

Reason this release was yanked:

Security vulnerability - please upgrade to 1.0.8

Project description

LMSystems SDK

The LMSystems SDK provides flexible interfaces for integrating and executing purchased graphs from the LMSystems marketplace in your Python applications. The SDK offers two main approaches:

  1. PurchasedGraph Class: For seamless integration with LangGraph workflows
  2. LmsystemsClient: For direct, low-level interaction with LMSystems graphs, offering more flexibility and control

Try it in Colab

Get started quickly with our interactive Colab notebook: Open In Colab

This notebook provides a hands-on introduction to the LMSystems SDK with ready-to-run examples.

Installation

Install the package using pip:

pip install lmsystems

Quick Start

Using the Client SDK

The client SDK provides direct interaction with LMSystems graphs:

from lmsystems.client import LmsystemsClient
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Async usage
async def main():
    # Simple initialization with just graph name and API key
    client = await LmsystemsClient.create(
        graph_name="graph-name-id",
        api_key=os.environ["LMSYSTEMS_API_KEY"]
    )

    # Create thread and run with error handling
    try:
        thread = await client.create_thread()

        # No need to provide config - it's handled through your account settings
        run = await client.create_run(
            thread,
            input={"messages": [{"role": "user", "content": "What's this repo about?"}],
                  "repo_url": "",
                  "repo_path": "",
                  "github_token": ""}
        )

        # Stream response
        async for chunk in client.stream_run(thread, run):
            print(chunk)

    except Exception as e:
        print(f"Error: {str(e)}")

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

Using PurchasedGraph with LangGraph

For integration with LangGraph workflows:

from lmsystems.purchased_graph import PurchasedGraph
from langgraph.graph import StateGraph, START, MessagesState
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Set required state values
state_values = {
    "repo_url": "https://github.com/yourusername/yourrepo",
    "github_token": "your-github-token",
    "repo_path": "/path/to/1234322"
}

# Initialize the purchased graph - no config needed!
purchased_graph = PurchasedGraph(
    graph_name="github-agent-6",
    api_key=os.environ.get("LMSYSTEMS_API_KEY"),
    default_state_values=state_values
)

# Create a parent graph with MessagesState schema
builder = StateGraph(MessagesState)
builder.add_node("purchased_node", purchased_graph)
builder.add_edge(START, "purchased_node")
graph = builder.compile()

# Invoke the graph
result = graph.invoke({
    "messages": [{"role": "user", "content": "what's this repo about?"}]
})

# Stream outputs (optional)
for chunk in graph.stream({
    "messages": [{"role": "user", "content": "what's this repo about?"}]
}, subgraphs=True):
    print(chunk)

Configuration

API Keys and Configuration

The SDK now automatically handles configuration through your LMSystems account. To set up:

  1. Create an account at LMSystems
  2. Navigate to your account settings
  3. Configure your API keys (OpenAI, Anthropic, etc.)
  4. Generate your LMSystems API key

Your configured API keys and settings will be automatically used when running graphs - no need to include them in your code!

Note: While configuration is handled automatically, you can still override settings programmatically if needed:

# Optional: Override stored config
config = {
    "configurable": {
        "model": "gpt-4",
        "openai_api_key": "your-custom-key"
    }
}
purchased_graph = PurchasedGraph(
    graph_name="github-agent-6",
    api_key=os.environ.get("LMSYSTEMS_API_KEY"),
    config=config  # Optional override
)

Store your LMSystems API key securely using environment variables:

export LMSYSTEMS_API_KEY="your-api-key"

API Reference

LmsystemsClient Class

LmsystemsClient.create(
    graph_name: str,
    api_key: str
)

Parameters:

  • graph_name: Name of the graph to interact with
  • api_key: Your LMSystems API key

Methods:

  • create_thread(): Create a new thread for graph execution
  • create_run(thread, input): Create a new run within a thread
  • stream_run(thread, run): Stream the output of a run
  • get_run(thread, run): Get the status and result of a run
  • list_runs(thread): List all runs in a thread

PurchasedGraph Class

PurchasedGraph(
    graph_name: str,
    api_key: str,
    config: Optional[RunnableConfig] = None,
    default_state_values: Optional[dict[str, Any]] = None
)

Parameters:

  • graph_name: Name of the purchased graph
  • api_key: Your LMSystems API key
  • config: Optional configuration for the graph
  • default_state_values: Default values for required state parameters

Methods:

  • invoke(): Execute the graph synchronously
  • ainvoke(): Execute the graph asynchronously
  • stream(): Stream graph outputs synchronously
  • astream(): Stream graph outputs asynchronously

Error Handling

The SDK provides specific exceptions for different error cases:

  • AuthenticationError: API key or authentication issues
  • GraphError: Graph execution or configuration issues
  • InputError: Invalid input parameters
  • APIError: Backend communication issues

Example error handling:

from lmsystems.exceptions import LmsystemsError

try:
    result = graph.invoke(input_data)
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except GraphError as e:
    print(f"Graph execution failed: {e}")
except InputError as e:
    print(f"Invalid input: {e}")
except APIError as e:
    print(f"API communication error: {e}")
except LmsystemsError as e:
    print(f"General error: {e}")

Support

For support, feature requests, or bug reports:

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

lmsystems-0.1.2.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

lmsystems-0.1.2-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lmsystems-0.1.2.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.9

File hashes

Hashes for lmsystems-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f518c2021f2f89a2bfff3df0ef26c4da197bab0d7ab1828ae440a53935f2698a
MD5 4f5e8a7e1ebae3fec9bca813aa80a4d6
BLAKE2b-256 7437e6ffb073060c9cf6744711386b171c32a9ec05e8a23e508aa646740dadca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lmsystems-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.9

File hashes

Hashes for lmsystems-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8cad1230ae1398ece55528d87d6c468a3b4880183f8bf707237999ad8836e7e6
MD5 bc26bc507634683924c7bddf387bb034
BLAKE2b-256 057fe3e49a0415c0eb30ec9c56eb0ab08eb6e592d6f69ecdff8fa4ddc4ec3c9f

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