Skip to content

Commit 26e60b9

Browse files
committed
Update ContentGenerationServiceRequest.php
1 parent 5ca583b commit 26e60b9

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

includes/Services/Ai/ContentGeneration/ContentGenerationServiceRequest.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@
1616
*/
1717
class ContentGenerationServiceRequest {
1818

19+
/**
20+
* Default production base URL
21+
*/
22+
const DEFAULT_PRODUCTION_BASE_URL = 'https://patterns.hiive.cloud';
23+
24+
/**
25+
* Default local base URL
26+
*/
27+
const DEFAULT_LOCAL_BASE_URL = 'http://localhost:8888';
28+
1929
/**
2030
* API URL
2131
*
2232
* @var string
2333
*/
24-
private $url = 'https://patterns.hiive.cloud/api/v1/content-generation/';
34+
private $url;
2535

2636
/**
2737
* API endpoint
@@ -54,12 +64,14 @@ class ContentGenerationServiceRequest {
5464
/**
5565
* Constructor
5666
*
57-
* @param array $body Request body data.
58-
* @param array $headers Additional headers to include in the request.
67+
* @param string $endpoint API endpoint.
68+
* @param array $body Request body data.
69+
* @param array $headers Additional headers to include in the request.
5970
*/
6071
public function __construct( string $endpoint, array $body, array $headers = array() ) {
6172
$this->endpoint = $endpoint;
6273
$this->body = $body;
74+
$this->url = $this->get_api_url();
6375
$this->headers = array_merge(
6476
array(
6577
'Content-Type' => 'application/json',
@@ -70,6 +82,23 @@ public function __construct( string $endpoint, array $body, array $headers = arr
7082

7183
}
7284

85+
/**
86+
* Get the API URL based on configuration
87+
*
88+
* @return string The API URL to use.
89+
*/
90+
private function get_api_url(): string {
91+
$base_url = '';
92+
93+
if ( defined( 'NFD_WB_DEV_MODE' ) && NFD_WB_DEV_MODE ) {
94+
$base_url = defined( 'NFD_WB_LOCAL_BASE_URL' ) ? NFD_WB_LOCAL_BASE_URL : self::DEFAULT_LOCAL_BASE_URL;
95+
} else {
96+
$base_url = defined( 'NFD_WB_PRODUCTION_BASE_URL' ) ? NFD_WB_PRODUCTION_BASE_URL : self::DEFAULT_PRODUCTION_BASE_URL;
97+
}
98+
99+
return $base_url . '/api/v1/content-generation/';
100+
}
101+
73102
/**
74103
* Send the HTTP request
75104
*

0 commit comments

Comments
 (0)