Configuration
You will need to configure the LLM connection and authorization secrets.
Model selection
The model used by the script is configured through the model
field in the script
function.
The model name is formatted as provider:model-name
, where provider
is the LLM provider
and the model-name
is provider specific.
Large and small models
You can also use the small
and large
aliases to use the default configured small and large models.
Large models are typically in the OpenAI gpt-4 reasoning range and can be used for more complex tasks.
Small models are in the OpenAI gpt-4o-mini range, and are useful for quick and simple tasks.
The model can also be overridden from the cli run command
or by adding the GENAISCRIPT_DEFAULT_MODEL
and GENAISCRIPT_DEFAULT_SMALL_MODEL
environment variables.
.env
file
GenAIScript uses a .env
file to load secrets and configuration information into the process environment variables.
Create or update a
.gitignore
file in the root of your project and make it sure it includes.env
. This ensures that you do not accidentally commit your secrets to your source control.Create a
.env
file in the root of your project.- .gitignore
- .env
Update the
.env
file with the configuration information (see below).
Custom .env file location
You can specify a custom .env
file location through the CLI or an environment variable.
- by adding the
--env <file>
argument to the CLI.
- by setting the
GENAISCRIPT_ENV_FILE
environment variable.
- by specifying the
.env
file location in a configuration file.
No .env file
If you do not want to use a .env
file, make sure to populate the environment variables
of the genaiscript process with the configuration values.
Here are some common examples:
- Using bash syntax
- GitHub Action configuration
OpenAI
This provider, openai
, is the OpenAI chat model provider.
It uses the OPENAI_API_...
environment variables.
Create a new secret key from the OpenAI API Keys portal.
Update the
.env
file with the secret key.Find the model you want to use from the OpenAI API Reference or the OpenAI Chat Playground.
Set the
model
field inscript
to the model you want to use.
GitHub Models
The GitHub Models provider, github
, allows running models through the GitHub Marketplace.
This provider is useful for prototyping and subject to rate limits
depending on your subscription.
If you are running from a GitHub Codespace, the token is already configured for you.
Create a GitHub personal access token. The token should not have any scopes or permissions.
Update the
.env
file with the token.
To configure a specific model,
Open the GitHub Marketplace and find the model you want to use.
Copy the model name from the Javascript/Python samples
to configure your script.
If you are already using GITHUB_TOKEN
variable in your script and need a different one
for GitHub Models, you can use the GITHUB_MODELS_TOKEN
variable instead.
o1-preview
and o1-mini
models
Currently these models do not support streaming and system prompts. GenAIScript handles this internally.
Azure OpenAI
The Azure OpenAI provider, azure
uses the AZURE_OPENAI_...
environment variables.
You can use a managed identity (recommended) or an API key to authenticate with the Azure OpenAI service.
You can also use a service principal as documented in automation.
Managed Identity (Entra ID)
Open your Azure OpenAI resource in the Azure Portal
Navigate to Access Control (IAM), then View My Access. Make sure your user or service principal has the Cognitive Services OpenAI User/Contributor role. If you get a
401
error, click on Add, Add role assignment and add the Cognitive Services OpenAI User role to your user.Navigate to Resource Management, then Keys and Endpoint.
Update the
.env
file with the endpoint.Navigate to deployments and make sure that you have your LLM deployed and copy the
deployment-id
, you will need it in the script.Open a terminal and login with Azure CLI.
Update the
model
field in thescript
function to match the model deployment name in your Azure resource.
Custom credentials
In some situations, the default credentials chain lookup may not work.
In that case, you can specify an additional environment variable AZURE_OPENAI_API_CREDENTIALS
with the type of credential that should be used.
The types are mapped directly to their @azure/identity credential types:
cli
-AzureCliCredential
env
-EnvironmentCredential
powershell
-AzurePowerShellCredential
devcli
-AzureDeveloperCliCredential
managedidentity
-ManagedIdentityCredential
Custom token scopes
The default token scope for Azure OpenAI access is https://cognitiveservices.azure.com/.default
.
You can override this value using the AZURE_OPENAI_TOKEN_SCOPES
environment variable.
API Key
Open your Azure OpenAI resource and navigate to Resource Management, then Keys and Endpoint.
Update the
.env
file with the secret key (Key 1 or Key 2) and the endpoint.The rest of the steps are the same: Find the deployment name and use it in your script,
model: "azure:deployment-id"
.
Azure AI Serverless Deployments
You can deploy “serverless” models through Azure AI Studio and pay as you go per token. You can browse the Azure AI model catalog and use the serverless API filter to see the available models.
There are two types of serverless deployments that require different configurations: OpenAI models and all other models.
The OpenAI models, like gpt-4o
, are deployed to .openai.azure.com
endpoints,
while the Azure AI models, like Meta-Llama-3.1-405B-Instruct
are deployed to .models.ai.azure.com
endpoints.
They are configured slightly differently.
Azure AI OpenAI
The azure_serverless
provider supports OpenAI models deployed through the Azure AI Studio serverless deployments.
It supports both Entra ID and key-based authentication.
Managed Identity (Entra ID)
Open a terminal and login with Azure CLI.
Open https://ai.azure.com/ and open the Deployments page.
Deploy a base model from the catalog. You can use the
Deployment Options
->Serverless API
option to deploy a model as a serverless API.Deploy an OpenAI base model. This will also create a new Azure OpenAI resource in your subscription.
Update the
.env
file with the deployment endpoint in theAZURE_SERVERLESS_OPENAI_API_ENDPOINT
variable.Open your Azure OpenAI resource that was created by Azure AI in the Azure Portal
Navigate to Access Control (IAM), then View My Access. Make sure your user or service principal has the Cognitive Services OpenAI User/Contributor role. If you get a
401
error, click on Add, Add role assignment and add the Cognitive Services OpenAI User role to your user.
API Key
Open your Azure OpenAI resource and navigate to Resource Management, then Keys and Endpoint.
Update the
.env
file with the endpoint and the secret key (Key 1 or Key 2) and the endpoint.
Azure AI Models
The azure_serverless_models
provider supports non-OpenAI models deployed through the Azure AI Studio serverless deployments.
Managed Identity (Entra ID)
Open your Azure AI Project resource in the Azure Portal
Navigate to Access Control (IAM), then View My Access. Make sure your user or service principal has the Azure AI Developer role. If you get a
401
error, click on Add, Add role assignment and add the Azure AI Developer role to your user.Configure the Endpoint Target URL as the
AZURE_SERVERLESS_MODELS_API_ENDPOINT
.Navigate to deployments and make sure that you have your LLM deployed and copy the Deployment Info name, you will need it in the script.
Update the
model
field in thescript
function to match the model deployment name in your Azure resource.
API Key
Open https://ai.azure.com/ and open the Deployments page.
Deploy a base model from the catalog. You can use the
Deployment Options
->Serverless API
option to deploy a model as a serverless API.Configure the Endpoint Target URL as the
AZURE_SERVERLESS_MODELS_API_ENDPOINT
variable and the key inAZURE_SERVERLESS_MODELS_API_KEY
in the.env
file**.**Find the deployment name and use it in your script,
model: "azure_serverless:deployment-id"
.
Support for multiple inference deployements
You can update the AZURE_SERVERLESS_MODELS_API_KEY
with a list of deploymentid=key
pairs to support multiple deployments (each deployment has a different key).
Google AI
The google
provider allows you to use Google AI models. It gives you access
Open Google AI Studio and create a new API key.
Update the
.env
file with the API key.Find the model identifier in the Gemini documentation and use it in your script or cli with the
google
provider.then use the model identifier in your script.
GitHub Copilot Chat Models
If you have access to GitHub Copilot Chat in Visual Studio Code, GenAIScript will be able to leverage those language models as well.
This mode is useful to run your scripts without having a separate LLM provider or local LLMs. However, those models are not available from the command line and have additional limitations and rate limiting defined by the GitHub Copilot platform.
There is no configuration needed as long as you have GitHub Copilot installed and configured in Visual Studio Code.
You can force using this model by using client:*
as a model name.
Install GitHub Copilot Chat (emphasis on Chat)
- run your script
Confirm that you are allowing GenAIScript to use the GitHub Copilot Chat models.
select the best chat model that matches the one you have in your script
(This step is skipped if you already have mappings in your settings)
The mapping of GenAIScript model names to Visual Studio Models is stored in the settings.
Anthropic
Anthropic is an AI research company that offers powerful language models, including the Claude series.
To use Anthropic models with GenAIScript, follow these steps:
Sign up for an Anthropic account and obtain an API key from their console.
Add your Anthropic API key to the
.env
file:Find the model that best suits your needs by visiting the Anthropic model documentation.
Update your script to use the
model
you choose.
Hugging Face
The huggingface
provider allows you to use Hugging Face Models using Text Generation Inference.
To use Hugging Face models with GenAIScript, follow these steps:
Sign up for a Hugging Face account and obtain an API key from their console. If you are creating a Fined Grained token, enable the Make calls to the serverless inference API option.
Add your Hugging Face API key to the
.env
file:Find the model that best suits your needs by visiting the HuggingFace models.
Update your script to use the
model
you choose.
LocalAI
LocalAI act as a drop-in replacement REST API that’s compatible with OpenAI API specifications for local inferencing. It uses free Open Source models and it runs on CPUs.
LocalAI acts as an OpenAI replacement, you can see the model name mapping
used in the container, like gpt-4
is mapped to phi-2
.
Install Docker. See the LocalAI documentation for more information.
Update the
.env
file and set the api type tolocalai
.
Ollama
Ollama is a desktop application that lets you download and run models locally.
Running tools locally may require additional GPU resources depending on the model you are using.
Use the ollama
provider to access Ollama models.
Start the Ollama application or
Update your script to use the
ollama:phi3.5
model (or any other model or from Hugging Face).GenAIScript will automatically pull the model, which may take some time depending on the model size. The model is cached locally by Ollama.
If Ollama runs on a server or a different computer or on a different port, you have to configure the
OLLAMA_HOST
environment variable to connect to a remote Ollama server.
You can specify the model size by adding the size to the model name, like ollama:llama3.2:3b
.
You can also use GGUF models from Hugging Face.
Llamafile
https://llamafile.ai/ is a single file desktop application that allows you to run an LLM locally.
The provider is llamafile
and the model name is ignored.
Jan, LMStudio, LLaMA.cpp
Jan, LMStudio, LLaMA.cpp also allow running models locally or interfacing with other LLM vendors.
Update the
.env
file with the local server information.
OpenRouter
You can configure the OpenAI provider to use the OpenRouter service instead
by setting the OPENAI_API_BASE
to https://openrouter.ai/api/v1
.
You will also need an api key.
Then use the OpenRouter model name in your script:
By default, GenAIScript will set the site URL and name to GenAIScript
but you can override these settings with your own values:
Model specific environment variables
You can provide different environment variables
for each named model by using the PROVIDER_MODEL_API_...
prefix or PROVIDER_API_...
prefix.
The model name is capitalized and
all non-alphanumeric characters are converted to _
.
This allows to have various sources of LLM computations
for different models. For example, to enable the ollama:phi3
model running locally, while keeping the default openai
model connection information.
Running behind a proxy
You can set the HTTP_PROXY
and/or HTTPS_PROXY
environment variables to run GenAIScript behind a proxy.
Checking your configuration
You can check your configuration by running the genaiscript info env
command.
It will display the current configuration information parsed by GenAIScript.
Next steps
Write your first script.