Skip to content

Commit

Permalink
feat: Updated sdks/ts/src/utils/openaiPatch.ts (#246)
Browse files Browse the repository at this point in the history
Co-authored-by: sweep-ai[bot] <128439645+sweep-ai[bot]@users.noreply.github.com>
  • Loading branch information
sweep-ai[bot] authored Apr 18, 2024
1 parent 4a1ac5a commit ea2e144
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sdks/ts/src/utils/openaiPatch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
/**
* Patches the 'create' method of an OpenAI client instance to ensure a default model is used if none is specified.
* This is useful for enforcing a consistent model usage across different parts of the SDK.
*
* @param client The OpenAI client instance to be patched.
* @param scope Optional. The scope in which the original 'create' method is bound. Defaults to the client itself if not provided.
*/
export function patchCreate(client: any, scope: any = null) {
if (!scope) {
scope = client;
}

const originalCreate = client.create.bind(client);
client.create = (settings: { [key: string]: any }) => {
// Set the default model to 'julep-ai/samantha-1-turbo' if none is specified in the settings.
settings.model = settings.model || "julep-ai/samantha-1-turbo";

return originalCreate.call(scope, settings);
};

return client;
// After applying this patch, any calls to the 'create' method on the patched client will use the default model unless another model is explicitly specified.
}

0 comments on commit ea2e144

Please sign in to comment.