API调用未能响应

问题描述 投票:0回答:1

我正在尝试使用Android studio中的ASYNC Http客户端>调用聊天gpt api(图像生成)我正在尝试基于文本输入生成图像。然而,每当我尝试调用 api 时,我仍然会失败。我仍然不确定如何解决这个问题,我们将不胜感激。

 fun getaiimage(prompt:String) {
            val client = AsyncHttpClient()
            val params = RequestParams()

            //apikey
            val apikey = "API_KEY"

            //Api parameters
            params["prompt"] = prompt
            params["size"] ="256x256"
            params.put("n",1)
            params["response_format"] = "https://api.openai.com/v1/images/generations"
            params["model"] = "image-beta-003"
            params["Authorization"] = "Bearer $apikey"

            client["https://api.openai.com/v1/images/generations",params, object :
                JsonHttpResponseHandler() {
                override fun onFailure(
                    statusCode: Int,
                    headers: Headers?,
                    response: String?,
                    throwable: Throwable?
                ) {
                    Log.d("Image Failed","Big Errors")
                }

                override fun onSuccess(statusCode: Int, headers: Headers?, response: JSONObject) {
                        Log.d("Image Received","No Errors")


                    }
            }]
        }

我多次尝试重新格式化代码但无济于事

android kotlin openai-api image-generation
1个回答
0
投票

也许您可以从使用现成的库中受益,而不必自己做所有的 http 工作?例如,查看 https://github.com/bay73/generic-ai/blob/main/README.mdhttps://github.com/aallam/openai-kotlin/blob/main/README.md

© www.soinside.com 2019 - 2024. All rights reserved.