Skip to content

Commit

Permalink
Switch to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
riedgar-ms committed Apr 29, 2024
1 parent bcc241a commit 25ecccf
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions guidance/models/_azureai_studio.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import hashlib
import json
import pathlib
import urllib.request

import diskcache as dc
import platformdirs
import requests

from ._model import Chat
from ._grammarless import GrammarlessEngine, Grammarless
Expand Down Expand Up @@ -98,9 +97,6 @@ def _generator(self, prompt, temperature: float):
yield chunk
return

# Now switch to the example code from AzureAI Studio
# Might want to rewrite this to the requests package

# Prepare for the API call (this might be model specific....)
parameters = dict(temperature=temperature)
payload = dict(input_data=dict(input_string=messages, parameters=parameters))
Expand All @@ -111,12 +107,13 @@ def _generator(self, prompt, temperature: float):
"azureml-model-deployment": self._deployment,
}

body = str.encode(json.dumps(payload))

req = urllib.request.Request(self._endpoint, body, headers)
response = requests.post(
self._endpoint,
json=payload,
headers=headers,
)

response = urllib.request.urlopen(req)
result = json.loads(response.read())
result = response.json()

# Now back to OpenAIChatEngine, with slight modifications since
# this isn't a streaming API
Expand Down

0 comments on commit 25ecccf

Please sign in to comment.