Ecosystem
LLMs
- Overview
- OpenAI
- Anthropic
- Google Gemini
- Google Vertex AI
- Azure OpenAI
- Bedrock
- AWS SageMaker
- Ollama
- More
- Bring Your Own LLM
Agents
Files
Upload files to Google Cloud Storage for Vertex AI fine-tuning and batch inference
To perform fine-tuning or batch inference with Vertex AI, you need to upload files to Google Cloud Storage. With Portkey, you can easily upload files to GCS and use them for fine-tuning or batch inference with Vertex AI models.
Uploading Files
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VERTEX_VIRTUAL_KEY", # Add your Vertex virtual key
vertex_storage_bucket_name="your_bucket_name", # Specify the GCS bucket name
provider_file_name="your_file_name.jsonl", # Specify the file name in GCS
provider_model="gemini-1.5-flash-001" # Specify the model to use
)
upload_file_response = portkey.files.create(
purpose="fine-tune", # Can be "fine-tune" or "batch"
file=open("dataset.jsonl", "rb")
)
print(upload_file_response)
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VERTEX_VIRTUAL_KEY", # Add your Vertex virtual key
vertex_storage_bucket_name="your_bucket_name", # Specify the GCS bucket name
provider_file_name="your_file_name.jsonl", # Specify the file name in GCS
provider_model="gemini-1.5-flash-001" # Specify the model to use
)
upload_file_response = portkey.files.create(
purpose="fine-tune", # Can be "fine-tune" or "batch"
file=open("dataset.jsonl", "rb")
)
print(upload_file_response)
import { Portkey } from 'portkey-ai';
import * as fs from 'fs';
// Initialize the Portkey client
const portkey = Portkey({
apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key
virtualKey: "VERTEX_VIRTUAL_KEY", // Add your Vertex virtual key
vertexStorageBucketName: "your_bucket_name", // Specify the GCS bucket name
providerFileName: "your_file_name.jsonl", // Specify the file name in GCS
providerModel: "gemini-1.5-flash-001" // Specify the model to use
});
const uploadFile = async () => {
const file = await portkey.files.create({
purpose: "fine-tune", // Can be "fine-tune" or "batch"
file: fs.createReadStream("dataset.jsonl")
});
console.log(file);
}
uploadFile();
curl -X POST --header 'x-portkey-api-key: <portkey_api_key>' \
--header 'x-portkey-virtual-key: <vertex_virtual_key>' \
--header 'x-portkey-vertex-storage-bucket-name: <bucket_name>' \
--header 'x-portkey-provider-file-name: <file_name>.jsonl' \
--header 'x-portkey-provider-model: <model_name>' \
--form 'purpose="fine-tune"' \
--form '[email protected]' \
'https://api.portkey.ai/v1/files'
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
import * as fs from 'fs';
const openai = new OpenAI({
apiKey: 'OPENAI_API_KEY',
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
virtualKey: "VERTEX_VIRTUAL_KEY",
apiKey: "PORTKEY_API_KEY",
vertexStorageBucketName: "your_bucket_name",
providerFileName: "your_file_name.jsonl",
providerModel: "gemini-1.5-flash-001"
})
});
const uploadFile = async () => {
const file = await openai.files.create({
purpose: "fine-tune", // Can be "fine-tune" or "batch"
file: fs.createReadStream("dataset.jsonl")
});
console.log(file);
}
uploadFile();
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
openai = OpenAI(
api_key='OPENAI_API_KEY',
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
virtual_key="VERTEX_VIRTUAL_KEY",
api_key="PORTKEY_API_KEY",
vertex_storage_bucket_name="your_bucket_name",
provider_file_name="your_file_name.jsonl",
provider_model="gemini-1.5-flash-001"
)
)
upload_file_response = openai.files.create(
purpose="fine-tune", # Can be "fine-tune" or "batch"
file=open("dataset.jsonl", "rb")
)
print(upload_file_response)
Get File
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VERTEX_VIRTUAL_KEY" # Add your Vertex virtual key
)
file = portkey.files.retrieve(file_id="file_id")
print(file)
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VERTEX_VIRTUAL_KEY" # Add your Vertex virtual key
)
file = portkey.files.retrieve(file_id="file_id")
print(file)
import { Portkey } from 'portkey-ai';
// Initialize the Portkey client
const portkey = Portkey({
apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key
virtualKey: "VERTEX_VIRTUAL_KEY" // Add your Vertex virtual key
});
const getFile = async () => {
const file = await portkey.files.retrieve("file_id");
console.log(file);
}
getFile();
curl -X GET --header 'x-portkey-api-key: <portkey_api_key>' \
--header 'x-portkey-virtual-key: <vertex_virtual_key>' \
'https://api.portkey.ai/v1/files/<file_id>'
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
const openai = new OpenAI({
apiKey: 'OPENAI_API_KEY',
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
virtualKey: "VERTEX_VIRTUAL_KEY",
apiKey: "PORTKEY_API_KEY"
})
});
const getFile = async () => {
const file = await openai.files.retrieve("file_id");
console.log(file);
}
getFile();
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
openai = OpenAI(
api_key='OPENAI_API_KEY',
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
virtual_key="VERTEX_VIRTUAL_KEY",
api_key="PORTKEY_API_KEY"
)
)
file = openai.files.retrieve(file_id="file_id")
print(file)
Get File Content
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VERTEX_VIRTUAL_KEY" # Add your Vertex virtual key
)
file_content = portkey.files.content(file_id="file_id")
print(file_content)
from portkey_ai import Portkey
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VERTEX_VIRTUAL_KEY" # Add your Vertex virtual key
)
file_content = portkey.files.content(file_id="file_id")
print(file_content)
import { Portkey } from 'portkey-ai';
// Initialize the Portkey client
const portkey = Portkey({
apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key
virtualKey: "VERTEX_VIRTUAL_KEY" // Add your Vertex virtual key
});
const getFileContent = async () => {
const fileContent = await portkey.files.content("file_id");
console.log(fileContent);
}
getFileContent();
curl -X GET --header 'x-portkey-api-key: <portkey_api_key>' \
--header 'x-portkey-virtual-key: <vertex_virtual_key>' \
'https://api.portkey.ai/v1/files/<file_id>/content'
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
const openai = new OpenAI({
apiKey: 'OPENAI_API_KEY',
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
virtualKey: "VERTEX_VIRTUAL_KEY",
apiKey: "PORTKEY_API_KEY"
})
});
const getFileContent = async () => {
const fileContent = await openai.files.content("file_id");
console.log(fileContent);
}
getFileContent();
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
openai = OpenAI(
api_key='OPENAI_API_KEY',
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
virtual_key="VERTEX_VIRTUAL_KEY",
api_key="PORTKEY_API_KEY"
)
)
file_content = openai.files.content(file_id="file_id")
print(file_content)
Note: The ListFiles
endpoint is not supported for Vertex AI.
Was this page helpful?
On this page