diff --git a/src/gucs/embedding.rs b/src/gucs/embedding.rs index 895425596..bdb600f38 100644 --- a/src/gucs/embedding.rs +++ b/src/gucs/embedding.rs @@ -1,11 +1,23 @@ -use super::guc_string_parse; use embedding::OpenAIOptions; use pgrx::guc::{GucContext, GucFlags, GucRegistry, GucSetting}; use std::ffi::CStr; pub fn openai_options() -> OpenAIOptions { - let base_url = guc_string_parse(&OPENAI_BASE_URL, "vectors.openai_base_url"); - let api_key = guc_string_parse(&OPENAI_API_KEY, "vectors.openai_api_key"); + use crate::error::*; + use pgrx::guc::GucSetting; + use std::ffi::CStr; + fn parse(target: &'static GucSetting>, name: &'static str) -> String { + let value = match target.get() { + Some(s) => s, + None => bad_guc_literal(name, "should not be `NULL`"), + }; + match value.to_str() { + Ok(s) => s.to_string(), + Err(_e) => bad_guc_literal(name, "should be a valid UTF-8 string"), + } + } + let base_url = parse(&OPENAI_BASE_URL, "vectors.openai_base_url"); + let api_key = parse(&OPENAI_API_KEY, "vectors.openai_api_key"); OpenAIOptions { base_url, api_key } } diff --git a/src/gucs/mod.rs b/src/gucs/mod.rs index a3dc64cf6..f43bed5b9 100644 --- a/src/gucs/mod.rs +++ b/src/gucs/mod.rs @@ -1,7 +1,3 @@ -use crate::error::*; -use pgrx::guc::GucSetting; -use std::ffi::CStr; - pub mod embedding; pub mod executing; pub mod internal; @@ -13,19 +9,9 @@ pub unsafe fn init() { internal::init(); executing::init(); embedding::init(); - } -} - -fn guc_string_parse( - target: &'static GucSetting>, - name: &'static str, -) -> String { - let value = match target.get() { - Some(s) => s, - None => bad_guc_literal(name, "should not be `NULL`"), - }; - match value.to_str() { - Ok(s) => s.to_string(), - Err(_e) => bad_guc_literal(name, "should be a valid UTF-8 string"), + #[cfg(feature = "pg14")] + pgrx::pg_sys::EmitWarningsOnPlaceholders(c"vectors".as_ptr()); + #[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))] + pgrx::pg_sys::MarkGUCPrefixReserved(c"vectors".as_ptr()); } }