[Python] How can I deploy a fine-tuned GPT model in Azure via Python without using a token...

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    I follow Azure's tutorial on fine-tuning GPT. I follow the deployment phase.

    Code:

    # Deploy fine-tuned model

    import json
    import requests

    token = '[redacted]'
    subscription = '[redacted]'
    resource_group = "[redacted]"
    resource_name = "[redacted]"
    model_deployment_name = "gpt-4o-mini-2024-07-18-ft" # Custom deployment name you chose for your fine-tuning model

    deploy_params = {'api-version': "2023-05-01"}
    deploy_headers = {'Authorization': 'Bearer {}'.format(token), 'Content-Type': 'application/json'}

    deploy_data = {
    "sku": {"name": "standard", "capacity": 1},
    "properties": {
    "model": {
    "format": "OpenAI",
    "name": "gpt-4o-mini-2024-07-18.ft-[redacted]", #retrieve this value from the previous call, it will look like gpt-4o-mini-2024-07-18.ft-[redacted]
    "version": "1"
    }
    }
    }
    deploy_data = json.dumps(deploy_data)

    request_url = f'https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resource_group}/providers/Microsoft.CognitiveServices/accounts/{resource_name}/deployments/{model_deployment_name}'

    print('Creating a new deployment...')

    r = requests.put(request_url, params=deploy_params, headers=deploy_headers, data=deploy_data)

    print(r)
    print(r.reason)
    print(r.json())


    That works fine, but the token expires quickly. This annoys me. How can I deploy a fine-tuned GPT model in Azure via Python without using a token (e.g., using an endpoint key instead)?

    Continue reading...

Compartilhe esta Página