-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updated sdks/ts/src/utils/openaiPatch.ts (#246)
Co-authored-by: sweep-ai[bot] <128439645+sweep-ai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4a1ac5a
commit ea2e144
Showing
1 changed file
with
9 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} |