Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vertexai instrumentation support #87

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/typescript/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { WeaviateFunctionNames, WeaviateFunctions } from './weaviate';
import { TiktokenModel, TiktokenEncoding } from 'js-tiktoken';
import { OllamaFunctionNames, OllamaFunctions } from './ollama';
import { VercelAIFunctionNames, VercelAIFunctions } from './ai';
import { VertexAIFunctionNames, VertexAIFunctions } from './vertexai';

function getTypedKeys<T extends object>(obj: T): Array<keyof T> {
return Object.keys(obj) as Array<keyof T>;
Expand All @@ -37,7 +38,8 @@ export const Vendors = {
WEAVIATE: 'weaviate',
PG: 'pg',
VERCEL: 'ai',
OLLAMA: 'ollama'
OLLAMA: 'ollama',
VERTEXAI: 'vertexai',
} as const;

export enum Event {
Expand Down Expand Up @@ -65,6 +67,7 @@ interface VendorInstrumentationFunctions {
pg: PgFunctions[];
ai: VercelAIFunctions[];
ollama: OllamaFunctions[];
vertexai: VertexAIFunctions[];
}

export type VendorTracedFunctions = {
Expand All @@ -84,7 +87,8 @@ export const TracedFunctionsByVendor: VendorTracedFunctions = {
qdrant: QdrantFunctionNames,
weaviate: WeaviateFunctionNames,
ai: VercelAIFunctionNames,
ollama: OllamaFunctionNames
ollama: OllamaFunctionNames,
vertexai: VertexAIFunctionNames,
} as const;

export const TIKTOKEN_MODEL_MAPPING: Record<TiktokenModel | string, TiktokenEncoding> = {
Expand Down
32 changes: 32 additions & 0 deletions src/typescript/constants/vertexai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 Scale3 Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const APIS = {
GENERATE_CONTENT: {
METHOD: "vertexAI.GenerativeModel.generateContent",
},
GENERATE_CONTENT_STREAM: {
METHOD: "vertexAI.GenerativeModel.generateContentStream",
},
SEND_MESSAGE: {
METHOD: "vertexAI.ChatSession.sendMessage",
},
SEND_MESSAGE_STREAM: {
METHOD: "vertexAI.ChatSession.sendMessageStream",
},
} as const;
export type VertexAIFunctions = typeof APIS[keyof typeof APIS]['METHOD']
export const VertexAIFunctionNames: VertexAIFunctions[] = Object.values(APIS).map((api) => api.METHOD)
4 changes: 3 additions & 1 deletion src/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { APIS as PineConeAPIS } from "./constants/pinecone";
import { APIS as QdrantAPIS } from "./constants/qdrant";
import { APIS as vercelAIAPIS } from "./constants/ai";
import { APIS as ollamaAPIS } from "./constants/ollama";
import { APIS as vertexAIAPIS } from "./constants/vertexai";
import { queryTypeToFunctionToProps } from "./constants/weaviate";
import { TIKTOKEN_MODEL_MAPPING } from "./constants/common";

Expand Down Expand Up @@ -50,7 +51,8 @@ const APIS = {
pinecone: PineConeAPIS,
qdrant: QdrantAPIS,
ai: vercelAIAPIS,
ollama: ollamaAPIS
ollama: ollamaAPIS,
vertexai: vertexAIAPIS,
}
export {
LLMSpanAttributeNames,
Expand Down
4 changes: 2 additions & 2 deletions src/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langtrase/trace-attributes",
"version": "7.2.0",
"version": "7.3.0",
"description": "LangTrace - Trace Attributes",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -19,4 +19,4 @@
"ncp": "^2.0.0",
"typescript": "^5.5.3"
}
}
}
Loading