File
OpenAI file support
# upload tuning file
filename := "tuning.json";
data := FileReader->ReadFile(filename)->ToByteArray();
API.OpenAI.File->Create(filename, "fine-tune", data, token)->PrintLine();
# list files
files := API.OpenAI.File->ListFiles(token);
if(files <> Nil) {
each(file in files) {
name := file->GetFilename();
id := file->GetId();
"file='{$name}', id='{$id}'"->PrintLine();
};
}
else {
API.OpenAI.File->GetLastError()->PrintLine();
};
# start tuning job
file := API.OpenAI.File->LoadOrCreate(filename, "fine-tune", token);
name := file->GetFilename();
id := file->GetId();
"file='{$name}', id='{$id}'"->PrintLine();
tuning_job := Tuner->Create("gpt-3.5-turbo", id, token);
model_id := tuning_job->GetId();
# query model
assistant := Assistant->Create(model_id, token);
if(assistant = Nil) {
Assistant->GetLastError()->PrintLine();
return;
};
assistant_id := assistant->GetId();
assistant_name := assistant->GetName();
assistant_model := assistant->GetModel();
"Created: id='{$id}', name='{$name}', model='{$model}', files={$file_count}, tools={$tool_count}"->PrintLine();
# chat with tuned assistant
session := API.OpenAI.Chat.Conversation->New(Assistant->Load(assistant_id, token), true, token);
session->AddFunction("get_coach_by_year", Callback(JsonElement) ~ JsonElement);
done := false;
do {
query := Console->ReadLine();
if(query->Equals("/quit")) {
session->Close();
done := true;
}
else {
response := session->Send(query, "user");
index := 0;
role := response->GetRole();
contents := response->GetContents();
each(content in contents) {
type := content->GetFirst()->As(String);
value := content->GetSecond()->As(String);
"{$index}: [{$role}, type='{$type}']: value='{$value}'"->PrintLine();
};
};
}
while(<>done);
session->Close();
Operations
- Create
- Delete
- GetBytes
- GetCreatedAt
- GetFilename
- GetId
- GetObject
- GetPurpose
- ListFiles
- Load
- LoadByName
- LoadOrCreate
- Retrieve
- ToString
Create
Upload a file that can be used across various endpoints
function : Create(name:String, content:Byte[], token:String) ~ Bool
Parameters
Name | Type | Description |
---|---|---|
name | String | file object name |
content | Byte | file content |
token | String | API token |
Return
Type | Description |
---|---|
Bool | string representation |
Create
Upload a file that can be used across various endpoints
function : Create(name:String, purpose:String, content:Byte[], token:String) ~ Bool
Parameters
Name | Type | Description |
---|---|---|
name | String | file object name |
purpose | String | file purpose 'assistants', 'vision' or 'fine-tune' |
content | Byte | file content |
token | String | API token |
Return
Type | Description |
---|---|
Bool | string representation |
Delete
Deletes a file
function : Delete(id:String, token:String) ~ Bool
Parameters
Name | Type | Description |
---|---|---|
id | String | file ID |
token | String | API token |
Return
Type | Description |
---|---|
Bool | true if successful, false otherwise |
GetBytes
Get the size of the file
method : public : GetBytes() ~ Int
Return
Type | Description |
---|---|
Int | size of the file |
GetCreatedAt
Unix timestamp (in seconds) of when the object instance was created
method : public : GetCreatedAt() ~ Int
Return
Type | Description |
---|---|
Int | time with the object instance was created |
GetFilename
Get the name of the file
method : public : GetFilename() ~ String
Return
Type | Description |
---|---|
String | name of the file |
GetId
Get object instance API ID
method : public : GetId() ~ String
Return
Type | Description |
---|---|
String | instance ID |
GetObject
Get the object type
method : public : GetObject() ~ String
Return
Type | Description |
---|---|
String | object type |
ListFiles
Loads a list available OpenAI files
function : ListFiles(token:String) ~ Vector<API.OpenAI.File>
Parameters
Name | Type | Description |
---|---|---|
token | String | API token |
Return
Type | Description |
---|---|
Vector<APIOpenAIFile> | file reference |
Load
Loads a file
function : Load(id:String, token:String) ~ API.OpenAI.File
Parameters
Name | Type | Description |
---|---|---|
id | String | file ID |
token | String | API token |
Return
Type | Description |
---|---|
API.OpenAI.File | file reference |
LoadByName
Loads an OpenAI file from the local filesystem
function : LoadByName(filename:String, token:String) ~ API.OpenAI.File
Parameters
Name | Type | Description |
---|---|---|
filename | String | local file path |
token | String | API token |
Return
Type | Description |
---|---|
API.OpenAI.File | file reference |
LoadOrCreate
Loads or creates an OpenAI file from the local filesystem
function : LoadOrCreate(filename:String, token:String) ~ API.OpenAI.File
Parameters
Name | Type | Description |
---|---|---|
filename | String | local file path |
token | String | API token |
Return
Type | Description |
---|---|
API.OpenAI.File | file reference |
LoadOrCreate
Loads or creates an OpenAI file from the local filesystem
function : LoadOrCreate(filename:String, purpose:String, token:String) ~ API.OpenAI.File
Parameters
Name | Type | Description |
---|---|---|
filename | String | local file path |
purpose | String | file purpose 'assistants', 'vision' or 'fine-tune' |
token | String | API token |
Return
Type | Description |
---|---|
API.OpenAI.File | file reference |
Retrieve
Returns the contents of the specified file
function : Retrieve(id:String, token:String) ~ Byte[]
Parameters
Name | Type | Description |
---|---|---|
id | String | file ID |
token | String | API token |
Return
Type | Description |
---|---|
Byte | file content |
ToString
String representation of the object
method : public : ToString() ~ String
Return
Type | Description |
---|---|
String | string representation |