Google's Gemini Models ✨
You can use merlin's API to access the new Google Gemini models. You can use the API directly or use the TypeScript package.
Available Models
Below is the list of the available text-based model IDs you can use with the Merlin API along with a brief description:
Model ID | Description | Provider |
---|---|---|
gemini-pro | Google's Gemini Pro Model | |
gemini-pro-vision | Google's Gemini Pro multi modal variant. |
Package Installation
Visit api.getmerlin.in to sign up for an account and obtain your API key. To begin using the Merlin API with your node.js project, you'll need to first install the merlin-node
package. Below are the commands for npm, pnpm, and yarn.
npm
npm install merlin-node --save
Using the TypeScript package
Once you have installed the merlin-node
package, you can import it into your TypeScript project as follows:
Example Usage with Gemini Pro
import { Merlin } from "merlin-node";
const apiKey = "<YOUR_MERLIN_API_KEY>"; // Replace with your API key from Merlin
const merlin = new Merlin({ merlinConfig: { apiKey } });
async function createCompletion() {
try {
const completion = await merlin.chat.completions.create({
messages: [{ role: "system", content: "You are a helpful assistant." }],
model: "gemini-pro",
});
console.log(completion.choices[0].message.content);
} catch (error) {
console.error("Error creating completion:", error);
}
}
createCompletion();
Example Usage with Gemini Pro Vision
Currently We Only Support 1 image per use message in gemini-pro-vision
model.
We will update the page once we add support for multiple input images per user message.
import { Merlin } from "merlin-node";
const apiKey = "<YOUR_MERLIN_API_KEY>"; // Replace with your API key from Merlin
const merlin = new Merlin({ merlinConfig: { apiKey } });
async function createCompletion() {
try {
const completion = await merlin.chat.completions.create({
messages: [
{ role: "system", content: "You are a helpful assistant." },
{
role: "user",
content: [
{
type: "image_url",
image_url:
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
{
type: "text",
text: "What’s in this image?",
},
],
},
],
model: "gemini-pro-vision",
});
console.log(completion.choices[0].message.content);
} catch (error) {
console.error("Error creating completion:", error);
}
}
createCompletion();
Make sure to replace <YOUR_MERLIN_API_KEY>
with your own API key obtained during the signup process on api.getmerlin.in.
Do node that right now, we only support createCompletion
and imageGeneration
, so if you want to do other things like finetuning on OpenAI or using the Assistants API, then add your OpenAI key with apiKey
parameter when initializing Merlin as follows
const merlin = new Merlin({ apiKey:"<YOUR_OPENAI_KEY>", merlinConfig: {apiKey: "<YOUR_MERLIN_API_KEY>"} });`
In this case, we directly use OpenAI endpoints, hence your existing pipelines stay in place.
Using Endpoints Directly
If you prefer to use the API without a package, you can call the service directly using tools such as curl
, axios
or the fetch
API in JavaScript. The API is accessible via the following URL: https://endpoints.getmerlin.in
.
cURL Request Example
Run this cURL command in your terminal to interact with the API directly:
curl --location --request POST 'https://endpoints.getmerlin.in/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-merlin-key: <YOUR_MERLIN_API_KEY>' \
--data-raw '{
"model": "gemini-pro",
"messages": [
{
"role": "user",
"content": "Who won the world series in 2020?"
},
{
"role": "assistant",
"content": "The Los Angeles Dodgers won the World Series in 2020."
},
{
"role": "user",
"content": "Where was it played?"
}
],
"temperature": 1,
"top_p": 1,
"n": 1,
"stream": false,
"max_tokens": 250,
"presence_penalty": 0,
"frequency_penalty": 0
}'
Axios Example
Alternatively, you can use the axios
library in a Node.js environment or in the browser to make an API request. Here's an example:
const axios = require("axios");
const apiKey = "<YOUR_MERLIN_API_KEY>"; // Replace with your API key from Merlin
import axios from "axios";
const headers = {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"x-merlin-key": apiKey,
},
};
const data = {
model: "gemini-pro",
messages: [
{
role: "user",
content: "Who won the world series in 2020?",
},
{
role: "assistant",
content: "The Los Angeles Dodgers won the World Series in 2020.",
},
{
role: "user",
content: "Where was it played?",
},
],
temperature: 1,
top_p: 1,
n: 1,
stream: false,
max_tokens: 250,
presence_penalty: 0,
frequency_penalty: 0,
};
axios
.post("https://endpoints.getmerlin.in/chat/completions", data, headers)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error("There was an error!", error);
});
We are yet to add support for function-calling in the Gemini Models. We will update this page once we have added support for it.
Once you have set up your preferred method of interaction, you should be able to send requests to Merlin API and receive AI-powered responses. Remember to consult the API documentation for specific parameters and models available.
If there are any further questions or need for clarifications during your installation and setup process, feel free to reach out to Merlin's support for assistance.