This documentation describes the integration of MindsDB with Portkey, an AI Gateway that allows developers to connect to All the AI models in the world with a single API.
Portkey also brings in observability, caching, and other features that are useful for building production-grade AI applications.
Prerequisites
Before proceeding, ensure the following prerequisites are met:
- Install MindsDB locally via Docker or Docker Desktop.
- To use Portkey within MindsDB, install the required dependencies following this instruction.
- Obtain the Portkey API key required to deploy and use Portkey within MindsDB. Follow the instructions for obtaining the API key.
Setup
Create an AI engine from the Portkey handler.
You can pass all the parameters that are supported by Portkey inside the USING
clause.
CREATE ML_ENGINE portkey_engine
FROM portkey
USING
portkey_api_key = '{PORTKEY_API_KEY}', -- get this from Portkey dashboard (https://app.portkey.ai/api-keys)
config = '{PORTKEY_CONFIG_ID}'; -- get this from Portkey dashboard (https://app.portkey.ai/configs)
Create a model using portkey_engine
as an engine.
You can pass all the parameters supported by Portkey Chat completions here inside the USING
clause.
refer Portkey Chat completions for more details.
CREATE MODEL portkey_model
PREDICT answer
USING
engine = 'portkey_engine',
model = 'gpt-3.5-turbo',
temperature = 0.2;
Query the model to get predictions.
SELECT question, answer
FROM portkey_model
WHERE question = 'Where is Stockholm located?';
Here is the output:
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| question | answer |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| Where is Stockholm located? | Stockholm is the capital and largest city of Sweden. It is located on Sweden's south-central east coast, where Lake Mälaren meets the Baltic Sea. |
+-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
Usage
The following usage examples utilize portkey_engine
and gpt-3.5-turbo
to create a model with the CREATE MODEL
statement.
Creating a Summarization Model
This example demonstrates how to create a model to summarize text using Portkey:
CREATE MODEL summarization_model
PREDICT summary
USING
engine = 'portkey_engine',
model = 'gpt-3.5-turbo',
temperature = 0.5,
max_tokens = 100;
SELECT document, summary
FROM summarization_model
WHERE document = 'MindsDB is a predictive platform that connects machine learning models with databases.';
Generating Sentiment Analysis
CREATE MODEL sentiment_model
PREDICT sentiment
USING
engine = 'portkey_engine',
model = 'gpt-3.5-turbo',
temperature = 0.3;
SELECT review, sentiment
FROM sentiment_model
WHERE review = 'The product was excellent and exceeded expectations!';
Translating Text
CREATE MODEL translation_model
PREDICT translation
USING
engine = 'portkey_engine',
model = 'gpt-3.5-turbo',
temperature = 0.4;
SELECT original_text, translation
FROM translation_model
WHERE original_text = 'Hello, how are you?' AND target_language = 'es';
CREATE MODEL extraction_model
PREDICT extracted_data
USING
engine = 'portkey_engine',
model = 'gpt-3.5-turbo',
temperature = 0.6;
SELECT text, extracted_data
FROM extraction_model
WHERE text = 'Minds , 35, lives in New York and works as a software engineer.';
Next Steps
Go to the Use Cases section to see more examples.