Skip to main content

Python library for LastMile AI API

Project description

LastMile AI Python Library

This library provides access to the LastMile AI API from Python. The code should reflect the same API endpoints documented here: https://lastmileai.dev/docs/api

API Token

This library requires a LastMile AI API Token, which can be obtained from https://lastmileai.dev/settings?page=tokens.

Important note: this library should only be used from a server-side context, where the API key can be securely accessed. Using this library from client-side browser code will expose your private API key!

Installation

pip install lastmileai

Usage

Initialize Library with API Key

This library needs to be configured with your API Token (aka API key) obtained above. You can store the API key in an environment variable or alternative secure storage that can be accessed in your server-side code. For example, to initialize the library with the API key loaded from environment variable:

import os
from lastmileai import LastMile

lastmile = LastMile(api_key=os.environ["LASTMILEAI_API_KEY"])

Completions -- Open AI Models

OpenAI completions are supported out-of the box for ChatGPT and GPT3 models:

completion = lastmile.create_openai_completion(
  completion_params = {
    model: "text-davinci-003",
    prompt: "Your prompt here",
  }
)
completion = lastmile.create_openai_chat_completion(
  completion_params = {
    model: "gpt-3.5-turbo",
    messages: [
      { role: "user", content: "Your prompt here" },
    ],
  }
)

Completions -- Custom Models

completion = lastmile.create_openai_completion(
  completion_params = {
    model: "text-davinci-003",
    prompt: "Your prompt here",
  },
  embedding_collection_id = "clfpqyvpp004npmzgp1d4j4fw"
)

Run tests

After setting LASTMILEAI_API_KEY in your shell environment, run the following:

pip3 install -e .
python3 -m unittest discover test

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

lastmileai-0.0.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

lastmileai-0.0.3-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file lastmileai-0.0.3.tar.gz.

File metadata

  • Download URL: lastmileai-0.0.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for lastmileai-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c28b2d71c9dd7ed00637e3d9ca8c3b9e92dd0c19ae0a0b30dd9dc74f67ae3e51
MD5 2762d0e94db084163fd06bc12d77588f
BLAKE2b-256 e4a6bf52899987017ec07f0d5ab9abf61c4c91f6a75706f1beb10159f9f67d38

See more details on using hashes here.

File details

Details for the file lastmileai-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: lastmileai-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for lastmileai-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 08f0a1f24645f284927585556f7dd5b522d5c39b80f747fb9173b1fccc3eb806
MD5 fe52b3d2fe631b83a661154d0c2d7da2
BLAKE2b-256 f4a5e1f50e28dc7eaf7ae6f146c0f85241dcb1a4d3b12266ba6ca0f7d1ecdd35

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page