Jump to content

Recommended Posts

Posted
; 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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...