Skip to content

Commit

Permalink
Consider all openai headers (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
KenyonY authored Nov 16, 2023
1 parent f53d6fd commit a091705
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
18 changes: 18 additions & 0 deletions Examples/beta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from openai import OpenAI
from sparrow import yaml_load

config = yaml_load("config.yaml", rel_path=True)
print(f"{config=}")

client = OpenAI(
api_key=config['api_key'],
base_url=config['api_base'],
)

my_assistant = client.beta.assistants.create(
instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
name="Math Tutor",
tools=[{"type": "code_interpreter"}],
model="gpt-4",
)
print(my_assistant)
18 changes: 13 additions & 5 deletions openai_forward/forward/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,19 @@ def prepare_client(self, request: Request, return_origin_header=False) -> dict:
)
url = f"{self.BASE_URL}{url_path}?{request.url.query}"

headers = dict(request.headers)
auth = headers.get("authorization", "")
content_type = headers.get("content-type", "application/json")
if not return_origin_header:
headers = {"Content-Type": content_type, "Authorization": auth}
auth = request.headers.get("Authorization", "")

if return_origin_header:
headers = request.headers
else:
headers = {
"content-type": request.headers.get("content-type", "application/json"),
"authorization": auth,
}
for key, value in request.headers.items():
if key.startswith("openai"):
headers[key] = value
print(f"{headers=}")

return {
'auth': auth,
Expand Down

0 comments on commit a091705

Please sign in to comment.