Skip to content

Commit

Permalink
Merge pull request #99 from Portkey-AI/vertex/types
Browse files Browse the repository at this point in the history
Vertex Changes
  • Loading branch information
VisargD authored Sep 5, 2024
2 parents 952ffd1 + ea37289 commit fdea390
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/_types/generalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ApiClientInterface {
forwardHeaders?: Array<string> | null | undefined;
cacheNamespace?: string | null | undefined;
requestTimeout?: number | null | undefined;
strictOpenAiCompliance?: boolean | null | undefined;
}

export interface APIResponseType {
Expand Down
7 changes: 7 additions & 0 deletions src/apis/chatCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,43 @@ interface Usage {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
[key: string]: any;
}

interface FunctionType {
arguments?: string;
name?: string;
[key: string]: any;
}

interface ToolCall {
index?: number;
id?: string;
function?: FunctionType;
type?: 'function';
[key: string]: any;
}

interface FunctionCall {
arguments?: string;
name?: string;
[key: string]: any;
}

interface Message {
role: string;
content: string | null;
function_call?: FunctionCall;
tool_calls?: Array<ToolCall>;
[key: string]: any;
}

interface Choices {
index?: number;
message?: Message;
delta?: Message;
finish_reason?: string;
[key: string]: any;
}

interface ChatCompletion extends APIResponseType {
Expand All @@ -106,4 +112,5 @@ interface ChatCompletion extends APIResponseType {
model: string;
choices: Array<Choices>;
usage: Usage;
[key: string]: any;
}
4 changes: 2 additions & 2 deletions src/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export abstract class ApiClient {
portkeyHeaders: Record<string, string>

private fetch: Fetch;
constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, huggingfaceBaseUrl, forwardHeaders, cacheNamespace, requestTimeout }: ApiClientInterface) {
constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, huggingfaceBaseUrl, forwardHeaders, cacheNamespace, requestTimeout, strictOpenAiCompliance }: ApiClientInterface) {
this.apiKey = apiKey ?? "";
this.baseURL = baseURL ?? "";
this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, cacheNamespace, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, huggingfaceBaseUrl, forwardHeaders, requestTimeout })
this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, cacheNamespace, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, huggingfaceBaseUrl, forwardHeaders, requestTimeout, strictOpenAiCompliance })
this.portkeyHeaders = this.defaultHeaders()
this.fetch = fetch;
this.responseHeaders = {}
Expand Down
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Portkey extends ApiClient {
forwardHeaders?: Array<string> | null | undefined;
requestTimeout?: number | null | undefined;
cacheNamespace?: string | null | undefined;
strictOpenAiCompliance?: boolean | null | undefined;
constructor({
apiKey = readEnv("PORTKEY_API_KEY") ?? null,
baseURL = readEnv("PORTKEY_BASE_URL") ?? null,
Expand Down Expand Up @@ -62,6 +63,7 @@ export class Portkey extends ApiClient {
forwardHeaders,
cacheNamespace,
requestTimeout,
strictOpenAiCompliance,
}: ApiClientInterface) {

super({
Expand Down Expand Up @@ -92,6 +94,7 @@ export class Portkey extends ApiClient {
huggingfaceBaseUrl,
forwardHeaders,
requestTimeout,
strictOpenAiCompliance,
});

this.apiKey = apiKey;
Expand Down Expand Up @@ -123,6 +126,7 @@ export class Portkey extends ApiClient {
this.huggingfaceBaseUrl = huggingfaceBaseUrl;
this.forwardHeaders = forwardHeaders;
this.requestTimeout = requestTimeout;
this.strictOpenAiCompliance = strictOpenAiCompliance;
}

completions: API.Completions = new API.Completions(this);
Expand Down

0 comments on commit fdea390

Please sign in to comment.