微调的 openAI API 给出 NotFoundError:错误代码:404

问题描述 投票:0回答:1

这是我的第一个openAI微调工作,所以我了解的不多。我正在尝试微调 OpenAI API 以根据描述生成产品 ID。代码运行成功并且还生成了模型 ID,我也为此付费了。但是,当我想使用模型生成输出时,它会给出 NotFoundError: Error code: 404 - {'error': {'message': 'The model `ftjob-****' does notence or您无权访问它。', 'type': 'invalid_request_error', 'param': None, 'code': 'model_not_found'}}

我的完整代码如下。

import pandas as pd
df = pd.read_csv("/content/machine screws.csv")
df.head()

def convert_to_gpt35_format(dataset):
    fine_tuning_data = []
    for _, row in dataset.iterrows():
        fine_tuning_data.append({
            "messages": [
                {"role": "user", "content": row['Input']},
                {"role": "assistant", "content": row['Output']} #json_response}
            ]
        })
    return fine_tuning_data

converted_data = convert_to_gpt35_format(df)

from sklearn.model_selection import train_test_split


train_data, val_data = train_test_split(
    converted_data,
    test_size=0.2,
    random_state=42  # for reproducibility
)


import json
def write_to_jsonl(data, file_path):
    with open(file_path, 'w') as file:
        for entry in data:
            json.dump(entry, file)
            file.write('\n')

training_file_name = "train_a.jsonl"
validation_file_name = "val_a.jsonl"

write_to_jsonl(train_data, training_file_name)
write_to_jsonl(val_data, validation_file_name)


from openai import OpenAI
client = OpenAI(api_key="OPENAI_KEY")


training_file = client.files.create(
    file=open(training_file_name, "rb"), purpose="fine-tune"
)
validation_file = client.files.create(
    file=open(validation_file_name, "rb"), purpose="fine-tune"
)


response = client.fine_tuning.jobs.create(
    training_file=training_file.id,
    validation_file=validation_file.id,
    model="gpt-3.5-turbo",
)

print("Fine-Tuning Job ID:", response.id)
print("Status:", response.status)
print("Created at:", response.created_at)

job_id = response.id


prompt = " 1-8 X 15 FLAT SLTD MACH SCREW 3 THRD HDG "


response = client.chat.completions.create(
        model=job_id, messages=prompt, temperature=0, max_tokens=50
    )

prediction_text = response.choices[0].text.strip()
print(f"Predicted code: {prediction_text}")
nlp openai-api fine-tuning
1个回答
0
投票

您需要指定在

此处
找到的api_version

您还需要指定 azure_endpoint,您可以在 azure 门户的“资源和密钥”中找到该端点。

from openai import AzureOpenAI

client = AzureOpenAI(
    api_version="2024-02-01",
    api_key=os.environ.get("OPENAI_KEY"),
    azure_endpoint="https://your-deployment.openai.azure.com"
)
© www.soinside.com 2019 - 2024. All rights reserved.