@@ -24,7 +24,7 @@ class Replicate
2424
2525 private array $ inputParams = [];
2626
27- private string $ baseUrl = '' ;
27+ private string $ baseUrl = 'https://api.replicate.com/v1/predictions ' ;
2828
2929 private string $ token = '' ;
3030
@@ -140,6 +140,55 @@ public static function get(string $replicateId)
140140 return $ result ;
141141 }
142142
143+ public function list ()
144+ {
145+ $ response = self ::make ()
146+ ->client ()
147+ ->get ($ this ->getBaseUrl ());
148+
149+ if ($ response ->getStatusCode () !== 200 ) {
150+ throw new Exception ('Failed to retrieve data. ' );
151+ }
152+
153+ return json_decode ((string ) $ response ->getBody (), true );
154+ }
155+
156+ public function getModel ($ model_owner , $ model_name )
157+ {
158+ if (empty ($ model_name ) || empty ($ model_owner )) {
159+ throw new Exception ("model_owner or model_name can't be empty. " );
160+ }
161+ $ uri = 'https://api.replicate.com/v1/models/ ' . trim ($ model_owner ) . '/ ' . trim ($ model_name );
162+
163+ $ response = self ::make ()
164+ ->client ()
165+ ->get ($ uri );
166+
167+ if ($ response ->getStatusCode () !== 200 ) {
168+ throw new Exception ('Failed to retrieve data. ' );
169+ }
170+
171+ return json_decode ((string ) $ response ->getBody (), true );
172+ }
173+
174+ public function getModelVersion ($ model_owner , $ model_name , $ version_id )
175+ {
176+ if (empty ($ model_name ) || empty ($ model_owner ) || empty ($ version_id )) {
177+ throw new Exception ("model_owner、version_id or model_name can't be empty. " );
178+ }
179+ $ uri = 'https://api.replicate.com/v1/models/ ' . trim ($ model_owner ) . '/ ' . trim ($ model_name ) . '/versions/ ' . $ version_id ;
180+
181+ $ response = self ::make ()
182+ ->client ()
183+ ->get ($ uri );
184+
185+ if ($ response ->getStatusCode () !== 200 ) {
186+ throw new Exception ('Failed to retrieve data. ' );
187+ }
188+
189+ return json_decode ((string ) $ response ->getBody (), true );
190+ }
191+
143192 public function withPrompt (Prompt $ prompt )
144193 {
145194 $ this ->prompt = $ prompt ;
@@ -241,7 +290,7 @@ public function generate()
241290 StableDiffusionResult::create ($ data );
242291 } catch (Exception $ exception ) {
243292 $ msg = $ exception ->getMessage ();
244- var_dump (['data insert error ' => $ msg ]);
293+ // var_dump(['data insert error' => $msg]);
245294 if ($ exception instanceof PDOException) {
246295 $ errorInfo = $ exception ->errorInfo ;
247296 $ code = $ errorInfo [1 ];
@@ -260,7 +309,7 @@ private function client(): ClientInterface
260309 {
261310 return ApplicationContext::getContainer ()->get (ClientFactory::class)->create ([
262311 // 'base_uri' => $this->getBaseUrl(),
263- // 'timeout' => 10 ,
312+ 'timeout ' => 600 ,
264313 'headers ' => [
265314 'Authorization ' => 'Token ' . $ this ->getToken (),
266315 'Accept ' => 'application/json ' ,
0 commit comments