Skip to content

Commit

Permalink
docs add usage example for js
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-jaff committed Nov 23, 2024
1 parent 77fe5af commit 7674217
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
65 changes: 65 additions & 0 deletions docs/my-website/docs/pass_through/vertex_ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

- Gemini API
Expand Down
20 changes: 18 additions & 2 deletions tests/pass_through_tests/test_local_vertex.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const generativeModel = vertexAI.getGenerativeModel(
requestOptions
);

async function testModel() {
async function streamingResponse() {
try {
const request = {
contents: [{role: 'user', parts: [{text: 'How are you doing today tell me your name?'}]}],
Expand All @@ -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();

0 comments on commit 7674217

Please sign in to comment.