umputun / tg-spam

Anti-Spam bot for Telegram and anti-spam library
https://tg-spam.umputun.dev
MIT License
221 stars 39 forks source link

OpenAI error: Post "/chat/completions": unsupported protocol scheme #161

Closed dsent closed 1 month ago

dsent commented 1 month ago

After updating to the latest release and trying to set a custom OpenAI prompt, I see all OpenAI checks failing 100% of the time with the error OpenAI error: Post "/chat/completions": unsupported protocol scheme. The same happens even if I copy the default prompt verbatim. The env variable is set correctly for the container. Studying debug output hints in the direction of quote escaping happening when handling env variables. This is the debug output if I set the OPENAI_PROMPT to the default prompt:

[DEBUG] {app/main.go:438 main.makeDetector} openai  config: {MaxTokensResponse:1024 MaxTokensRequest:2048 MaxSymbolsRequest:16000 Model:gpt-4o SystemPrompt:I'll give you a text from the messaging application and you will return me a json with three fields: {\"spam\": true/false, \"reason\":\"why this is spam\", \"confidence\":1-100}. Set spam:true only of confidence above 80

As we can see, all double quotes get escaped.

dsent commented 1 month ago

I've tried to replace double quotes to single quotes in different ways. They don't seem to be escaped in the logs, but the error is still the same: unsupported protocol scheme.

Maybe something else is going on, like curly braces being interpreted or something.

dsent commented 1 month ago

Okay, it seems that the problem might not be with the custom OpenAI prompt. After removing OPENAI_PROMPT from the env completely, I see the same problem happening. Might be a bug introduced in the latest release.

umputun commented 1 month ago

This was a regression introduced by incorrect handling of a custom API endpoint. It should be fixed on master. Please give it a try and let me know. If all is good, I'll release a quick-fix version right away.

dsent commented 1 month ago

Yep, the issue is fixed. Custom prompting works too!