Using Google Gemini Chat Completion
Google’s Gemini models are available through the same OpenAI-compatible request shape as the other chat completion endpoints, so switching between providers only requires changing the URL and model name.
Personalities and built-in functions are features of the OpenAI endpoint and are not available here.
Request
URL: https://ai.purlabs.xyz/google/chat/completions
Request Method: POST
TS Interface
interface Request {
model: string;
messages: {
role: 'system' | 'user' | 'assistant';
content: string;
}[];
temperature?: number;
top_p?: number;
top_k?: number;
max_tokens?: number;
stop?: string | string[] | null;
};Request API Reference
| Parameter | Type (check TS Interface) | Required | Description |
|---|---|---|---|
model | string | Required | The model to use, such as gemini-pro. Refer to the Listing Available Models page for more information. |
messages | object[] | Required | The list of messages in the conversation so far. |
messages.role | string | Required | The author of the message: system, user, or assistant. |
messages.content | string | Required | The text content of the message. |
temperature | number | Optional | The sampling temperature, between 0 and 1. Higher values make the output more random; lower values make it more focused and deterministic. |
top_p | number | Optional | Nucleus sampling: the model considers tokens comprising the top top_p probability mass. |
top_k | number | Optional | The model considers only the top_k most likely tokens at each step. |
max_tokens | number | Optional | The maximum number of tokens to generate in the response. |
stop | string | string[] | null | Optional | Up to four sequences where the model will stop generating further tokens. |
Example JSON Request Body
{
"model": "gemini-pro",
"messages": [
{
"role": "user",
"content": "Summarize the benefits of unit testing in two sentences."
}
]
}Response
TS Response Interface
interface Response {
id: string;
object: 'chat.completion';
created: number;
model: string;
choices: [
{
index: number;
message: {
role: 'assistant',
content: string;
};
finish_reason: any;
}
];
overwritten: boolean;
provider: string;
};Example JSON Response
{
"id": "f81d4fae7dec11d0a76500a0c91e6bf6",
"object": "chat.completion",
"created": 1703031002,
"model": "gemini-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Unit testing catches defects early by verifying that each piece of code behaves as expected in isolation, which makes bugs cheaper and faster to fix. It also serves as living documentation and gives developers the confidence to refactor code without breaking existing functionality."
},
"finish_reason": "stop"
}
],
"provider": "provider-1",
"overwritten": false
}Last updated on