Pexels
Guide to use pexels tool on your AI agent using Vity Toolkit
Search curated stock photos and videos from Pexels to enhance creative or marketing workflows.
Details
Supported Auth Type
AuthType.API_KEYQuick Start
1
Install the package.
npm install vity-toolkit langchain @langchain/openai2
Initialize Vity Toolkit and Langchain.
import { ChatOpenAI } from "@langchain/openai";
import { App, LangchainToolkit } from "vity-toolkit";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
const P = (globalThis as any).process;
const model = new ChatOpenAI({ model: "gpt-4o" });
const toolKit = new LangchainToolkit({
userPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
appPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
});Make sure that you already have integrated and connected the app.
3
Add the tool.
const tools = toolKit.getTools({ apps: [App.PEXELS] });4
Define the Agent.
const tools = toolKit.getTools({ apps: [App.PEXELS] });
const prompt = ChatPromptTemplate.fromMessages([
["system", `You are an AI agent responsible for fetching stock media from Pexels on users' behalf. Use the Pexels tools to search photos/videos and fetch by ID.`],
["placeholder", "{chat_history}"],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);
const agent = createToolCallingAgent({ llm: model, tools, prompt });
const agentExecutor = new AgentExecutor({
agent,
tools,
verbose: false,
});5
Execute the Agent.
const response = await agentExecutor.invoke({ input: "I'm designing a summer beach landing page. Can you find 6 beautiful beach photos (mix of landscape and portrait) and 2 short videos with warm sunset vibes? Please include direct preview links and a suggested filename for each." });
console.log(response);Supported Actions
Action
Description
Action.PEXELS_SEARCH_PHOTOSSearch for stock photos by query from Pexels.
Action.PEXELS_SEARCH_VIDEOSSearch for stock videos by query from Pexels.
Action.PEXELS_GET_PHOTOGet a photo by its Pexels ID.
Action.PEXELS_GET_VIDEOGet a video by its Pexels ID.
Action.PEXELS_GET_CURATED_PHOTOSGet curated featured photos from Pexels.
Action.PEXELS_GET_POPULAR_VIDEOSGet popular videos from Pexels.
Last updated