Skip to content

Commit

Permalink
Merge pull request #51 from Portkey-AI/hotfix/debugHeader
Browse files Browse the repository at this point in the history
TS Issue: debug header
  • Loading branch information
VisargD authored Apr 20, 2024
2 parents a34f0c3 + 72dfa56 commit 64299e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/_types/generalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ApiClientInterface {
metadata?: Record<string, unknown> | null | undefined;
Authorization?: string | null | undefined;
cacheForceRefresh?: boolean | null | undefined;
debug?: boolean | null | undefined;
}

export interface APIResponseType {
Expand Down
7 changes: 6 additions & 1 deletion src/apis/createHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ export const createHeaders = (config: Record<string, any>): Record<string, strin

for (let k in config) {
let v = config[k];

if (isEmpty(v)) continue;

// convert to snakecase
if (k.toLocaleLowerCase() === "authorization") {
headers[k.toLowerCase()] = v || ""
continue
}

// false logic (type is boolean, to handle flasy logic)
if (typeof v === "boolean") {
v = v.toString()
}

k = k.replace('ID', 'Id')
.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)
if (!isEmpty(v) && typeof v == "object") {
Expand Down
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 }: ApiClientInterface) {
constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug }: ApiClientInterface) {
this.apiKey = apiKey ?? "";
this.baseURL = baseURL ?? "";
this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh })
this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug })
this.portkeyHeaders = this.defaultHeaders()
this.fetch = fetch;
this.responseHeaders = {}
Expand Down
6 changes: 5 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class Portkey extends ApiClient {
metadata: Record<string, unknown> | null | undefined;
Authorization?: string;
cacheForceRefresh?: boolean | null | undefined;
debug?: boolean | null | undefined;
constructor({
apiKey = readEnv("PORTKEY_API_KEY") ?? null,
baseURL = readEnv("PORTKEY_BASE_URL") ?? null,
Expand All @@ -24,7 +25,8 @@ export class Portkey extends ApiClient {
traceID,
metadata,
Authorization,
cacheForceRefresh
cacheForceRefresh,
debug,
}: ApiClientInterface) {

super({
Expand All @@ -37,6 +39,7 @@ export class Portkey extends ApiClient {
metadata,
Authorization,
cacheForceRefresh,
debug,
});

this.apiKey = apiKey;
Expand All @@ -50,6 +53,7 @@ export class Portkey extends ApiClient {
this.traceID = traceID
this.metadata = metadata
this.cacheForceRefresh = cacheForceRefresh;
this.debug = debug;
}

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

0 comments on commit 64299e8

Please sign in to comment.