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
Find out more about the package at https://aashishmehta.com/rest-ai-queries-making-apis-smarter/
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rest_ai-0.1.3.tar.gz.
File metadata
- Download URL: rest_ai-0.1.3.tar.gz
- Upload date:
- Size: 4.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4263480ac50ac5ad0f8ee663fa2f05dfb9df38282a2485937f9212c59fbe8b49
|
|
| MD5 |
bc62c897d745516aee649deaf331e71d
|
|
| BLAKE2b-256 |
061dd53bc68b0506c934345ce22a00fb4a205b28864462c87701127a0ce6355d
|
File details
Details for the file rest_ai-0.1.3-py3-none-any.whl.
File metadata
- Download URL: rest_ai-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe3b3b9025bd0b8065bda94f603111fe349045ad594ec6cd3afda75b125f38fb
|
|
| MD5 |
d24fb15043f4400004ef42dd56cad786
|
|
| BLAKE2b-256 |
f8ffca6c563cea98264ec1ff345ac9d731f6b87b5b0c1e36b3e0114341151a3c
|