Setup
Setup of Polyglot in your PHP project
This chapter will guide you through the initial steps of setting up and using Polyglot in your PHP project. We’ll cover installation and configuration to get you up and running quickly.
Installation
You can install it using Composer:
This will install Polyglot along with its dependencies.
NOTE: Polyglot is distributed as part of the Instructor PHP package, so if you have it installed, you don’t need to install Polyglot separately.
Requirements
- PHP 8.2 or higher
- Composer
- Valid API keys for at least one supported LLM provider
Configuration
Setting Up API Keys
Polyglot requires API keys to authenticate with LLM providers. The recommended approach is to use environment variables:
- Create a
.env
file in your project root (or use your existing one) - Add your API keys:
- Make sure your application loads these environment variables (using a package like
vlucas/phpdotenv
or your framework’s built-in environment handling)
Configuration Files
Polyglot loads its configuration from PHP files. The default configuration files are located in the Instructor package, but you can publish and customize them:
- Create a
config
directory in your project if it doesn’t exist - Copy the configuration files from the Instructor package:
- Customize the configuration files as needed
LLM Configuration
The llm.php
configuration file contains settings for LLM providers:
Embeddings Configuration
The embed.php
configuration file contains settings for embeddings providers:
Custom Configuration Location
By default, Polyglot looks for configuration files in the config
directory relative to your project root. You can specify a different location by setting the INSTRUCTOR_CONFIG_PATH
environment variable:
Overriding Configuration Location
You can use Settings
class static setPath()
method to override the value of config path set in environment variable with your own value.
Troubleshooting
Common Installation Issues
- Composer Dependencies: Make sure you have PHP 8.2+ installed and Composer correctly configured.
- API Keys: Verify that your API keys are correctly set in your environment variables.
- Configuration Files: Check that your configuration files are properly formatted and accessible.
Testing Your Installation
A simple way to test if everything is working correctly is to run a small script:
If you see a friendly greeting, your installation is working correctly!