Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion configs/agents/openai-chat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion configs/agents/openai-text.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/client/agents/http_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down