clients.openai #
openai
To get started
import freeflowuniverse.herolib.clients. openai
mut client:= openai.get()!
client...
example heroscript
!!openai.configure
secret: '...'
host: 'localhost'
port: 8888
Constants #
const version = '1.14.3'
fn get #
fn get(args_ ArgsGet) !&OpenAI
fn heroscript_default #
fn heroscript_default() !string
Todo: THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE TO STRUCT BELOW, IS STRUCTURED AS HEROSCRIPT
fn play #
fn play(args_ PlayArgs) !
fn switch #
fn switch(name string)
switch instance to be used for openai
enum AudioFormat #
enum AudioFormat {
mp3
opus
aac
flac
wav
pcm
}
enum AudioRespType #
enum AudioRespType {
json
text
srt
verbose_json
vtt
}
enum EmbeddingModel #
enum EmbeddingModel {
text_embedding_ada
}
enum FilePurpose #
enum FilePurpose {
assistants
vision
batch
fine_tuning
}
enum ImageRespType #
enum ImageRespType {
url
b64_json
}
enum ImageSize #
enum ImageSize {
size_256_256
size_512_512
size_1024_1024
}
enum ModelType #
enum ModelType {
gpt_4o_2024_08_06
gpt_3_5_turbo
gpt_4
gpt_4_0613
gpt_4_32k
gpt_4_32k_0613
gpt_3_5_turbo_0613
gpt_3_5_turbo_16k
gpt_3_5_turbo_16k_0613
whisper_1
tts_1
}
enum ModerationModel #
enum ModerationModel {
text_moderation_latest
text_moderation_stable
}
enum RoleType #
enum RoleType {
system
user
assistant
function
}
enum Voice #
enum Voice {
alloy
ash
coral
echo
fable
onyx
nova
sage
shimmer
}
struct ArgsGet #
struct ArgsGet {
pub mut:
name string = 'default'
}
///////FACTORY
struct AudioArgs #
struct AudioArgs {
pub mut:
filepath string
prompt string
response_format AudioRespType
temperature int
language string
}
struct AudioResponse #
struct AudioResponse {
pub mut:
text string
}
struct ChatCompletion #
struct ChatCompletion {
pub mut:
id string
object string
created u32
choices []Choice
usage Usage
}
struct Choice #
struct Choice {
pub mut:
index int
message MessageRaw
finish_reason string
}
struct CreateSpeechArgs #
struct CreateSpeechArgs {
pub:
model ModelType = .tts_1
input string @[required]
voice Voice = .alloy
response_format AudioFormat = .mp3
speed f32 = 1.0
output_path string @[required]
}
struct CreateSpeechRequest #
struct CreateSpeechRequest {
pub:
model string
input string
voice string
response_format string
speed f32
}
struct DeleteResp #
struct DeleteResp {
pub mut:
id string
object string
deleted bool
}
struct Embedding #
struct Embedding {
pub mut:
object string
embedding []f32
index int
}
struct EmbeddingCreateArgs #
struct EmbeddingCreateArgs {
input []string @[required]
model EmbeddingModel @[required]
user string
}
struct EmbeddingCreateRequest #
struct EmbeddingCreateRequest {
input []string
model string
user string
}
struct EmbeddingResponse #
struct EmbeddingResponse {
pub mut:
object string
data []Embedding
model string
usage Usage
}
struct File #
struct File {
pub mut:
id string
object string
bytes int
created_at int
filename string
purpose string
}
struct FileUploadArgs #
struct FileUploadArgs {
pub:
filepath string
purpose FilePurpose
}
struct Files #
struct Files {
pub mut:
data []File
}
struct FineTune #
struct FineTune {
pub:
id string
object string
model string
created_at int
events []FineTuneEvent
fine_tuned_model string
hyperparams FineTuneHyperParams
organization_id string
result_files []File
status string
validation_files []File
training_files []File
updated_at int
}
struct FineTuneCreateArgs #
struct FineTuneCreateArgs {
pub mut:
training_file string @[required]
model string
n_epochs int = 4
batch_size int
learning_rate_multiplier f32
prompt_loss_weight f64
compute_classification_metrics bool
suffix string
}
struct FineTuneEvent #
struct FineTuneEvent {
pub:
object string
created_at int
level string
message string
}
struct FineTuneEventList #
struct FineTuneEventList {
pub:
object string
data []FineTuneEvent
}
struct FineTuneHyperParams #
struct FineTuneHyperParams {
pub:
batch_size int
learning_rate_multiplier f64
n_epochs int
prompt_loss_weight f64
}
struct FineTuneList #
struct FineTuneList {
pub:
object string
data []FineTune
}
struct ImageCreateArgs #
struct ImageCreateArgs {
pub mut:
prompt string
num_images int
size ImageSize
format ImageRespType
user string
}
struct ImageEditArgs #
struct ImageEditArgs {
pub mut:
image_path string
mask_path string
prompt string
num_images int
size ImageSize
format ImageRespType
user string
}
struct ImageRequest #
struct ImageRequest {
pub mut:
prompt string
n int
size string
response_format string
user string
}
struct ImageResponse #
struct ImageResponse {
pub mut:
url string
b64_json string
}
struct ImageVariationArgs #
struct ImageVariationArgs {
pub mut:
image_path string
num_images int
size ImageSize
format ImageRespType
user string
}
struct Images #
struct Images {
pub mut:
created int
data []ImageResponse
}
struct Message #
struct Message {
pub mut:
role RoleType
content string
}
struct MessageRaw #
struct MessageRaw {
pub mut:
role string
content string
}
struct Messages #
struct Messages {
pub mut:
messages []Message
}
struct Model #
struct Model {
pub mut:
id string
created int
object string
owned_by string
root string
parent string
permission []ModelPermission
}
struct ModelPermission #
struct ModelPermission {
pub mut:
id string
created int
object string
allow_create_engine bool
allow_sampling bool
allow_logprobs bool
allow_search_indices bool
allow_view bool
allow_fine_tuning bool
organization string
is_blocking bool
}
struct Models #
struct Models {
pub mut:
data []Model
}
struct ModerationRequest #
struct ModerationRequest {
mut:
input string
model string
}
struct ModerationResponse #
struct ModerationResponse {
pub mut:
id string
model string
results []ModerationResult
}
struct ModerationResult #
struct ModerationResult {
pub mut:
categories ModerationResultCategories
category_scores ModerationResultCategoryScores
flagged bool
}
struct ModerationResultCategories #
struct ModerationResultCategories {
pub mut:
sexual bool
hate bool
harassment bool
selfharm bool @[json: 'self-harm']
sexual_minors bool @[json: 'sexual/minors']
hate_threatening bool @[json: 'hate/threatening']
violence_graphic bool @[json: 'violence/graphic']
selfharm_intent bool @[json: 'self-harm/intent']
selfharm_instructions bool @[json: 'self-harm/instructions']
harassment_threatening bool @[json: 'harassment/threatening']
violence bool
}
struct ModerationResultCategoryScores #
struct ModerationResultCategoryScores {
pub mut:
sexual f32
hate f32
harassment f32
selfharm f32 @[json: 'self-harm']
sexual_minors f32 @[json: 'sexual/minors']
hate_threatening f32 @[json: 'hate/threatening']
violence_graphic f32 @[json: 'violence/graphic']
selfharm_intent f32 @[json: 'self-harm/intent']
selfharm_instructions f32 @[json: 'self-harm/instructions']
harassment_threatening f32 @[json: 'harassment/threatening']
violence f32
}
struct OpenAI #
struct OpenAI {
pub mut:
name string = 'default'
api_key string @[secret]
conn ?&httpconnection.HTTPConnection
}
THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
fn (OpenAI) cancel_fine_tune #
fn (mut f OpenAI) cancel_fine_tune(fine_tune string) !FineTune
cancel a fine-tune that didn't finish yet
fn (OpenAI) chat_completion #
fn (mut f OpenAI) chat_completion(model_type ModelType, msgs Messages) !ChatCompletion
creates a new chat completion given a list of messages each message consists of message content and the role of the author
fn (OpenAI) connection #
fn (mut client OpenAI) connection() !&httpconnection.HTTPConnection
fn (OpenAI) create_edit_image #
fn (mut f OpenAI) create_edit_image(args ImageEditArgs) !Images
edit images generation given a prompt and an existing image image needs to be in PNG format and transparent or else a mask of the same size needs to be specified to indicate where the image should be in the generated image the amount of images returned is specified by num_images
fn (OpenAI) create_embeddings #
fn (mut f OpenAI) create_embeddings(args EmbeddingCreateArgs) !EmbeddingResponse
fn (OpenAI) create_fine_tune #
fn (mut f OpenAI) create_fine_tune(args FineTuneCreateArgs) !FineTune
creates a new fine-tune based on an already uploaded file
fn (OpenAI) create_image #
fn (mut f OpenAI) create_image(args ImageCreateArgs) !Images
Create new images generation given a prompt the amount of images returned is specified by num_images
fn (OpenAI) create_moderation #
fn (mut f OpenAI) create_moderation(input string, model ModerationModel) !ModerationResponse
fn (OpenAI) create_speech #
fn (mut f OpenAI) create_speech(args CreateSpeechArgs) !
fn (OpenAI) create_tranlation #
fn (mut f OpenAI) create_tranlation(args AudioArgs) !AudioResponse
create translation to english from an audio file supported audio formats are mp3, mp4, mpeg, mpga, m4a, wav, or webm
fn (OpenAI) create_transcription #
fn (mut f OpenAI) create_transcription(args AudioArgs) !AudioResponse
create transcription from an audio file supported audio formats are mp3, mp4, mpeg, mpga, m4a, wav, or webm
fn (OpenAI) create_variation_image #
fn (mut f OpenAI) create_variation_image(args ImageVariationArgs) !Images
create variations of the given image image needs to be in PNG format the amount of images returned is specified by num_images
fn (OpenAI) delete_file #
fn (mut f OpenAI) delete_file(file_id string) !DeleteResp
deletes a file
fn (OpenAI) get_file #
fn (mut f OpenAI) get_file(file_id string) !File
returns a single file metadata
fn (OpenAI) get_file_content #
fn (mut f OpenAI) get_file_content(file_id string) !string
returns the content of a specific file
fn (OpenAI) get_fine_tune #
fn (mut f OpenAI) get_fine_tune(fine_tune string) !FineTune
get a single fine-tune information
fn (OpenAI) get_model #
fn (mut f OpenAI) get_model(model string) !Model
returns details of a model using the model id
fn (OpenAI) list_files #
fn (mut f OpenAI) list_files() !Files
list all files in client org
fn (OpenAI) list_fine_tune_events #
fn (mut f OpenAI) list_fine_tune_events(fine_tune string) !FineTuneEventList
returns all events for a fine tune in this account
fn (OpenAI) list_fine_tunes #
fn (mut f OpenAI) list_fine_tunes() !FineTuneList
returns all fine-tunes in this account
fn (OpenAI) list_models #
fn (mut f OpenAI) list_models() !Models
list current models available in Open AI
fn (OpenAI) upload_file #
fn (mut f OpenAI) upload_file(args FileUploadArgs) !File
upload file to client org, usually used for fine tuning
struct PlayArgs #
struct PlayArgs {
pub mut:
name string = 'default'
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
start bool
stop bool
restart bool
delete bool
configure bool // make sure there is at least one installed
}
struct Usage #
struct Usage {
pub mut:
prompt_tokens int
completion_tokens int
total_tokens int
}
- README
- Constants
- fn get
- fn heroscript_default
- fn play
- fn switch
- enum AudioFormat
- enum AudioRespType
- enum EmbeddingModel
- enum FilePurpose
- enum ImageRespType
- enum ImageSize
- enum ModelType
- enum ModerationModel
- enum RoleType
- enum Voice
- struct ArgsGet
- struct AudioArgs
- struct AudioResponse
- struct ChatCompletion
- struct Choice
- struct CreateSpeechArgs
- struct CreateSpeechRequest
- struct DeleteResp
- struct Embedding
- struct EmbeddingCreateArgs
- struct EmbeddingCreateRequest
- struct EmbeddingResponse
- struct File
- struct FileUploadArgs
- struct Files
- struct FineTune
- struct FineTuneCreateArgs
- struct FineTuneEvent
- struct FineTuneEventList
- struct FineTuneHyperParams
- struct FineTuneList
- struct ImageCreateArgs
- struct ImageEditArgs
- struct ImageRequest
- struct ImageResponse
- struct ImageVariationArgs
- struct Images
- struct Message
- struct MessageRaw
- struct Messages
- struct Model
- struct ModelPermission
- struct Models
- struct ModerationRequest
- struct ModerationResponse
- struct ModerationResult
- struct ModerationResultCategories
- struct ModerationResultCategoryScores
- struct OpenAI
- fn cancel_fine_tune
- fn chat_completion
- fn connection
- fn create_edit_image
- fn create_embeddings
- fn create_fine_tune
- fn create_image
- fn create_moderation
- fn create_speech
- fn create_tranlation
- fn create_transcription
- fn create_variation_image
- fn delete_file
- fn get_file
- fn get_file_content
- fn get_fine_tune
- fn get_model
- fn list_files
- fn list_fine_tune_events
- fn list_fine_tunes
- fn list_models
- fn upload_file
- struct PlayArgs
- struct Usage