Skip to content

Commit

Permalink
ENV support
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani committed Dec 29, 2024
1 parent 01835de commit b86b137
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ CREATE SECRET IF NOT EXISTS open_prompt (
);
```

Alternatively the following ENV variables can be used at runtime
```
OPEN_PROMPT_API_URL
OPEN_PROMPT_API_TOKEN
OPEN_PROMPT_MODEL_NAME
OPEN_PROMPT_API_TIMEOUT
```


### Usage
```sql
D SELECT open_prompt('Write a one-line poem about ducks') AS response;
Expand Down
14 changes: 13 additions & 1 deletion src/open_prompt_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "httplib.hpp"

#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <string>
#include <sstream>
#include <mutex>
Expand Down Expand Up @@ -148,7 +151,16 @@ namespace duckdb {

// Settings management
static std::string GetConfigValue(ClientContext &context, const string &var_name, const string &default_value) {
// First try to get from secrets

// Try environment variables
std::string env_var_name = "OPEN_PROMPT_" + var_name;
std::transform(env_var_name.begin(), env_var_name.end(), env_var_name.begin(), ::toupper);
const char* env_value = std::getenv(env_var_name.c_str());
if (env_value != nullptr && strlen(env_value) > 0) {
return std::string(env_value);
}

// Try to get from secrets
auto &secret_manager = SecretManager::Get(context);
try {
auto transaction = CatalogTransaction::GetSystemCatalogTransaction(context);
Expand Down

0 comments on commit b86b137

Please sign in to comment.