Skip to content

Commit

Permalink
Feat: Add apim-request-id to stream_with_data response (#320)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Seabock (Centific Technologies Inc) <[email protected]>
  • Loading branch information
iseabock and Ian Seabock (Centific Technologies Inc) authored Oct 17, 2023
1 parent 153c4d0 commit 0c69d69
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ def stream_with_data(body, headers, endpoint, history_metadata={}):
"choices": [{
"messages": []
}],
"apim-request-id": "",
'history_metadata': history_metadata
}
try:
with s.post(endpoint, json=body, headers=headers, stream=True) as r:
apimRequestId = r.headers.get('apim-request-id')
for line in r.iter_lines(chunk_size=10):
if line:
lineJson = json.loads(line.lstrip(b'data:').decode('utf-8'))
Expand All @@ -227,6 +229,7 @@ def stream_with_data(body, headers, endpoint, history_metadata={}):
response["model"] = lineJson["model"]
response["created"] = lineJson["created"]
response["object"] = lineJson["object"]
response["apim-request-id"] = apimRequestId

role = lineJson["choices"][0]["messages"][0]["delta"].get("role")
if role == "tool":
Expand Down

0 comments on commit 0c69d69

Please sign in to comment.