Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit f52a8e3

Browse files
Add an optional parameter to set the max_tokens option
1 parent 2d90f9a commit f52a8e3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/jetpackai/JetpackAIRestClient.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest.WPComGson
1515
import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequestBuilder
1616
import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequestBuilder.Response
1717
import org.wordpress.android.fluxc.network.rest.wpcom.auth.AccessToken
18+
import org.wordpress.android.fluxc.utils.extensions.filterNotNull
1819
import org.wordpress.android.fluxc.utils.extensions.putIfNotNull
1920
import javax.inject.Inject
2021
import javax.inject.Named
@@ -194,6 +195,7 @@ class JetpackAIRestClient @Inject constructor(
194195
* @param stream When true, the response is a set of EventSource events, otherwise a single response
195196
* @param format The format of the response: 'text' or 'json_object'
196197
* @param model The model to be used for the query: 'gpt-4o' or 'gpt-3.5-turbo-1106'
198+
* @param maxTokens The maximum number of tokens to generate in the response, leave null for default
197199
* @param fields The fields to be requested in the response
198200
*/
199201
@Suppress("LongParameterList")
@@ -204,6 +206,7 @@ class JetpackAIRestClient @Inject constructor(
204206
model: String,
205207
stream: Boolean,
206208
format: ResponseFormat,
209+
maxTokens: Int? = null,
207210
fields: String? = null
208211
): JetpackAIQueryResponse {
209212
val url = WPCOMV2.jetpack_ai_query.url
@@ -213,8 +216,9 @@ class JetpackAIRestClient @Inject constructor(
213216
"stream" to stream,
214217
"feature" to feature,
215218
"format" to format.value,
216-
"model" to model
217-
)
219+
"model" to model,
220+
"max_tokens" to maxTokens
221+
).filterNotNull()
218222

219223
val response = wpComGsonRequestBuilder.syncPostRequest(
220224
restClient = this,

fluxc/src/main/java/org/wordpress/android/fluxc/store/jetpackai/JetpackAIStore.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ class JetpackAIStore @Inject constructor(
293293
* @param stream When true, the response is a set of EventSource events, otherwise a single response
294294
* @param format The format of the response: 'text' or 'json_object'. Default "text"
295295
* @param model The model to be used for the query: 'gpt-4o' or 'gpt-3.5-turbo-1106'. Optional
296+
* @param maxTokens The maximum number of tokens to generate, leave null for default
296297
* @param fields The fields to be requested in the response
297298
*/
298299
@Suppress("LongParameterList")
@@ -303,6 +304,7 @@ class JetpackAIStore @Inject constructor(
303304
stream: Boolean,
304305
model: String = OPENAI_GPT4_MODEL_NAME,
305306
format: ResponseFormat = ResponseFormat.TEXT,
307+
maxTokens: Int? = null,
306308
fields: String? = null
307309
): JetpackAIQueryResponse = coroutineEngine.withDefaultContext(
308310
tag = AppLog.T.API,
@@ -333,6 +335,7 @@ class JetpackAIStore @Inject constructor(
333335
format = format,
334336
model = model,
335337
stream = stream,
338+
maxTokens = maxTokens,
336339
fields = fields
337340
)
338341

0 commit comments

Comments
 (0)