1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# Configuración de la solicitud $uri = "https://api.openai.com/v1/chat/completions" $apiKey = "sk-ADFAFASDF" # Asegúrate de reemplazar 'sk-code' con tu clave de API real $headers = @{ "Authorization" = "Bearer $apiKey" "Content-Type" = "application/json; charset=utf-8" } # Cuerpo de la solicitud $body = @{ model = "gpt-3.5-turbo" messages = @( @{ role = "user" content = "Para qué sirve Kotlin?" } ) } # Convertir el cuerpo a JSON con codificación UTF-8 $jsonBody = $body | ConvertTo-Json -Depth 10 -Compress $bytes = [System.Text.Encoding]::UTF8.GetBytes($jsonBody) $stream = [System.IO.MemoryStream]::new($bytes) # Realizar la solicitud $response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $stream $response.choices.message.content |