vinnyMS1 Posted November 10, 2024 Posted November 10, 2024 ; Define the Azure OpenAI API key and endpoint Global $apiKey = "" ; Replace with your actual Azure OpenAI API key Global $apiUrl = "https://user.openai.azure.com/openai/deployments/gpt-3.5-turbo-instruct/chat/completions?api-version=2023-09-13" ; Define your Azure OpenAI request payload Global $model = "gpt-3.5-turbo-instruct" ; Specify your model (could be different based on your deployment) Global $prompt = "Tell me a joke" Global $maxTokens = 50 ; Convert payload to JSON format Global $jsonData = '{"model": "' & $model & '", "messages": [{"role": "user", "content": "' & $prompt & '"}], "max_tokens": ' & $maxTokens & '}' ; Send the request using WinHTTP Func AzureOpenAIRequest($url, $jsonPayload, $apiKey) Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("POST", $url, False) $oHTTP.SetRequestHeader("Content-Type", "application/json") $oHTTP.SetRequestHeader("Ocp-Apim-Subscription-Key", $apiKey) ; Correct header for Azure API ; Send the request with JSON payload $oHTTP.Send($jsonPayload) ; Wait for response If $oHTTP.Status = 200 Then Return $oHTTP.ResponseText Else MsgBox(0, "Error", "Request failed with status: " & $oHTTP.Status & " - " & $oHTTP.StatusText) Return "" EndIf EndFunc ; Call the function and display the response Local $response = AzureOpenAIRequest($apiUrl, $jsonData, $apiKey) If $response <> "" Then MsgBox(0, "Azure OpenAI Response", $response) EndIf it throws a 404 error but everything seems ok with the code any ideas?
argumentum Posted November 11, 2024 Posted November 11, 2024 4 hours ago, vinnyMS1 said: throws a 404 error but everything seems ok actually: {"error":{"code":"404","message": "Resource not found"}} 4 hours ago, vinnyMS1 said: but everything seems ok with the code Yes. The problem is the link. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now