|
před 1 dnem | |
---|---|---|
.. | ||
README.md | před 1 dnem | |
api_inference.py | před 1 dnem | |
llama_inference_api.ipynb | před 1 dnem |
This module provides a command-line interface for interacting with Llama models through the Llama API.
The api_inference.py
script allows you to:
Ensure you have the required packages installed:
pip install gradio llama_api_client
You can run the script from the command line using:
python api_inference.py [OPTIONS]
--api-key
: Your API key (optional)
--provider
: API provider to use (optional, default: "Llama")
You can provide your API key in one of two ways:
Command-line argument:
python api_inference.py --api-key YOUR_API_KEY --provider Llama
Environment variable: The environment variable name depends on the provider you choose: ```bash
export LLAMA_API_KEY=YOUR_API_KEY
# For OpenAI export OPENAI_API_KEY=YOUR_API_KEY
For Windows:
```bash
# Command Prompt (example for Llama)
set LLAMA_API_KEY=YOUR_API_KEY
# PowerShell (example for Llama)
$env:LLAMA_API_KEY="YOUR_API_KEY"
Run the script: ```bash
python api_inference.py --api-key YOUR_API_KEY
# Using a different provider python api_inference.py --api-key YOUR_API_KEY --provider OpenAI
2. The script will launch a Gradio web interface (typically at http://127.0.0.1:7860)
3. 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
## Troubleshooting
### API Key Issues
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-key` argument
- Set the appropriate environment variable for your chosen provider (LLAMA_API_KEY)
## Advanced Usage
You can modify the script to use different models or customize the Gradio interface as needed.
## Implementation Notes
- The script uses type hints for better code readability and IDE support:
```python
api_key: Optional[str] = args.api_key
This line uses the Optional
type from the typing
module to indicate that api_key
can be either a string or None
. The Optional
type is imported from the typing
module at the beginning of the script.
[Include license information here]