Skip to content

Instantly share code, notes, and snippets.

@claygriffiths
Created December 27, 2022 20:51
Show Gist options
  • Save claygriffiths/1ae860d89d8349914a6b176912a2883e to your computer and use it in GitHub Desktop.
Save claygriffiths/1ae860d89d8349914a6b176912a2883e to your computer and use it in GitHub Desktop.
Gravity Forms OpenAI: Custom Separator for Fine-Tuned Models
<?php
/**
* Gravity Wiz // Gravity Forms OpenAI // Add separator to prompt
* https://gravitywiz.com/path/to/article/
*
* Adds a separator to a prompt if needed by a fine-tuned model.
*
* Instructions:
* 1. Customize $model and $sep accordingly.
*/
add_filter( 'gf_openai_request_body', function ( $body, $endpoint, $feed ) {
$model = 'ada:ft-personal-2022-12-27-20-25-37';
$sep = "\n\n###\n\n";
// Customize the model accordingly
if ( $endpoint !== 'completions' || rgars( $feed, 'meta/completions_model' ) !== $model ) {
return $body;
}
// Customize separator accordingly
$body['prompt'] = $body['prompt'] . $sep;
return $body;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment