This module provides a command-line interface for interacting with Llama models through the Llama API.
The api_inference.py script allows you to:
- Connect to Llama's API using your API key
- Launch a Gradio web interface for sending prompts to Llama models
- Get completions from models like Llama-4-Maverick-17B
- Python 3.8 or higher
- A valid Llama API key
- Required Python packages:
- gradio
- llama_api_client
Ensure you have the required packages installed:
pip install gradio llama_api_clientYou can run the script from the command line using:
python api_inference.py [OPTIONS]--api-key: Your Llama API key (optional)- If not provided, the script will look for the
LLAMA_API_KEYenvironment variable
- If not provided, the script will look for the
You can provide your API key in one of two ways:
-
Command-line argument:
python api_inference.py --api-key YOUR_API_KEY
-
Environment variable:
# For bash/zsh export LLAMA_API_KEY=YOUR_API_KEY # For Windows Command Prompt set LLAMA_API_KEY=YOUR_API_KEY # For PowerShell $env:LLAMA_API_KEY="YOUR_API_KEY"
-
Run the script:
python api_inference.py --api-key YOUR_API_KEY
-
The script will launch a Gradio web interface (typically at http://127.0.0.1:7860)
-
In the interface:
- Enter your prompt in the text box
- The default model is "Llama-4-Maverick-17B-128E-Instruct-FP8" but you can change it
- Click "Submit" to get a response from the model
If you see an error like:
No API key provided and *_API_KEY environment variable not found
Make sure you've either:
- Passed the API key using the
--api-keyargument - Set the appropriate environment variable
- There appears to be a reference to
args.providerin the code, but no provider argument is defined in the ArgumentParser. - The script uses
Optional[str]but doesn't import it from typing.
You can modify the script to use different models or customize the Gradio interface as needed.
[Include license information here]