import os
import requests
url = "https://api.openai.com/v1/fine_tuning/jobs"
headers = {
"Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}",
"Content-Type": "application/json"
}
data = {
"training_file": "file-1234567890",
"model": "gpt-3.5-turbo",
"hyperparameters": {"n_epochs": "2"}
}
response = requests.post(url, headers=headers, json=data)
if response.status_code != 200:
print(response.text)
else:
print(response.json())
import os
import httpx
url = "https://api.openai.com/v1/fine_tuning/jobs"
headers = {
"Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}",
"Content-Type": "application/json"
}
data = {
"training_file": "file-1234567890",
"model": "gpt-3.5-turbo",
"hyperparameters": {"n_epochs": "2"}
}
with httpx.Client() as client:
response = client.post(url, headers=headers, json=data)
if response.status_code != 200:
print(response.text)
else:
print(response.json())
const fetch = require('node-fetch');
const url = 'https://api.openai.com/v1/fine_tuning/jobs';
const headers = {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json'
};
const data = {
training_file: 'file-1234567890',
model: 'gpt-3.5-turbo',
hyperparameters: { n_epochs: '2' }
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
})
.then(res => {
if (!res.ok) {
return res.text().then(text => { throw new Error(text); });
}
return res.json();
})
.then(json => console.log(json))
.catch(err => console.error(err));
const axios = require('axios');
const url = 'https://api.openai.com/v1/fine_tuning/jobs';
const headers = {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json'
};
const data = {
training_file: 'file-1234567890',
model: 'gpt-3.5-turbo',
hyperparameters: { n_epochs: '2' }
};
axios.post(url, data, { headers })
.then(response => {
if (response.status !== 200) {
console.error(response.data);
} else {
console.log(response.data);
}
})
.catch(error => {
console.error(error.message);
});
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
url := "https://api.openai.com/v1/fine_tuning/jobs"
reqBody := map[string]interface{}{
"training_file": "file-1234567890",
"model": "gpt-3.5-turbo",
"hyperparameters": map[string]string{
"n_epochs": "2",
},
}
body, _ := json.Marshal(reqBody)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("OPENAI_API_KEY"))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
log.Fatalf("Request failed: %s", string(body))
}
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
<?php
$url = 'https://api.openai.com/v1/fine_tuning/jobs';
$headers = [
'Authorization: Bearer ' . getenv('OPENAI_API_KEY'),
'Content-Type: application/json'
];
$data = [
'training_file' => 'file-1234567890',
'model' => 'gpt-3.5-turbo',
'hyperparameters' => ['n_epochs' => '2']
];
$options = [
'http' => [
'header' => $headers,
'method' => 'POST',
'content' => json_encode($data),
'ignore_errors' => true
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($http_response_header[0] !== 'HTTP/1.1 200 OK') {
echo $response;
} else {
echo $response;
}
?>
require 'net/http'
require 'json'
require 'uri'
url = URI.parse('https://api.openai.com/v1/fine_tuning/jobs')
headers = {
'Authorization' => "Bearer #{ENV['OPENAI_API_KEY']}",
'Content-Type' => 'application/json'
}
data = {
training_file: 'file-1234567890',
model: 'gpt-3.5-turbo',
hyperparameters: { n_epochs: '2' }
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.request_uri, headers)
request.body = data.to_json
response = http.request(request)
if response.code != '200'
puts response.body
else
puts JSON.parse(response.body)
end
import Foundation
let url = URL(string: "https://api.openai.com/v1/fine_tuning/jobs")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: Any] = [
"training_file": "file-1234567890",
"model": "gpt-3.5-turbo",
"hyperparameters": ["n_epochs": "2"]
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print(error.localizedDescription)
return
}
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
print(String(data: data ?? Data(), encoding: .utf8) ?? "")
return
}
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
RunLoop.main.run()
use reqwest::blocking::Client;
use std::collections::HashMap;
use std::env;
fn main() {
let url = "https://api.openai.com/v1/fine_tuning/jobs";
let client = Client::new();
let api_key = env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY must be set");
let mut params = HashMap::new();
params.insert("training_file", "file-1234567890");
params.insert("model", "gpt-3.5-turbo");
let mut hyperparams = HashMap::new();
hyperparams.insert("n_epochs", "2");
params.insert("hyperparameters", hyperparams);
let response = client
.post(url)
.header("Authorization", format!("Bearer {}", api_key))
.header("Content-Type", "application/json")
.json(¶ms)
.send()
.expect("Failed to send request");
if !response.status().is_success() {
println!("{}", response.text().expect("Failed to read response"));
} else {
println!("{:?}", response.json::<serde_json::Value>().unwrap());
}
}
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var url = "https://api.openai.com/v1/fine_tuning/jobs";
var client = new HttpClient();
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
var requestBody = new Dictionary<string, object>
{
{ "training_file", "file-1234567890" },
{ "model", "gpt-3.5-turbo" },
{ "hyperparameters", new Dictionary<string, string> { { "n_epochs", "2" } } }
};
var content = new StringContent(JsonSerializer.Serialize(requestBody))
{
MediaType = "application/json"
};
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
var response = await client.PostAsync(url, content);
if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync();
Console.WriteLine(error);
}
else
{
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
}