Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joschkabraun committed Feb 1, 2024
1 parent ae345a0 commit 4c11925
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/utils/wrap_openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pareaLogger } from '../parea_logger';
import { asyncLocalStorage, traceInsert } from './trace_utils';
import { genTraceId, toDateTimeString } from '../helpers';

function wrapMethod(method: Function, idxArgs: number = 0, io: any) {
function wrapMethod(method: Function, idxArgs: number = 0) {
return async function (this: any, ...args: any[]) {
const traceId = genTraceId();
const startTimestamp = new Date();
Expand Down Expand Up @@ -49,9 +49,6 @@ function wrapMethod(method: Function, idxArgs: number = 0, io: any) {

try {
response = await method.apply(this, args);
if (io) {
await io.logger.info(`response in try: ${response}`);
}
traceInsert(traceId, {
output: getOutput(response),
input_tokens: response.usage.prompt_tokens,
Expand All @@ -74,15 +71,7 @@ function wrapMethod(method: Function, idxArgs: number = 0, io: any) {
latency: (endTimestamp.getTime() - startTimestamp.getTime()) / 1000,
status: status,
});
if (io) {
await io.logger.info(`'traceLog in finally: ${JSON.stringify(traceLog)}`);
await io.logger.info(`pareaLogger in finally: ${pareaLogger}`);
}
const response = await pareaLogger.recordLog(traceLog);
if (io) {
await io.logger.info(`response in finally: ${response}`);
await io.logger.info(`response in finally: ${JSON.stringify(response)}`);
}
await pareaLogger.recordLog(traceLog);
}

if (error) {
Expand All @@ -95,8 +84,8 @@ function wrapMethod(method: Function, idxArgs: number = 0, io: any) {
};
}

export function traceOpenAITriggerDev(ioOpenAIChatCompletionsCreate: Function, io: any): Function {
return wrapMethod(ioOpenAIChatCompletionsCreate, 1, io);
export function traceOpenAITriggerDev(ioOpenAIChatCompletionsCreate: Function): Function {
return wrapMethod(ioOpenAIChatCompletionsCreate, 1);
}

export function patchOpenAI(openai: OpenAI) {
Expand Down

0 comments on commit 4c11925

Please sign in to comment.