diff --git a/configs/agents/openai-chat.yaml b/configs/agents/openai-chat.yaml index 53eff77d..a11d217f 100644 --- a/configs/agents/openai-chat.yaml +++ b/configs/agents/openai-chat.yaml @@ -3,7 +3,11 @@ parameters: url: https://api.openai.com/v1/chat/completions headers: Content-Type: application/json - Authorization: Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + Authorization: + - Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + - Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + - Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + # You can place any number of keys here, and they will be invoked equally. body: temperature: 0 prompter: diff --git a/configs/agents/openai-text.yaml b/configs/agents/openai-text.yaml index 1bd3536a..4f78dd89 100644 --- a/configs/agents/openai-text.yaml +++ b/configs/agents/openai-text.yaml @@ -4,7 +4,11 @@ parameters: url: https://api.openai.com/v1/completions headers: Content-Type: application/json - Authorization: Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + Authorization: + - Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + - Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + - Bearer <% PUT-YOUR-OPENAI-KEY-HERE %> + # You can place any number of keys here, and they will be invoked equally. body: model: <% NAME %> temperature: 0 diff --git a/src/client/agents/http_agent.py b/src/client/agents/http_agent.py index 677f668c..c4814ebe 100644 --- a/src/client/agents/http_agent.py +++ b/src/client/agents/http_agent.py @@ -179,13 +179,22 @@ def __init__( self.body = body or {} self.return_format = return_format self.prompter = Prompter.get_prompter(prompter) + self.key_list = self.headers["Authorization"] if type(self.headers["Authorization"]) == list else [self.headers["Authorization"]] + self.key_amount = len(self.key_list) + self.key_idx = 0 + if not self.url: raise Exception("Please set 'url' parameter") def _handle_history(self, history: List[dict]) -> Dict[str, Any]: return self.prompter(history) + def _authorization_scheduling(self): + self.headers["Authorization"] = self.key_list[self.key_idx] + self.key_idx = (self.key_idx + 1) % self.key_amount + def inference(self, history: List[dict]) -> str: + self._authorization_scheduling() for _ in range(3): try: body = self.body.copy()