Skip to content

Commit

Permalink
feat: chat and completion back to original call
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Feb 23, 2024
1 parent 2005aca commit 56ea656
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 46 deletions.
41 changes: 21 additions & 20 deletions src/apis/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import { createHeaders } from "./createHeaders";
import OpenAI from 'openai';

export class Completions extends ApiResource {
async create(
create(
_body: CompletionsBodyNonStreaming,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<TextCompletion>;
async create(
): APIPromise<TextCompletion>;
create(
_body: CompletionsBodyStreaming,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<Stream<TextCompletion>>
async create(
): APIPromise<Stream<TextCompletion>>
create(
_body: CompletionsBodyBase,
params?: ApiClientInterface,
opts?: RequestOptions,
): Promise<Stream<TextCompletion> | TextCompletion>;
async create(
): APIPromise<Stream<TextCompletion> | TextCompletion>;
create(
_body: CompletionCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: CompletionCreateParams | CompletionsBodyBase | CompletionsBodyStreaming | CompletionsBodyNonStreaming = _body
): APIPromise<TextCompletion> | APIPromise<Stream<TextCompletion>> {
// const body: CompletionCreateParams | CompletionsBodyBase | CompletionsBodyStreaming | CompletionsBodyNonStreaming = _body
const body = _body
// If config is present then override it.
if (params) {
const config = overrideConfig(this.client.config, params.config)
Expand All @@ -38,14 +39,14 @@ export class Completions extends ApiResource {
const stream = _body.stream ?? false


const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: PORTKEY_DEV_BASE_URL,
defaultHeaders: this.client.customHeaders
// const OAIclient = new OpenAI({
// apiKey: OPEN_AI_API_KEY,
// baseURL: PORTKEY_DEV_BASE_URL,
// defaultHeaders: this.client.customHeaders

})
const result = await OAIclient.completions.create(body, opts)
return result;
// })
// const result = await OAIclient.completions.create(body, opts)
// return result;

// if(!stream){
// const result = await OAIclient.completions.create(body, opts)
Expand All @@ -66,10 +67,10 @@ export class Completions extends ApiResource {
// return final_response;
// }

// this.client.responseHeaders
// return this.post(TEXT_COMPLETE_API, { body, ...opts, stream }) as
// | APIPromise<TextCompletion>
// | APIPromise<Stream<TextCompletion>>
this.client.responseHeaders
return this.post(TEXT_COMPLETE_API, { body, ...opts, stream }) as
| APIPromise<TextCompletion>
| APIPromise<Stream<TextCompletion>>
}
}

Expand Down
67 changes: 41 additions & 26 deletions src/apis/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,55 @@ export interface EmbeddingsBody extends ModelParams {
export type EmbeddingsResponse = Record<string, any> & APIResponseType

export class Embeddings extends ApiResource {
async create(
create(
_body: EmbeddingsBody,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body : EmbeddingsBody = _body
const params1 = params
// console.log("embeddings class: PRE: openai_client", this.client.openai_client);

): APIPromise<EmbeddingsResponse> {
const body = _body
if (params) {
const config = overrideConfig(this.client.config, params.config)
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params, config }) }
}

// console.log("embeddings class: body:", body);
// console.log("embeddings class: params1:", params1);
// console.log("embeddings class: opts1:", opts);
// console.log("embeddings class: customHeaders", this.client.customHeaders);
// console.log("embeddings class: POST openai_client", this.client.openai_client);

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: PORTKEY_DEV_BASE_URL,
defaultHeaders: this.client.customHeaders

})
const result = await OAIclient.embeddings.create(body, opts)
// const result = await this.openai_client.embeddings.create(body, opts)
// console.log("RESULT:", result);
return result;

// const response = this.post<EmbeddingsResponse>(EMBEDDINGS_API, { body, ...opts })
// return response
const response = this.post<EmbeddingsResponse>(EMBEDDINGS_API, { body, ...opts })
return response
}
}


// export class Embeddings extends ApiResource {
// async create(
// _body: EmbeddingsBody,
// params?: ApiClientInterface,
// opts?: RequestOptions
// ): Promise<any> {
// const body : EmbeddingsBody = _body
// const params1 = params
// // console.log("embeddings class: PRE: openai_client", this.client.openai_client);

// if (params) {
// const config = overrideConfig(this.client.config, params.config)
// this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params, config }) }
// }

// // console.log("embeddings class: body:", body);
// // console.log("embeddings class: params1:", params1);
// // console.log("embeddings class: opts1:", opts);
// // console.log("embeddings class: customHeaders", this.client.customHeaders);
// // console.log("embeddings class: POST openai_client", this.client.openai_client);

// const OAIclient = new OpenAI({
// apiKey: OPEN_AI_API_KEY,
// baseURL: PORTKEY_DEV_BASE_URL,
// defaultHeaders: this.client.customHeaders

// })
// const result = await OAIclient.embeddings.create(body, opts)
// // const result = await this.openai_client.embeddings.create(body, opts)
// // console.log("RESULT:", result);
// return result;

// // const response = this.post<EmbeddingsResponse>(EMBEDDINGS_API, { body, ...opts })
// // return response
// }
// }

0 comments on commit 56ea656

Please sign in to comment.