Skip to content

Commit 5cd96f3

Browse files
committed
add more methods to chatgpt client
1 parent f86b7c7 commit 5cd96f3

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ $chatGptScrapingbeeClient = Ziming\LaravelScrapingBee\LaravelScrapingBeeChatGpt:
190190

191191
$response = $chatGptScrapingbeeClient
192192
->prompt('Explain why a career in web development is a bad choice')
193+
->webSearch()
194+
->countryCode('US')
195+
->addHtml()
193196
->get();
194197
```
195198
Look at the source code of `src/LaravelScrapingBeeChatGpt.php` for the other methods (link below).

src/LaravelScrapingBeeChatGpt.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,21 @@ final class LaravelScrapingBeeChatGpt
1616

1717
private readonly string $baseUrl;
1818
private readonly string $apiKey;
19-
private readonly int $timeout;
2019

2120
private array $params = [];
2221
private array $headers = [];
2322

24-
public static function make(#[\SensitiveParameter] ?string $apiKey = null, ?int $timeout = null): self
23+
public static function make(#[\SensitiveParameter] ?string $apiKey = null): self
2524
{
26-
return new self($apiKey, $timeout);
25+
return new self($apiKey);
2726
}
2827

29-
public function __construct(#[\SensitiveParameter] ?string $apiKey = null, ?int $timeout = null)
28+
public function __construct(#[\SensitiveParameter] ?string $apiKey = null)
3029
{
3130
// If somebody pass '' into the constructor, we should use '' as the api key
3231
// even if it doesn't make sense.
3332
// If $apiKey is null, then we use the 1 in the config file.
3433
$this->apiKey = $apiKey ?? config('scrapingbee.api_key');
35-
$this->timeout = $timeout ?? config('scrapingbee.timeout');
3634

3735
$this->baseUrl = config(
3836
'scrapingbee.chatgpt_base_url',
@@ -80,6 +78,27 @@ public function prompt(string $prompt): self
8078
return $this;
8179
}
8280

81+
public function addHtml(): self
82+
{
83+
$this->params['add_html'] = true;
84+
85+
return $this;
86+
}
87+
88+
public function countryCode(string $countryCode): self
89+
{
90+
$this->params['country_code'] = $countryCode;
91+
92+
return $this;
93+
}
94+
95+
public function webSearch(): self
96+
{
97+
$this->params['search'] = true;
98+
99+
return $this;
100+
}
101+
83102
/*
84103
* If the API hasn't caught up, and you need to support a new ScrapingBee parameter,
85104
* you can set it using this method.

0 commit comments

Comments
 (0)