Skip to content

Commit 62899b5

Browse files
junerverclaude
andcommitted
⚡️ [AI]: Rename schemaString parameter to schema in useGenerateObject
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fb1d1ec commit 62899b5

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ messages.value.forEach { message ->
200200
data class Recipe(val name: String, val ingredients: List<String>)
201201

202202
val (recipe, rawJson, isLoading, error, submit, stop) = useGenerateObject<Recipe>(
203-
schemaString = Recipe::class.jsonSchemaString,
203+
schema = Recipe::class.jsonSchemaString,
204204
) {
205205
provider = Providers.OpenAI(apiKey = "your-api-key")
206206
systemPrompt = "You are a professional chef."

README.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ messages.value.forEach { message ->
207207
data class Recipe(val name: String, val ingredients: List<String>)
208208

209209
val (recipe, rawJson, isLoading, error, submit, stop) = useGenerateObject<Recipe>(
210-
schemaString = Recipe::class.jsonSchemaString,
210+
schema = Recipe::class.jsonSchemaString,
211211
) {
212212
provider = Providers.OpenAI(apiKey = "your-api-key")
213213
systemPrompt = "你是一位专业的厨师。"

ai/src/commonMain/kotlin/xyz/junerver/compose/ai/usegenerateobject/useGenerateObject.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ private val defaultJson = Json {
109109
/**
110110
* Builds the system prompt with JSON schema injection.
111111
*/
112-
private fun buildSchemaSystemPrompt(userSystemPrompt: String?, schemaString: String): String {
112+
private fun buildSchemaSystemPrompt(userSystemPrompt: String?, schema: String): String {
113113
val basePrompt = userSystemPrompt?.let { "$it\n\n" } ?: ""
114114
return """
115115
|${basePrompt}You must respond in JSON format, strictly following this JSON Schema:
116-
|$schemaString
116+
|$schema
117117
|
118118
|Output only valid JSON, do not include any other text, markdown code blocks, or explanations.
119119
""".trimMargin()
@@ -170,7 +170,7 @@ private fun cleanJsonResponse(raw: String): String = raw
170170
* @Composable
171171
* fun RecipeGenerator() {
172172
* val (recipe, rawJson, isLoading, error, submit, stop) = useGenerateObject<Recipe>(
173-
* schemaString = recipeSchema
173+
* schema = recipeSchema
174174
* ) {
175175
* provider = Providers.DeepSeek(apiKey = "your-api-key")
176176
* systemPrompt = "You are a professional chef."
@@ -188,16 +188,16 @@ private fun cleanJsonResponse(raw: String): String = raw
188188
* ```
189189
*
190190
* @param T The target data class type, must be @Serializable
191-
* @param schemaString The JSON Schema string describing the expected output structure
191+
* @param schema The JSON Schema string describing the expected output structure
192192
* @param optionsOf Configuration factory function for options
193193
* @return GenerateObjectHolder containing object state and control functions
194194
*/
195195
@Composable
196196
inline fun <reified T : Any> useGenerateObject(
197-
schemaString: String,
197+
schema: String,
198198
noinline optionsOf: GenerateObjectOptions<T>.() -> Unit = {},
199199
): GenerateObjectHolder<T> = useGenerateObject(
200-
schemaString = schemaString,
200+
schema = schema,
201201
serializer = serializer<T>(),
202202
optionsOf = optionsOf,
203203
)
@@ -209,14 +209,14 @@ inline fun <reified T : Any> useGenerateObject(
209209
* cannot be used.
210210
*
211211
* @param T The target data class type
212-
* @param schemaString The JSON Schema string describing the expected output structure
212+
* @param schema The JSON Schema string describing the expected output structure
213213
* @param serializer The KSerializer for type T
214214
* @param optionsOf Configuration factory function for options
215215
* @return GenerateObjectHolder containing object state and control functions
216216
*/
217217
@Composable
218218
fun <T : Any> useGenerateObject(
219-
schemaString: String,
219+
schema: String,
220220
serializer: KSerializer<T>,
221221
optionsOf: GenerateObjectOptions<T>.() -> Unit = {},
222222
): GenerateObjectHolder<T> {
@@ -229,8 +229,8 @@ fun <T : Any> useGenerateObject(
229229
val parseError = _useState<Throwable?>(null)
230230

231231
// Build schema-injected system prompt
232-
val schemaSystemPrompt = remember(schemaString, options.systemPrompt) {
233-
buildSchemaSystemPrompt(options.systemPrompt, schemaString)
232+
val schemaSystemPrompt = remember(schema, options.systemPrompt) {
233+
buildSchemaSystemPrompt(options.systemPrompt, schema)
234234
}
235235

236236
// Use useChat internally
@@ -307,6 +307,6 @@ fun <T : Any> useGenerateObject(
307307
*/
308308
@Composable
309309
inline fun <reified T : Any> rememberGenerateObject(
310-
schemaString: String,
310+
schema: String,
311311
noinline optionsOf: GenerateObjectOptions<T>.() -> Unit = {},
312-
): GenerateObjectHolder<T> = useGenerateObject(schemaString, optionsOf)
312+
): GenerateObjectHolder<T> = useGenerateObject(schema, optionsOf)

app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseGenerateObjectExample.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fun UseGenerateObjectExample() {
151151

152152
// Use the hook
153153
val (recipe, _, isLoading, error, submit, stop) = useGenerateObject<Recipe>(
154-
schemaString = recipeSchema,
154+
schema = recipeSchema,
155155
) {
156156
this.provider = provider
157157
this.model = model.ifBlank { null }

0 commit comments

Comments
 (0)