openai-cpp icon indicating copy to clipboard operation
openai-cpp copied to clipboard

About multiple secret keys rate limit

Open lzonel opened this issue 2 years ago • 1 comments

If I want to use multiple sks and dynamically change sks, how should I write them because a single sk affects the rate?

lzonel avatar Apr 26 '23 06:04 lzonel

@lzonel I suppose you are referring to secret keys as sks ?

Approach 1: If you want to have only one instance and manage dynamically keys

If you are conformtable with C++, you can use the undocumented method setToken on the session see https://github.com/olrea/openai-cpp/blob/61ad823ba3653d9751e1e5f60846af208858f69e/include/openai/openai.hpp#L97

I am willing to add more helpers and documentation if this something you might really need and you don't know how to proceed.

Approach 2: If you want to have several instances with different secret keys

Check out https://github.com/olrea/openai-cpp#pass-by-reference

Pass by reference

An other approach is to pass the OpenAI instance by reference, store it, and call the appropriate methods when needed.

void bar(openai::OpenAI& openai) {
    openai.completion.create({
        {"model", "text-davinci-003"},
        {"prompt", "Say bar() function called"}
    });
}

int main() {
    openai::OpenAI openai_instance{"your_api_key"};
    bar(openai_instance);
}

You can use a std::reference_wrapper as shown in examples/09-instances.cpp. This strategy is useful if you have to manage several OpenAI-CPP instances.

coin-au-carre avatar Apr 27 '23 09:04 coin-au-carre