pub struct OpenAIProvider { /* private fields */ }Expand description
OpenAI GPT API provider.
Supports GPT-4o, GPT-4, GPT-3.5, and other OpenAI models.
Also works with Azure OpenAI and compatible APIs.
Implementations§
Source§impl OpenAIProvider
impl OpenAIProvider
pub fn into_reference( val: OpenAIProvider, env: Env, ) -> Result<Reference<OpenAIProvider>>
pub fn into_instance(self, env: Env) -> Result<ClassInstance<OpenAIProvider>>
Source§impl OpenAIProvider
impl OpenAIProvider
Sourcepub fn new(api_key: String) -> Self
pub fn new(api_key: String) -> Self
Create a new OpenAI provider with API key.
§Arguments
api_key- YourOpenAIAPI key (starts with “sk-”)
Sourcepub fn with_base_url(api_key: String, base_url: String) -> Self
pub fn with_base_url(api_key: String, base_url: String) -> Self
Create a provider with custom base URL.
Useful for Azure OpenAI, LocalAI, or other compatible APIs.
Sourcepub fn with_org(api_key: String, org_id: String) -> Self
pub fn with_org(api_key: String, org_id: String) -> Self
Create a provider with organization ID.
Sourcepub async fn list_models(&self) -> Result<Vec<String>>
pub async fn list_models(&self) -> Result<Vec<String>>
List available models.
Returns an array of model IDs like “gpt-4o”, “gpt-4-turbo”.
Sourcepub async fn complete(
&self,
request: JsCompletionRequest,
) -> Result<JsCompletionResponse>
pub async fn complete( &self, request: JsCompletionRequest, ) -> Result<JsCompletionResponse>
Sourcepub fn complete_stream(
&self,
request: JsCompletionRequest,
callback: JsFunction,
) -> Result<()>
pub fn complete_stream( &self, request: JsCompletionRequest, callback: JsFunction, ) -> Result<()>
Create a streaming completion.
The callback is called for each chunk received. Chunks have:
chunk_type: “content_block_delta”, “message_stop”, etc.delta: Text content (for delta chunks)stop_reason: Why generation stopped (for final chunk)
§Arguments
request- The completion requestcallback- Function called with (error, chunk) for each chunk
Trait Implementations§
Source§impl FromNapiMutRef for OpenAIProvider
impl FromNapiMutRef for OpenAIProvider
Source§unsafe fn from_napi_mut_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static mut Self>
unsafe fn from_napi_mut_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static mut Self>
Safety Read more
Source§impl FromNapiRef for OpenAIProvider
impl FromNapiRef for OpenAIProvider
Source§unsafe fn from_napi_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static Self>
unsafe fn from_napi_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static Self>
Safety Read more
Source§impl FromNapiValue for &OpenAIProvider
impl FromNapiValue for &OpenAIProvider
Source§unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
Safety Read more
fn from_unknown(value: JsUnknown) -> Result<Self, Error>
Source§impl FromNapiValue for &mut OpenAIProvider
impl FromNapiValue for &mut OpenAIProvider
Source§unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
Safety Read more
fn from_unknown(value: JsUnknown) -> Result<Self, Error>
Source§impl ObjectFinalize for OpenAIProvider
impl ObjectFinalize for OpenAIProvider
Source§impl ToNapiValue for OpenAIProvider
impl ToNapiValue for OpenAIProvider
Source§unsafe fn to_napi_value(
env: napi_env,
val: OpenAIProvider,
) -> Result<napi_value>
unsafe fn to_napi_value( env: napi_env, val: OpenAIProvider, ) -> Result<napi_value>
Safety Read more
Source§impl TypeName for &OpenAIProvider
impl TypeName for &OpenAIProvider
Source§impl TypeName for &mut OpenAIProvider
impl TypeName for &mut OpenAIProvider
Source§impl TypeName for OpenAIProvider
impl TypeName for OpenAIProvider
Source§impl ValidateNapiValue for &OpenAIProvider
impl ValidateNapiValue for &OpenAIProvider
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
Source§impl ValidateNapiValue for &mut OpenAIProvider
impl ValidateNapiValue for &mut OpenAIProvider
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
Auto Trait Implementations§
impl Freeze for OpenAIProvider
impl !RefUnwindSafe for OpenAIProvider
impl Send for OpenAIProvider
impl Sync for OpenAIProvider
impl Unpin for OpenAIProvider
impl !UnwindSafe for OpenAIProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more