Skip to content

Commit 0b8e97f

Browse files
Add missing serial names on ImagesGenerationRequest (#65)
* fix: add serial names for images generation request * style: spotless happiness * refactor: apply suggestion on image size naming Co-authored-by: Simon Vergauwen <[email protected]> * refactor: apply suggestion on image size naming on rest of models --------- Co-authored-by: Simon Vergauwen <[email protected]>
1 parent 6e963cb commit 0b8e97f

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

core/src/commonMain/kotlin/com/xebia/functional/xef/agents/ImageGenerationAgent.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ImageGenerationAgent(
1414
private val context: VectorStore = VectorStore.EMPTY,
1515
private val user: String = "testing",
1616
private val numberImages: Int,
17-
private val imageSize: String,
17+
private val size: String,
1818
private val bringFromContext: Int = 10
1919
) : Agent<Map<String, String>, ImagesGenerationResponse> {
2020

@@ -48,7 +48,7 @@ class ImageGenerationAgent(
4848
ImagesGenerationRequest(
4949
prompt = prompt,
5050
numberImages = numberImages,
51-
imageSize = imageSize,
51+
size = size,
5252
user = user
5353
)
5454
return llm.createImages(request)

core/src/commonMain/kotlin/com/xebia/functional/xef/auto/AI.kt

+9-10
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,22 @@ class AIScope(
230230
* @param prompt a [PromptTemplate] describing the images you want to generate.
231231
* @param variables a map of variables to be replaced in the [prompt].
232232
* @param numberImages number of images to generate.
233-
* @param imageSize size of the images to generate.
233+
* @param size the size of the images to generate.
234234
*/
235235
@AiDsl
236236
suspend fun images(
237237
prompt: PromptTemplate<String>,
238238
variables: Map<String, String>,
239239
numberImages: Int = 1,
240-
imageSize: String = "1024x1024"
240+
size: String = "1024x1024"
241241
): ImagesGenerationResponse =
242242
with(
243243
ImageGenerationAgent(
244244
llm = openAIClient,
245245
template = prompt,
246246
context = context,
247247
numberImages = numberImages,
248-
imageSize = imageSize
248+
size = size
249249
)
250250
) {
251251
call(variables)
@@ -257,30 +257,29 @@ class AIScope(
257257
*
258258
* @param prompt a [PromptTemplate] describing the images you want to generate.
259259
* @param numberImages number of images to generate.
260-
* @param imageSize size of the images to generate.
260+
* @param size the size of the images to generate.
261261
*/
262262
@AiDsl
263263
suspend fun images(
264264
prompt: String,
265265
numberImages: Int = 1,
266-
imageSize: String = "1024x1024"
267-
): ImagesGenerationResponse = images(PromptTemplate(prompt), emptyMap(), numberImages, imageSize)
266+
size: String = "1024x1024"
267+
): ImagesGenerationResponse = images(PromptTemplate(prompt), emptyMap(), numberImages, size)
268268

269269
/**
270270
* Run a [prompt] describes the images you want to generate within the context of [AIScope].
271271
* Produces a [ImagesGenerationResponse] which then gets serialized to [A] through [prompt].
272272
*
273273
* @param prompt a [PromptTemplate] describing the images you want to generate.
274-
* @param n number of images to generate.
275-
* @param imageSize size of the images to generate.
274+
* @param size the size of the images to generate.
276275
*/
277276
@AiDsl
278277
suspend inline fun <reified A> Raise<AIError>.image(
279278
prompt: String,
280-
imageSize: String = "1024x1024",
279+
size: String = "1024x1024",
281280
llmModel: LLMModel = LLMModel.GPT_3_5_TURBO
282281
): A {
283-
val imageResponse = images(prompt, 1, imageSize)
282+
val imageResponse = images(prompt, 1, size)
284283
val url = imageResponse.data.firstOrNull() ?: raise(AIError.NoResponse)
285284
return either {
286285
PromptTemplate(

core/src/commonMain/kotlin/com/xebia/functional/xef/llm/openai/OpenAIClient.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.xebia.functional.xef.httpClient
88
import io.ktor.client.HttpClient
99
import io.ktor.client.call.body
1010
import io.ktor.client.engine.HttpClientEngine
11-
import io.ktor.client.plugins.*
11+
import io.ktor.client.plugins.timeout
1212
import io.ktor.client.request.post
1313
import io.ktor.client.statement.HttpResponse
1414
import io.ktor.http.path
@@ -25,8 +25,8 @@ interface OpenAIClient {
2525
@Serializable
2626
data class ImagesGenerationRequest(
2727
val prompt: String,
28-
val numberImages: Int = 1,
29-
val imageSize: String = "1024x1024",
28+
@SerialName("n") val numberImages: Int = 1,
29+
val size: String = "1024x1024",
3030
@SerialName("response_format") val responseFormat: String = "url",
3131
val user: String? = null
3232
)
@@ -39,8 +39,7 @@ data class ImagesGenerationResponse(val created: Long, val data: List<ImageGener
3939
suspend fun ResourceScope.KtorOpenAIClient(
4040
config: OpenAIConfig,
4141
engine: HttpClientEngine? = null
42-
): OpenAIClient =
43-
com.xebia.functional.xef.llm.openai.KtorOpenAIClient(httpClient(engine, config.baseUrl), config)
42+
): OpenAIClient = KtorOpenAIClient(httpClient(engine, config.baseUrl), config)
4443

4544
private class KtorOpenAIClient(
4645
private val httpClient: HttpClient,

0 commit comments

Comments
 (0)