Skip to main content

A unified tool to generate fine-tuning datasets for LLMs, including questions, answers, and dialogues.

Project description

EDG4LLM

Table of Contents

Features

  • Convert OpenAPI specifications into LLM-compatible tool/function definitions
  • Support for multiple LLM providers (OpenAI, Anthropic, Cohere)
  • Handle complex request bodies and parameter types
  • Support for multiple authentication mechanisms
  • Support for OpenAPI 3.0.x and 3.1.x specifications
  • Handles both YAML and JSON OpenAPI specifications

Installation

pip install openapi-llm

Supported Python Versions

  • Python >= 3.8

LLM Provider Dependencies

This library focuses on OpenAPI-to-LLM conversion and doesn't include LLM provider libraries by default. Install the ones you need:

# For OpenAI
pip install openai

# For Anthropic
pip install anthropic

# For Cohere
pip install cohere

Library Scope

OpenAPI-LLM provides core functionality for converting OpenAPI specifications into LLM-compatible tool/function definitions. It intentionally does not provide an opinionated, high-level interface for OpenAPI-LLM interactions. Users are encouraged to develop their own thin application layer above this library that suits their specific needs and preferences for OpenAPI-LLM integration.

OpenAPI Specification Validation

This library does not perform OpenAPI specification validation. It is the user's responsibility to ensure that the provided OpenAPI specifications are valid. We recommend using established validation tools such as:

Example of validating a spec before using it with openapi-llm:

from openapi_spec_validator import validate_spec
import yaml

# Load and validate your OpenAPI spec
with open('your_spec.yaml', 'r') as f:
    spec_dict = yaml.safe_load(f)
validate_spec(spec_dict)

Quick Start

Here's a practical example using OpenAI to perform a Google search via SerperDev API:

import os
from openai import OpenAI

from openapi_llm.client.config import ClientConfig
from openapi_llm.client.openapi import OpenAPIClient
from openapi_llm.core.spec import OpenAPISpecification


# Configure the OpenAPI client with SerperDev API spec and credentials
config = ClientConfig(
    openapi_spec=OpenAPISpecification.from_url("https://bit.ly/serperdev_openapi"), 
    credentials=os.getenv("SERPERDEV_API_KEY")
)

# Initialize OpenAI client
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

# Create a chat completion with tool definitions
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Do a serperdev google search: Who was Nikola Tesla?"}],
    tools=config.get_tool_definitions(),
)

# Execute the API call based on the LLM's response
service_api = OpenAPIClient(config)
service_response = service_api.invoke(response)

This example demonstrates:

  • Loading an OpenAPI specification from a URL
  • Integrating with OpenAI's function calling
  • Handling API authentication
  • Converting and executing OpenAPI calls based on LLM responses

Requirements

  • Python >= 3.8
  • Dependencies:
    • jsonref
    • requests
    • PyYAML

Development Setup

  1. Clone the repository
git clone https://github.com/vblagoje/openapi-llm.git
  1. Install hatch if you haven't already
pip install hatch
  1. Install pre-commit hooks
pre-commit install
  1. Install desired LLM provider dependencies (as needed)
pip install openai anthropic cohere

Testing

Run tests using hatch:

# Unit tests
hatch run test:unit

# Integration tests
hatch run test:integration

# Type checking
hatch run test:typing

# Linting
hatch run test:lint

License

MIT License - See LICENSE for details.

Security

For security concerns, please see our Security Policy.

Contributing

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

Author

Vladimir Blagojevic (dovlex@gmail.com)

Reviews and guidance by Madeesh Kannan

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

edg4llm-1.0.6.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

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

edg4llm-1.0.6-py3-none-any.whl (40.4 kB view details)

Uploaded Python 3

File details

Details for the file edg4llm-1.0.6.tar.gz.

File metadata

  • Download URL: edg4llm-1.0.6.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.0

File hashes

Hashes for edg4llm-1.0.6.tar.gz
Algorithm Hash digest
SHA256 6cb9afb5de89ba648634fbf316990816c13d3441e5e37a2f00e664f7e00419c6
MD5 b9483e5540c8953a01d495286f364a09
BLAKE2b-256 40d0da5b75a9a4defa8c944d60c8243db41cedcac6db9cb07c16418a7c8ef189

See more details on using hashes here.

File details

Details for the file edg4llm-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: edg4llm-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 40.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.0

File hashes

Hashes for edg4llm-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 71b2ad4c8cd2c06aa204219046480d0190d05669f1ef6aa67de134db1560e793
MD5 9e9d8457db70339536a7c46839fd2e0f
BLAKE2b-256 32268a1e3173dbc1af787436ec0b78abaa222ee34aa07202e0887b8aeefe9eef

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