clients.openai.files #
Example: Uploading a File
import incubaid.herolib.clients.openai
mut client:= openai.get()! //will be the default client, key is in `AIKEY` on environment variable or `OPENROUTER_API_KEY`
// Assuming you have a file named 'mydata.jsonl' in the same directory
// For a real application, handle file paths dynamically
file_path := 'mydata.jsonl'
resp := client.files.upload_file(
file: file_path,
purpose: 'fine-tune' // or 'assistants', 'batch', 'vision'
)
if resp.id.len > 0 {
println('File uploaded successfully with ID: ${resp.id}')
} else {
eprintln('Failed to upload file.')
}
fn (OpenAIAlias) upload_file #
fn (mut f OpenAIAlias) upload_file(args FileUploadArgs) !File
upload file to client org, usually used for fine tuning
fn (OpenAIAlias) list_files #
fn (mut f OpenAIAlias) list_files() !Files
list all files in client org
fn (OpenAIAlias) delete_file #
fn (mut f OpenAIAlias) delete_file(file_id string) !DeleteResp
deletes a file
fn (OpenAIAlias) get_file #
fn (mut f OpenAIAlias) get_file(file_id string) !File
returns a single file metadata
fn (OpenAIAlias) get_file_content #
fn (mut f OpenAIAlias) get_file_content(file_id string) !string
returns the content of a specific file
enum FilePurpose #
enum FilePurpose {
assistants
vision
batch
fine_tuning
}
struct DeleteResp #
struct DeleteResp {
pub mut:
id string
object string
deleted bool
}
struct File #
struct File {
pub mut:
id string
object string
bytes int
created_at int
filename string
purpose string
}
struct FileUploadArgs #
@[params]
struct FileUploadArgs {
pub:
filepath string
purpose FilePurpose
}
struct Files #
struct Files {
pub mut:
data []File
}