1. Prompty Invoker¶
In this section, we cover the different built-in Prompty Invokers and walk you through how you can build your own custom invoker.
1. Prompty Invokers¶
The Prompty runtime comes with a set of built-in invokers that can be used to execute external models and APIs. Invokers trigger a call to the different models and return their output, ensuring standardization when it comes to handling models. The invokers currently supported are:
- azure: Invokes the Azure OpenAI API
- openai: Invokes the OpenAI API
- serverless: Invokes serverless models (e.g., GitHub Models) using the Azure AI Inference client library (currently only key-based authentication is supported with more managed identity support coming soon)
2. How Invokers Work¶
Invokers in Prompty are responsible for executing prompts against specified models or APIs. They ensure that the necessary configurations and inputs are correctly handled, making it possible to integrate prompt execution seamlessly into applications. Each invoker follows a standard interface, which includes methods for synchronous and asynchronous invocation.
Invoker Interface¶
An invoker must implement the following methods:
invoke(data: any): Promise<any>
: Asynchronous method to invoke the invoker.invokeSync(data: any): any
: Synchronous method to invoke the invoker.
Built-in Invokers¶
Prompty provides several built-in invokers:
- AzureInvoker: Executes prompts using the Azure OpenAI API.
- OpenAIInvoker: Executes prompts using the OpenAI API.
- ServerlessInvoker: Executes prompts using serverless models.
3. How Invokers Are Used¶
Azure Invoker Example¶
YAML | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|
OpenAI Invoker Example¶
YAML | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
Serverless Invoker Example¶
YAML | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|
4. Creating a Custom Invoker¶
Creating a custom invoker involves extending the Invoker
class and implementing the required methods. Below is a step-by-step guide to creating a custom invoker.
Step 1: Define the Invoker Class¶
Create a new class that extends the Invoker
class and implement the invoke
and invokeSync
methods.
TypeScript | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Step 2: Register the Invoker¶
Register the custom invoker with the InvokerFactory
.
TypeScript | |
---|---|
1 2 3 4 |
|
Step 3: Use the Custom Invoker¶
Use the custom invoker in your application.
TypeScript | |
---|---|
1 2 3 4 5 6 7 8 |
|
Example .Prompty
File¶
YAML | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
5. Hugging Face Invoker Tutorial¶
In this section, we will create a custom invoker for Hugging Face models.
Step 1: Install Dependencies¶
Install the necessary dependencies.
Bash | |
---|---|
1 |
|
Step 2: Define the Invoker Class¶
Create a new class that extends the Invoker
class and implements the required methods.
TypeScript | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Step 3: Register the Invoker¶
Register the Hugging Face invoker with the InvokerFactory
.
TypeScript | |
---|---|
1 2 3 4 |
|
Step 4: Use the Invoker¶
Use the Hugging Face invoker in your application.
TypeScript | |
---|---|
1 2 3 4 5 6 7 8 |
|
Example : basic_hf.prompty
¶
Text Only | |
---|---|
1 2 3 4 5 6 7 8 9 |
|