Skip to content

Instantly share code, notes, and snippets.

@jalotra
Created July 14, 2023 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalotra/d25e986cd75db9bcc6039c0b74779d65 to your computer and use it in GitHub Desktop.
Save jalotra/d25e986cd75db9bcc6039c0b74779d65 to your computer and use it in GitHub Desktop.
def get_prompt_from_azure(message: str):
# Create an openAI connection every time the request is sent !
AZURE_API_ENDPOINT = os.environ.get("AZURE_API_ENDPOINT")
AZURE_API_KEY = os.environ.get("AZURE_API_KEY")
AZURE_API_DEPLOYMENT_NAME = "gpt-35-turbo-france"
AZURE_API_VERSION = "2023-05-15"
url = f"{AZURE_API_ENDPOINT}/openai/deployments/{AZURE_API_DEPLOYMENT_NAME}/chat/completions?api-version={AZURE_API_VERSION}"
payload = json.dumps({
"messages": [
{
"role" : "system",
"content" : f"{SYSTEM_PROMPT}"
},
{
"role": "user",
"content": f"{message}"
}
]
})
headers = {
'Content-Type': 'application/json',
'api-key': f'{AZURE_API_KEY}'
}
response = requests.request("POST", url, headers=headers, data=payload)
if response.status_code != 200:
raise Exception("Not 200 response code")
return response.json()["choices"][0]["message"]["content"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment