Skip to main content

Using Langchain to parse language to REST API calls.

Project description

REST AI

Leverage AI to parse human language to REST API calls.

Description

Note: this package is still in development. There will be features not yet available, but contributions are welcome.

Features:

  • Translates plain language to rest api requests using an openapi schema
  • Invokes the request, and verifies a correct response
  • Uses reasoned retry logic to try and correct invalid requests

Installation

pip install rest-ai

Usage

To use this package, you must have:

  • An Openapi schema (loaded as a python dictionary)
  • Access to a langchain ChatModel that supports structured outputs
  • Details of the API endpoint to call

Examples

from rest_ai import RestAi
import json
import logging
import sys
from langchain_ollama import ChatOllama

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

base_url = "http://localhost:8000"
file_path = "/path/to/openapi.json"

with open(file_path, "r", encoding="utf-8") as file:
    openapi_spec = file.read()
    openapi_spec = json.loads(openapi_spec)

base_model = ChatOllama(
    base_url="localhost:11434",
    model="llama3.2:3b",
    temperature=0,
)

rest_ai_controller = RestAi(base_url, openapi_spec, base_model)

while True:
    user_input = input("Enter a command to parse into REST API call (or 'exit' to quit): ")
    
    if user_input.lower() == 'exit':
        break
    
    response = rest_ai_controller.invoke(user_input)
    if response:
        print("Response: ")
        print(response.json())

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

rest_ai-0.1.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

rest_ai-0.1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rest_ai-0.1.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for rest_ai-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cc7c2fed5f52deab462d41387b9598cbe68ead933531f5414dbc3705ff8c2456
MD5 7bbb0b19ad6637fc2a4f8e1b3269700f
BLAKE2b-256 c0f67ccb7d204444e80c3460b1cb8e849d40d163c8713bdd9bc12422afb4edd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rest_ai-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for rest_ai-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c89b0c787739e72611b3a443b7666ae4c7072bc919a5bcdcd00f6bd265940a38
MD5 5a0a377b90e2901b07c420ef26277277
BLAKE2b-256 7c0ea04eb460b7e2f53627a40d3b9dc0605718983eeb8a540da15f6a270aca60

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