Skip to content

Commit d890b2c

Browse files
committed
Added new gf_openai_chat_completions_message PHP filter hook.
1 parent 0610bc5 commit d890b2c

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

class-gwiz-gf-openai.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,18 @@ public function get_user_models() {
361361
$response = json_decode( $response, true );
362362

363363
if ( is_array( rgar( $response, 'data' ) ) ) {
364-
// Filter results to only models owned by the user/org.
365-
foreach ( $response['data'] as $model ) {
366-
if ( strpos( $model['owned_by'], 'user-' ) === 0 || strpos( $model['owned_by'], 'org-' ) === 0 ) {
367-
$models[ $model['id'] ] = array_merge(
368-
$model,
369-
array(
370-
'user_model' => true,
371-
)
372-
);
364+
// Filter results to only models owned by the user/org.
365+
foreach ( $response['data'] as $model ) {
366+
if ( strpos( $model['owned_by'], 'user-' ) === 0 || strpos( $model['owned_by'], 'org-' ) === 0 ) {
367+
$models[ $model['id'] ] = array_merge(
368+
$model,
369+
array(
370+
'user_model' => true,
371+
)
372+
);
373+
}
373374
}
374375
}
375-
}
376376
} catch ( Exception $e ) {
377377
// Do nothing, $models is already an empty array.
378378
}
@@ -1134,6 +1134,9 @@ public function process_endpoint_chat_completions( $feed, $entry, $form ) {
11341134
// Parse the merge tags in the message.
11351135
$message = GFCommon::replace_variables( $message, $form, $entry, false, false, false, 'text' );
11361136

1137+
// Allow filtering the message
1138+
$message = apply_filters( 'gf_openai_chat_completions_message', $message, $entry, $feed, $form );
1139+
11371140
GFAPI::add_note( $entry['id'], 0, 'OpenAI Request (' . $feed['meta']['feed_name'] . ')', sprintf( __( 'Sent request to OpenAI chat/completions endpoint.', 'gravityforms-openai' ) ) );
11381141

11391142
// translators: placeholders are the feed name, model, prompt

0 commit comments

Comments
 (0)