nalgeon / pokitoki

Humble GPT Telegram Bot
MIT License
316 stars 55 forks source link

Can it support Azure openai? Or an endpoint that can be customized for api access? #18

Closed suikaremilia closed 1 year ago

suikaremilia commented 1 year ago

https://learn.microsoft.com/en-us/azure/cognitive-services/openai/overview

Azure also has openai service, which can do more customizable things than openai, so can the bot support azure openai?

nalgeon commented 1 year ago

According to the link, both gpt-3.5 and gpt-4 are not yet publicly available on Azure. Do you already have access to them?

suikaremilia commented 1 year ago

https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?tabs=command-line&pivots=programming-language-python

Like openai, they use two items as a preview version, but they can easily apply for access rights.

GPT4 needs to wait, GPT-3.5 is actually open.

nalgeon commented 1 year ago

Do you have access to the GPT 3.5 Azure OpenAI API? Will you be able to test the implementation if the bot supports it?

suikaremilia commented 1 year ago

Yes, I can test it.

nalgeon commented 1 year ago

Okay, please try with the latest bot version (5fa0144). You'll need to set the actual values for all three parameters in the openai.azure config property (endpoint, version, and deployment):

openai:
    # ...
    azure:
        endpoint: https://example-endpoint.openai.azure.com
        version: 2023-03-15-preview
        deployment: deployment-name
suikaremilia commented 1 year ago

Thanks for your work, now both GPT-4 and GPT-3.5 of azure openai are working fine.

It works normally with the built-in model, and can also reply as an attachment.

From my tests it looks like only /imagine is not working, but this is an Azure issue.

imagine:
    enabled: users_only

When users_only is set, you will get such prompts:

The imagine command is disabled for group users.

Maybe image can call DALLE2 alone instead of sharing API_KEY with chat.

suikaremilia commented 1 year ago

Image generation is quite pricey ($0.016-$0.020 per image). By default it's only enabled for users listed in telegram.usernames, not for group members. You can change this with the imagine.enabled config property.

I am bad, I noticed this tip.

I thought the prompt of the image was wrong, because I didn't add users when I first tested the image. Now the prompt is normal: Failed to answer. Reason: openai.error.AuthenticationError: Incorrect API key provided:

Also, why filter users by username and not by user id? Not everyone has a telegram username set up.

suikaremilia commented 1 year ago

I tested all the items in the readme with gpt-4 and gpt-3.5 of azure openai, and found no other problems. Thanks again for your work.

HeySlava commented 1 year ago

Also, why filter users by username and not by user id? Not everyone has a telegram username set up.

If I've got it correctly, you can specify your users in config.telegram.chat_ids and it will work as you expected Source code of python-telegram-bot filters Chat

nalgeon commented 1 year ago

According to Azure docs, it does not support the DALL-E model (please correct me if I am wrong). So I didn't add any Azure API params for the /imagine command (which uses DALL-E).

Also, why filter users by username and not by user id?

Because it's much easier to ask a user for their username than to try to find out their user id. And if they don't have a username, they can easily get one.