Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello。请教一下。我使用了咱们的地址做了转发。结果报错是 400 。是咱们这边的协议转换吃了什么特殊值么 #3

Open
sjsdfg opened this issue Mar 9, 2023 · 8 comments

Comments

@sjsdfg
Copy link

sjsdfg commented Mar 9, 2023

ObjectMapper mapper = defaultObjectMapper();
        OkHttpClient client = OpenAiService.defaultClient("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",
                        Duration.ofMinutes(2))
                .newBuilder()
                .build();

        Retrofit retrofit = new retrofit2.Retrofit.Builder().
                baseUrl("https://open.aiproxy.xyz/").
                client(client).
                addConverterFactory(JacksonConverterFactory.create(mapper)).
                addCallAdapterFactory(RxJava2CallAdapterFactory.create()).
                build();

        Retrofit defaultRetrofit = OpenAiService.defaultRetrofit(client, mapper);
        OpenAiApi api = retrofit.create(OpenAiApi.class);
        OpenAiService openAiService = new OpenAiService(api);

        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
                .model("gpt-3.5-turbo-0301")
                .messages(Lists.newArrayList(
                        new ChatMessage("user", ""),
                        new ChatMessage("user", "他有什么贡献")
                ))
                .build();
        ChatCompletionResult result = openAiService.createChatCompletion(chatCompletionRequest);
        System.out.println(result);
Caused by: retrofit2.adapter.rxjava2.HttpException: HTTP 400 
	at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:57)
	at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:38)
	at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:48)
	at io.reactivex.Observable.subscribe(Observable.java:12267)
	at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
	at io.reactivex.Observable.subscribe(Observable.java:12267)
	at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
	at io.reactivex.Single.subscribe(Single.java:3603)
	at io.reactivex.Single.blockingGet(Single.java:2834)
	at com.theokanning.openai.service.OpenAiService.execute(OpenAiService.java:217)
@sjsdfg
Copy link
Author

sjsdfg commented Mar 9, 2023

image

@sjsdfg
Copy link
Author

sjsdfg commented Mar 9, 2023

Uploading image.png…
并且看起来没有吧 header 转发过去

@sjsdfg
Copy link
Author

sjsdfg commented Mar 9, 2023

image

@geekr-dev
Copy link
Owner

这个里面的key不是你真的吧 建议隐去 不要公开出来 请求头里面设置json类型 然后传递的body必须是json结构数据

curl --location --request POST 'https://open.aiproxy.xyz/v1/completions' \
--header 'Authorization: Bearer sk-XXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{ 
    "model": "text-davinci-003",
    "prompt": "扮演一个导游,告诉我杭州有啥好玩的",
    "max_tokens": 100,
    "temperature": 0
}'

把这里的 sk-XXXXXXXX 换成你自己的 API KEY 试试看

image

@sjsdfg
Copy link
Author

sjsdfg commented Mar 10, 2023

这个里面的key不是你真的吧 建议隐去 不要公开出来 请求头里面设置json类型 然后传递的body必须是json结构数据

curl --location --request POST 'https://open.aiproxy.xyz/v1/completions' \
--header 'Authorization: Bearer sk-XXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{ 
    "model": "text-davinci-003",
    "prompt": "扮演一个导游,告诉我杭州有啥好玩的",
    "max_tokens": 100,
    "temperature": 0
}'

把这里的 sk-XXXXXXXX 换成你自己的 API KEY 试试看

image

那个 token 已经被封禁了。发出来没啥事。就是用来测试能不能吃到 Openapi 的 429 来看链路是不是通的。

我确定发送过去的是json 数据结构。因为开 VPN 的时候直连打过去上面的代码是 ok 的。现在不知道问题出在了哪里。
使用 postman 确实是可以能被 json 正确的解析到

@geekr-dev
Copy link
Owner

这个里面的key不是你真的吧 建议隐去 不要公开出来 请求头里面设置json类型 然后传递的body必须是json结构数据

curl --location --request POST 'https://open.aiproxy.xyz/v1/completions' \
--header 'Authorization: Bearer sk-XXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{ 
    "model": "text-davinci-003",
    "prompt": "扮演一个导游,告诉我杭州有啥好玩的",
    "max_tokens": 100,
    "temperature": 0
}'

把这里的 sk-XXXXXXXX 换成你自己的 API KEY 试试看
image

那个 token 已经被封禁了。发出来没啥事。就是用来测试能不能吃到 Openapi 的 429 来看链路是不是通的。

我确定发送过去的是json 数据结构。因为开 VPN 的时候直连打过去上面的代码是 ok 的。现在不知道问题出在了哪里。 使用 postman 确实是可以能被 json 正确的解析到

调试下代码看看底层传递到代理的请求数据是怎么样的,包括请求头和请求的Body,看看有没有问题

@geekr-dev
Copy link
Owner

如果Postman里面代理和OpenAI返回的数据结构一致,就不是代理的问题,你看看两个返回的数据结构是一样的吗

@zl277287818
Copy link

可能账号被封了。看下有没有收到邮件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants