Skip to content

Commit

Permalink
Merge pull request #78 from aschet/cmake_improvements
Browse files Browse the repository at this point in the history
CMake improvements
  • Loading branch information
D7EAD authored Sep 27, 2024
2 parents 7db6c85 + b3fd7df commit fc072e2
Show file tree
Hide file tree
Showing 39 changed files with 748 additions and 214 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.vs
build
out
TestApp
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.13)

project(liboai)

option(BUILD_EXAMPLES "Build example applications" OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

add_subdirectory(liboai)

if(BUILD_EXAMPLES)
add_subdirectory(documentation)
endif()

set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT oai)
27 changes: 27 additions & 0 deletions documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.13)

project(documentation)

macro(add_example target_name source_name)
add_executable(${target_name} "${source_name}")
target_link_libraries(${target_name} oai)
set_target_properties(${target_name} PROPERTIES FOLDER "examples/${PROJECT_NAME}")
endmacro()

macro(add_basic_example source_base_name)
add_example(${source_base_name} "${source_base_name}.cpp")
endmacro()

add_subdirectory(audio/examples)
add_subdirectory(authorization/examples)
add_subdirectory(azure/examples)
add_subdirectory(chat/examples)
add_subdirectory(chat/conversation/examples)
add_subdirectory(completions/examples)
add_subdirectory(edits/examples)
add_subdirectory(embeddings/examples)
add_subdirectory(files/examples)
add_subdirectory(fine-tunes/examples)
add_subdirectory(images/examples)
add_subdirectory(models/examples)
add_subdirectory(moderations/examples)
10 changes: 10 additions & 0 deletions documentation/audio/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.13)

project(audio)

add_basic_example(create_speech)
add_basic_example(create_speech_async)
add_basic_example(create_transcription)
add_basic_example(create_transcription_async)
add_basic_example(create_translation)
add_basic_example(create_translation_async)
15 changes: 15 additions & 0 deletions documentation/authorization/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.13)

project(authorization)

add_basic_example(set_azure_key)
add_basic_example(set_azure_key_env)
add_basic_example(set_azure_key_file)
add_basic_example(set_key)
add_basic_example(set_key_env_var)
add_basic_example(set_key_file)
add_basic_example(set_organization)
add_basic_example(set_organization_env_var)
add_basic_example(set_organization_file)
add_basic_example(set_proxies)
add_basic_example(set_proxy_auth)
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_azure_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetAzureKey("hard-coded-key")) { // NOT recommended
...
// ...
}
}
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_azure_key_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetAzureKeyEnv("AZURE_API_KEY")) {
...
// ...
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetAzureKeyFile("C:/some/folder/key.dat")) {
...
// ...
}
}
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetKey("hard-coded-key")) { // NOT recommended
...
// ...
}
}
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_key_env_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetKeyEnv("OPENAI_API_KEY")) {
...
// ...
}
}
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_key_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetKeyFile("C:/some/folder/key.dat")) {
...
// ...
}
}
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_organization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetKeyEnv("OPENAI_API_KEY") && oai.auth.SetOrganization("org-123")) {
...
// ...
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetKeyEnv("OPENAI_API_KEY") && oai.auth.SetOrganizationEnv("OPENAI_ORG_ID")) {
...
// ...
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace liboai;
int main() {
OpenAI oai;
if (oai.auth.SetKeyEnv("OPENAI_API_KEY") && oai.auth.SetOrganizationFile("C:/some/folder/org.dat")) {
...
// ...
}
}
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_proxies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ int main() {
});

if (oai.auth.SetKeyEnv("OPENAI_API_KEY")) {
...
// ...
}
}
2 changes: 1 addition & 1 deletion documentation/authorization/examples/set_proxy_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ int main() {
});

if (oai.auth.SetKeyEnv("OPENAI_API_KEY")) {
...
// ...
}
}
16 changes: 16 additions & 0 deletions documentation/azure/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.13)

project(azure)

add_example(create_chat_completion_azure "create_chat_completion.cpp")
add_example(create_chat_completion_async_azure "create_chat_completion_async.cpp")
add_basic_example(create_completion)
add_basic_example(create_completion_async)
add_example(create_embedding_azure "create_embedding.cpp")
add_example(create_embedding_async_azure "create_embedding_async.cpp")
add_basic_example(delete_generated_image)
add_basic_example(delete_generated_image_async)
add_basic_example(get_generated_image)
add_basic_example(get_generated_image_async)
add_basic_example(request_image_generation)
add_basic_example(request_image_generation_async)
13 changes: 13 additions & 0 deletions documentation/chat/conversation/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.13)

project(conversation)

add_basic_example(adduserdata)
add_basic_example(getjsonobject)
add_basic_example(getlastresponse)
add_basic_example(getrawconversation)
add_basic_example(poplastresponse)
add_basic_example(popsystemdata)
add_basic_example(popuserdata)
add_basic_example(setsystemdata)
add_basic_example(update)
2 changes: 1 addition & 1 deletion documentation/chat/conversation/examples/adduserdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ int main() {
// add user data - such as a question
convo.AddUserData("What is the meaning of life?");

...
// ...
}
2 changes: 1 addition & 1 deletion documentation/chat/conversation/examples/popsystemdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ int main() {
// add a different system message
convo.SetSystemData("You are a helpful bot that enjoys business.");

...
// ...
}
2 changes: 1 addition & 1 deletion documentation/chat/conversation/examples/popuserdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ int main() {
// add different user data
convo.AddUserData("What is the size of the universe?");

...
// ...
}
2 changes: 1 addition & 1 deletion documentation/chat/conversation/examples/setsystemdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ int main() {
// set system message to guide the chat model
convo.SetSystemData("You are helpful bot.");

...
// ...
}
7 changes: 7 additions & 0 deletions documentation/chat/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.13)

project(chat)

add_basic_example(create_chat_completion)
add_basic_example(create_chat_completion_async)
add_basic_example(ongoing_user_convo)
6 changes: 6 additions & 0 deletions documentation/completions/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13)

project(completions)

add_basic_example(generate_completion)
add_basic_example(generate_completion_async)
6 changes: 6 additions & 0 deletions documentation/edits/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13)

project(edits)

add_basic_example(create_edit)
add_basic_example(create_edit_async)
6 changes: 6 additions & 0 deletions documentation/embeddings/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13)

project(embeddings)

add_basic_example(create_embedding)
add_basic_example(create_embedding_async)
14 changes: 14 additions & 0 deletions documentation/files/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.13)

project(files)

add_basic_example(delete_file)
add_basic_example(delete_file_async)
add_basic_example(download_uploaded_file)
add_basic_example(download_uploaded_file_async)
add_basic_example(list_files)
add_basic_example(list_files_async)
add_basic_example(retrieve_file)
add_basic_example(retrieve_file_async)
add_basic_example(upload_file)
add_basic_example(upload_file_async)
16 changes: 16 additions & 0 deletions documentation/fine-tunes/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.13)

project(fine-tunes)

add_basic_example(cancel_fine_tune)
add_basic_example(cancel_fine_tune_async)
add_basic_example(create_fine_tune)
add_basic_example(create_fine_tune_async)
add_basic_example(delete_fine_tune_model)
add_basic_example(delete_fine_tune_model_async)
add_basic_example(list_fine_tune_events)
add_basic_example(list_fine_tune_events_async)
add_basic_example(list_fine_tunes)
add_basic_example(list_fine_tunes_async)
add_basic_example(retrieve_fine_tune)
add_basic_example(retrieve_fine_tune_async)
12 changes: 12 additions & 0 deletions documentation/images/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.13)

project(images)

# compilation error
#add_basic_example(download_generated_image)
add_basic_example(generate_edit)
add_basic_example(generate_edit_async)
add_basic_example(generate_image)
add_basic_example(generate_image_async)
add_basic_example(generate_variation)
add_basic_example(generate_variation_async)
8 changes: 8 additions & 0 deletions documentation/models/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.13)

project(models)

add_basic_example(list_models)
add_basic_example(list_models_async)
add_basic_example(retrieve_model)
add_basic_example(retrieve_model_async)
6 changes: 6 additions & 0 deletions documentation/moderations/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13)

project(moderations)

add_basic_example(create_moderation)
add_basic_example(create_moderation_async)
Loading

0 comments on commit fc072e2

Please sign in to comment.