in 3_llmops-aifoundry/3_2_prototyping/chat/phi35_finetuned.py [0:0]
def chat(input_data: str, connection: CustomConnection) -> str:
# Request data goes here
# The example below assumes JSON formatting which may be updated
# depending on the format your endpoint expects.
# More information can be found here:
# https://docs.microsoft.com/azure/machine-learning/how-to-deploy-advanced-entry-script
data = {
"input_data":
[
{"role": "user", "content": "Tell me Microsoft's brief history."},
{"role": "assistant", "content": "Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell a BASIC interpreter for the Altair 8800."},
{"role": "user", "content": input_data},
{"role": "user", "content": "Keep the answer simple."},
],
"params": {
"temperature": 0.2,
"max_new_tokens": 256,
"do_sample": True,
"return_full_text": False
}
}
body = str.encode(json.dumps(data))
endpoint_url = connection.endpoint
# Replace this with the primary/secondary key, AMLToken, or Microsoft Entra ID token for the endpoint
api_key = connection.key
if not api_key:
raise Exception("A key should be provided to invoke the endpoint")
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}
try:
response = requests.post(endpoint_url, json=data, headers=headers)
print(response)
response.raise_for_status()
result = response.json()
result = result['result']
return result
except requests.exceptions.RequestException as e:
print(e)
except urllib.error.HTTPError as error:
print("The request failed with status code: " + str(error.code))
# Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
print(error.info())
print(error.read().decode("utf8", 'ignore'))