Foundry Local Manager Python SDK: Control-plane SDK for Foundry Local.
Project description
Foundry Local Python SDK
The Foundry Local SDK simplifies AI model management in local environments by providing control-plane operations separate from data-plane inferencing code.
Prerequisites
Foundry Local must be installed and findable in your PATH.
Getting Started
pip install foundry-local-sdk
Usage
The SDK provides a simple interface to interact with the Foundry Local API. You can use it to manage models, check the status of the service, and make requests to the models.
Bootstrapping
The SDK can bootstrap Foundry Local, which will initiate the following sequence:
- Start the Foundry Local service, if it is not already running.
- Automatically detect the hardware and software requirements for the model.
- Download the highest-performance model for the detected hardware, if it is not already downloaded.
- Load the model into memory.
To use the SDK with bootstrapping, you can use the following code:
from foundry_local import FoundryLocalManager
# Provide the alias of the model you want to use
# The alias is a string that identifies the model in the Foundry Local catalog.
# The alias can be found in the Foundry Local catalog.
# For example, "phi-3.5-mini" is the alias for the Phi 3.5 model.
# Foundry local will automatically download the most suitable model for your hardware.
alias = "phi-3.5-mini"
fl_manager = FoundryLocalManager(alias)
# check that the service is running
print(fl_manager.is_service_running())
# list all available models in the catalog
print(fl_manager.list_catalog_models())
# list all downloaded models
print(fl_manager.list_cached_models())
# get information on the selected model
model_info = fl_manager.get_model_info(alias)
print(model_info)
Alternatively, you can use the FoundryLocalManager class to manage the service and models manually. This is useful if you want to control the service and models without bootstrapping. For example, you want to present to the end user what is happening in the background.
from foundry_local import FoundryLocalManager
alias = "phi-3.5-mini"
fl_manager = FoundryLocalManager()
# start the service
fl_manager.start_service()
# download the model
fl_manager.download_model(alias)
# load the model
model_info = fl_manager.load_model(alias)
print(model_info)
Use the foundry local endpoint with an OpenAI compatible API client. For example, using the openai package:
import openai
from foundry_local import FoundryLocalManager
# By using an alias, the most suitable model will be downloaded
# to your end-user's device.
alias = "phi-3.5-mini"
# Create a FoundryLocalManager instance. This will start the Foundry
# Local service if it is not already running and load the specified model.
manager = FoundryLocalManager(alias)
# The remaining code us es the OpenAI Python SDK to interact with the local model.
# Configure the client to use the local Foundry service
client = openai.OpenAI(
base_url=manager.endpoint,
api_key=manager.api_key # API key is not required for local usage
)
# Set the model to use and generate a streaming response
stream = client.chat.completions.create(
model=manager.get_model_info(alias).id,
messages=[{"role": "user", "content": "What is the golden ratio?"}],
stream=True
)
# Print the streaming response
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="", flush=True)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 foundry_local_sdk-0.3.1-py3-none-any.whl.
File metadata
- Download URL: foundry_local_sdk-0.3.1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52846d76c953ee4cd3fff9613781912a434a90b022248dc7bf4b61544970cda9
|
|
| MD5 |
d6a0213a42fceab6f1123eb207f93968
|
|
| BLAKE2b-256 |
9f5a7a53fcdb3c5cbf13a09119921910cc578969246d095cd65abbd85d93ea7b
|