Using Vertex AI with Flowstack

Vertex AI can be integrated with Flowstack using various methods including REST API, Python, and Node.js. Below are the implementations for each.

1. Using REST API

To make a request using the REST API, use the following Curl command. Replace YOUR_GCP_PROJECT_ID, MODEL_ID, and YOUR_GCLOUD_ACCESS_TOKEN with your Google Cloud project ID, Vertex AI model ID, and GCloud access token, respectively.

curl -X POST "https://vertex-ai.flowstack.ai/v1/projects/YOUR_GCP_PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:predict" \
-H "Authorization: Bearer YOUR_GCLOUD_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "Flowstack-Auth: Bearer YOUR_FLOWSTACK_KEY" \
-d '{
    "instances": [
        {
            "prompt": "Hello"
        }
    ],
    "parameters": {
        "temperature": 0,
        "maxOutputTokens": 5,
        "topP": 0,
        "topK": 1
    }
}'

2. Using Python

For Python integration, use the following script. Ensure to replace YOUR_GCP_PROJECT_ID, MODEL_ID, YOUR_GCLOUD_ACCESS_TOKEN, and YOUR_FLOWSTACK_KEY with your actual credentials.

import requests
import json

url = f"https://vertex-ai.flowstack.ai/v1/projects/YOUR_GCP_PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:predict"

headers = {
    "Authorization": f"Bearer YOUR_GCLOUD_ACCESS_TOKEN",
    "Content-Type": "application/json",
    "Flowstack-Auth": "Bearer YOUR_FLOWSTACK_KEY"
}

data = {
    "instances": [
        {
            "prompt": "Hello"
        }
    ],
    "parameters": {
        "temperature": 0,
        "maxOutputTokens": 5,
        "topP": 0,
        "topK": 1
    }
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)

3. Using Node.js

For Node.js, the following implementation can be used. Replace YOUR_GCP_PROJECT_ID, MODEL_ID, YOUR_GCLOUD_ACCESS_TOKEN, and YOUR_FLOWSTACK_KEY with the respective credentials.

const axios = require('axios');

const url = `https://vertex-ai.flowstack.ai/v1/projects/YOUR_GCP_PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:predict`;

const headers = {
    "Authorization": `Bearer YOUR_GCLOUD_ACCESS_TOKEN`,
    "Content-Type": "application/json",
    "Flowstack-Auth": `Bearer YOUR_FLOWSTACK_KEY`
};

const data = {
    instances: [
        {
            prompt: "Hello"
        }
    ],
    parameters: {
        temperature: 0,
        maxOutputTokens: 5,
        topP: 0,
        topK: 1
    }
};

axios.post(url, data, { headers: headers })
    .then(response => {
        console.log(response.data);
    })
    .catch(error => {
        console.error('Error:', error);
    });