forked from phoenix/litellm-mirror
docs add usage example for js
This commit is contained in:
parent
77fe5af5b3
commit
7674217e6c
2 changed files with 83 additions and 2 deletions
|
@ -12,6 +12,71 @@ Looking for the Unified API (OpenAI format) for VertexAI ? [Go here - using vert
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
Pass-through endpoints for Vertex AI - call provider-specific endpoint, in native format (no translation).
|
||||||
|
|
||||||
|
Just replace `https://REGION-aiplatform.googleapis.com` with `LITELLM_PROXY_BASE_URL/vertex-ai`
|
||||||
|
|
||||||
|
|
||||||
|
#### **Example Usage**
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value="curl" label="curl">
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl http://localhost:4000/vertex-ai/publishers/google/models/gemini-1.0-pro:generateContent \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer sk-1234" \
|
||||||
|
-d '{
|
||||||
|
"contents":[{
|
||||||
|
"role": "user",
|
||||||
|
"parts":[{"text": "How are you doing today?"}]
|
||||||
|
}]
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value="js" label="Vertex Node.js SDK">
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { VertexAI } = require('@google-cloud/vertexai');
|
||||||
|
|
||||||
|
const vertexAI = new VertexAI({
|
||||||
|
project: 'your-project-id', // enter your vertex project id
|
||||||
|
location: 'us-central1', // enter your vertex region
|
||||||
|
apiEndpoint: "localhost:4000/vertex-ai" // <proxy-server-url>/vertex-ai # note, do not include 'https://' in the url
|
||||||
|
});
|
||||||
|
|
||||||
|
const model = vertexAI.getGenerativeModel({
|
||||||
|
model: 'gemini-1.0-pro'
|
||||||
|
}, {
|
||||||
|
customHeaders: {
|
||||||
|
"X-Litellm-Api-Key": "sk-1234" // Your litellm Virtual Key
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function generateContent() {
|
||||||
|
try {
|
||||||
|
const prompt = {
|
||||||
|
contents: [{
|
||||||
|
role: 'user',
|
||||||
|
parts: [{ text: 'How are you doing today?' }]
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await model.generateContent(prompt);
|
||||||
|
console.log('Response:', response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateContent();
|
||||||
|
```
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
|
||||||
## Supported API Endpoints
|
## Supported API Endpoints
|
||||||
|
|
||||||
- Gemini API
|
- Gemini API
|
||||||
|
|
|
@ -33,7 +33,7 @@ const generativeModel = vertexAI.getGenerativeModel(
|
||||||
requestOptions
|
requestOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
async function testModel() {
|
async function streamingResponse() {
|
||||||
try {
|
try {
|
||||||
const request = {
|
const request = {
|
||||||
contents: [{role: 'user', parts: [{text: 'How are you doing today tell me your name?'}]}],
|
contents: [{role: 'user', parts: [{text: 'How are you doing today tell me your name?'}]}],
|
||||||
|
@ -49,4 +49,20 @@ async function testModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testModel();
|
|
||||||
|
async function nonStreamingResponse() {
|
||||||
|
try {
|
||||||
|
const request = {
|
||||||
|
contents: [{role: 'user', parts: [{text: 'How are you doing today tell me your name?'}]}],
|
||||||
|
};
|
||||||
|
const response = await generativeModel.generateContent(request);
|
||||||
|
console.log('non streaming response: ', JSON.stringify(response));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
streamingResponse();
|
||||||
|
nonStreamingResponse();
|
Loading…
Add table
Add a link
Reference in a new issue