Skip to content

Commit 84dd68b

Browse files
authored
Merge pull request #30 from Copyleaks/disconnect-ai-source-code-detection
disconnect ai code detection
2 parents 6f3e93d + d79e2bb commit 84dd68b

File tree

12 files changed

+291
-180
lines changed

12 files changed

+291
-180
lines changed

README.md

Lines changed: 200 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,218 @@
1-
# Copyleaks PHP SDK
1+
# Copyleaks SDK
2+
The official [Copyleaks](https://copyleaks.com/) PHP library, supporting PHP versions >=7.4.0.
23

3-
Copyleaks SDK is a simple framework that allows you to scan text for plagiarism and detect content distribution online, using the Copyleaks plagiarism checker cloud.
4+
## 🚀 Getting Started
5+
Before you start, ensure you have the following:
46

5-
Using Copyleaks SDK you can check for plagiarism in:
6-
* Online content and webpages
7-
* Local and cloud files (see [supported files](https://api.copyleaks.com/documentation/specifications#2-supported-file-types))
8-
* Free text
9-
* OCR (Optical Character Recognition) - scanning pictures with textual content (see [supported files](https://api.copyleaks.com/documentation/specifications#6-supported-image-types-ocr))
7+
* An active Copyleaks account. If you don’t have one, [sign up for free](https://copyleaks.com/signup).
8+
* You can find your API key on the [API Dashboard](https://api.copyleaks.com/dashboard).
109

11-
## Installation
10+
Once you have your account and API key:
1211

13-
Install using [Packagist](https://packagist.org/packages/copyleaks/php-plagiarism-checker)
12+
**Install the SDK**:
1413

14+
Install using [Packagist](https://packagist.org/packages/copyleaks/php-plagiarism-checker)
1515
```bash
1616
composer require copyleaks/php-plagiarism-checker
1717
```
1818

19-
## Register and Get Your API Key
20-
To use the Copyleaks API you need to first be a registered user. The registration to Copyleaks takes a minute and is free of charge. [Signup](https://api.copyleaks.com/?register=true) and make sure to confirm your account.
19+
## 📚 Documentation
20+
To learn more about how to use Copyleaks API please check out our [Documentation](https://docs.copyleaks.com/resources/sdks/php/).
21+
22+
## 💡 Usage Examples
23+
Here are some common usage examples for the Copyleaks SDK. You can also see a comprehensive code example in the `demo.php` file on our GitHub repository: [demo.php](https://github.com/Copyleaks/PHP-Plagiarism-Checker/blob/master/demo/demo.php).
24+
25+
### Get Authentication Token
26+
This example demonstrates how to log in to the Copyleaks API and obtain an authentication token.
27+
28+
```php
29+
<?php
30+
31+
require_once(__DIR__ . '/vendor/autoload.php');
2132

22-
As a signed user you can generate your personal API key. Do so on your [dashboard home](https://api.copyleaks.com/dashboard) under 'API Access Credentials'.
33+
use Copyleaks\Copyleaks;
34+
use Copyleaks\CopyleaksFileSubmissionModel;
35+
use Copyleaks\SubmissionProperties;
36+
use Copyleaks\SubmissionWebhooks;
2337

24-
For more information check out our [API guide](https://api.copyleaks.com/documentation/v3).
38+
// --- Your Credentials ---
39+
$EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
40+
$KEY = 'YOUR_API_KEY';
41+
$WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
42+
// --------------------
43+
44+
// Log in to the Copyleaks API
45+
echo "Authenticating...\n";
46+
$copyleaks = new Copyleaks();
47+
$loginToken = $copyleaks->login($EMAIL_ADDRESS, $KEY);
48+
echo "✅ Logged in successfully!\n";
49+
50+
```
51+
For a detailed understanding of the authentication process, refer to the Copyleaks Login Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/account/login).
52+
##
53+
### Submit Text for Plagiarism Scan
54+
This example shows how to prepare and submit raw text content for a plagiarism scan.
2555

26-
## Usage
2756
```php
28-
include_once('vendor/copyleaks/php-plagiarism-checker/autoload.php');
29-
use Copyleaks\Copyleaks;
57+
<?php
58+
59+
require_once(__DIR__ . '/vendor/autoload.php');
60+
61+
use Copyleaks\Copyleaks;
62+
use Copyleaks\CopyleaksFileSubmissionModel;
63+
use Copyleaks\SubmissionProperties;
64+
use Copyleaks\SubmissionWebhooks;
65+
66+
// --- Your Credentials ---
67+
$EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
68+
$KEY = 'YOUR_API_KEY';
69+
$WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
70+
// --------------------
71+
72+
// Prepare your content for scanning
73+
echo "Submitting text for scanning...\n";
74+
$textToScan = "Hello world, this is a test.";
75+
$base64Content = base64_encode($textToScan);
76+
$scanId = time();
77+
78+
// Configure the scan
79+
$webhooks = new SubmissionWebhooks($WEBHOOK_URL);
80+
$properties = new SubmissionProperties($webhooks);
81+
$properties->setSandbox(true); // Turn on sandbox mode for testing
82+
83+
$submission = new CopyleaksFileSubmissionModel($base64Content, 'test.txt', $properties);
84+
85+
// Submit the scan to Copyleaks
86+
$copyleaks->submitFile($loginToken, $scanId, $submission);
87+
echo "🚀 Scan submitted successfully! Scan ID: " . $scanId . "\n";
88+
echo "You will be notified via your webhook when the scan is complete.\n";
89+
90+
```
91+
For a full guide please refer to our step by step [Guide](https://docs.copyleaks.com/guides/authenticity/detect-plagiarism-text)
92+
93+
For a detailed understanding of the plagiarism detection process, refer to the Copyleaks Submit Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/scans/submit-file)
94+
##
95+
### AI-Generated Text Detection
96+
Use the AI detection client to determine if content was generated by artificial intelligence.
97+
98+
```php
99+
<?php
100+
101+
require_once(__DIR__ . '/vendor/autoload.php');
102+
103+
use Copyleaks\Copyleaks;
104+
use Copyleaks\CopyleaksNaturalLanguageSubmissionModel;
105+
106+
// --- Your Credentials ---
107+
$EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
108+
$KEY = 'YOUR_API_KEY';
109+
$WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
110+
// --------------------
111+
112+
$sampleText = "Lions are social animals, living in groups called prides, typically consisting of several females, their offspring, and a few males. Female lions are the primary hunters, working together to catch prey. Lions are known for their strength, teamwork, and complex social structures.";
113+
114+
$submission = new CopyleaksNaturalLanguageSubmissionModel(
115+
$sampleText,
116+
);
117+
$submission->sandbox = true;
118+
119+
$response = $this->copyleaks->aiDetectionClient->submitNaturalLanguage($authToken, time(), $submission);
120+
$this->logInfo('AI Detection - submitNaturalLanguage', $response);
30121

31-
$copyleaks = new Copyleaks();
32-
$loginResult = $copyleaks->login(<your email>,<your api key>);
33-
echo json_encode($loginResult);
34122
```
35-
* (Option) To change the Identity server URI (default:"https://id.copyleaks.com"):
36-
```rb
37-
CopyleaksConfig::SET_IDENTITY_SERVER_URI("<your identity server URI>");
123+
124+
### Writing Assistant
125+
Get intelligent suggestions for improving grammar, spelling, style, and overall writing quality.
126+
127+
```php
128+
<?php
129+
130+
require_once(__DIR__ . '/vendor/autoload.php');
131+
132+
use Copyleaks\Copyleaks;
133+
use Copyleaks\CopyleaksWritingAssistantSubmissionModel;
134+
135+
// --- Your Credentials ---
136+
$EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
137+
$KEY = 'YOUR_API_KEY';
138+
$WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
139+
// --------------------
140+
141+
$sampleText = "Lions are the only cat that live in groups, called pride. A prides typically consists of a few adult males, several feales, and their offspring. This social structure is essential for hunting and raising young cubs. Female lions, or lionesses are the primary hunters of the prid. They work together in cordinated groups to take down prey usually targeting large herbiores like zbras, wildebeest and buffalo. Their teamwork and strategy during hunts highlight the intelligence and coperation that are key to their survival.";
142+
143+
$scoreWeights = new ScoreWeights(
144+
0.1, 0.2, 0.3, 0.4
145+
);
146+
147+
$submission = new CopyleaksWritingAssistantSubmissionModel(
148+
$sampleText,
149+
);
150+
151+
$submission->sandbox = true;
152+
$submission->score = $scoreWeights;
153+
154+
$response = $this->copyleaks->writingAssistantClient->submitText($authToken, time(), $submission);
155+
$this->logInfo('Writing Assistant - submitText', $response);
156+
38157
```
39-
* (Option) To change the API server URI (default:"https://api.copyleaks.com"):
40-
```rb
41-
CopyleaksConfig::SET_API_SERVER_URI("<your API server URI>");
158+
For a full guide please refer to our step by step [Guide](https://docs.copyleaks.com/guides/writing/check-grammar/)
159+
160+
For a detailed understanding of the Writing assistant process, refer to the Copyleaks writing feedback Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/writing-assistant/check/)
161+
##
162+
### Text Moderation
163+
Scan and moderate text content for unsafe, inappropriate, or policy-violating material across various categories.
164+
165+
```php
166+
<?php
167+
168+
require_once(__DIR__ . '/vendor/autoload.php');
169+
170+
use Copyleaks\Copyleaks;
171+
use Copyleaks\CopyleaksTextModerationRequestModel;
172+
173+
// --- Your Credentials ---
174+
$EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
175+
$KEY = 'YOUR_API_KEY';
176+
$WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
177+
// --------------------
178+
179+
var labelsArray = new CopyleaksTextModerationLabel[]
180+
{
181+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.ADULT_V1),
182+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.TOXIC_V1),
183+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.VIOLENT_V1),
184+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.PROFANITY_V1),
185+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.SELF_HARM_V1),
186+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.HARASSMENT_V1),
187+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.HATE_SPEECH_V1),
188+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.DRUGS_V1),
189+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.FIREARMS_V1),
190+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.CYBERSECURITY_V1)
191+
};
192+
193+
var model = new CopyleaksTextModerationRequestModel(
194+
text: "This is some text to scan.",
195+
sandbox: true,
196+
language: CopyleaksTextModerationLanguages.ENGLISH,
197+
labels: labelsArray
198+
);
199+
200+
$response = $this->copyleaks->textModerationClient->submitText($authToken, time(), $model);
201+
$textModerationResponse= CopyleaksTextModerationResponseModel::fromArray(json_decode(json_encode($response), true));
202+
203+
$this->logInfo('Text Moderation - submitText', $textModerationResponse);
204+
42205
```
206+
For a full guide please refer to our step by step [Guide](https://docs.copyleaks.com/guides/moderation/moderate-text/)
207+
208+
For a detailed understanding of the Text moderation process, refer to the Copyleaks text moderation Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/text-moderation/check/)
209+
##
210+
## Further Resources
211+
212+
* **Copyleaks API Dashboard:** Manage your API keys, monitor usage, and view analytics from your personalized dashboard. [Access Dashboard](https://api.copyleaks.com/dashboard)
213+
* **Copyleaks SDK Documentation:** Explore comprehensive guides, API references, and code examples for seamless integration. [Read Documentation](https://docs.copyleaks.com/resources/sdks/overview/)
214+
43215

44-
## Demo
45-
See [demo.php](./demo/demo.php) under demo folder for an example.
46-
## Read More
47-
* [API Homepage](https://api.copyleaks.com/)
48-
* [API Documentation](https://api.copyleaks.com/documentation)
49-
* [Plagiarism Report](https://github.com/Copyleaks/plagiarism-report)
216+
## Support
217+
* If you need assistance, please contact Copyleaks Support via our support portal: Contact Copyleaks [Support](https://help.copyleaks.com/s/contactsupport).
218+
* To arrange a product demonstration, book a demo here: [Booking Link](https://copyleaks.com/book-a-demo).

demo/demo.php

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Copyleaks\CopyleaksExportModel;
1010
use Copyleaks\CopyleaksFileOcrSubmissionModel;
1111
use Copyleaks\CopyleaksNaturalLanguageSubmissionModel;
12-
use Copyleaks\CopyleaksSourceCodeSubmissionModel;
1312
use Copyleaks\CopyleaksWritingAssistantSubmissionModel;
1413
use Copyleaks\ScoreWeights;
1514
use Copyleaks\CopyleaksFileSubmissionModel;
@@ -34,6 +33,10 @@
3433
use Copyleaks\SubmissionWebhooks;
3534
use Copyleaks\CopyleaksTextModerationRequestModel;
3635
use Copyleaks\CopyleaksTextModerationResponseModel;
36+
use Copyleaks\CopyleaksTextModerationLanguages;
37+
use Copyleaks\CopyleaksTextModerationConstants;
38+
use Copyleaks\CopyleaksTextModerationLabel;
39+
3740
use Throwable;
3841

3942
class Test {
@@ -74,11 +77,9 @@ public function run(string $email, string $key, string $webook) {
7477

7578
// $this->TEST_aiDetectionSubmitNaturalLanguage($loginResult);
7679

77-
$this->TEST_aiDetectionSubmitSourceCode($loginResult);
78-
7980
// $this->TEST_writingAssistant($loginResult);
80-
// $this->TEST_textModeration($loginResult);
8181

82+
$this->TEST_textModeration($loginResult);
8283

8384
} catch (Throwable $th) {
8485
echo $th->getMessage();
@@ -186,35 +187,6 @@ private function TEST_aiDetectionSubmitNaturalLanguage(CopyleaksAuthToken $authT
186187
$this->logInfo('AI Detection - submitNaturalLanguage', $response);
187188
}
188189

189-
private function TEST_aiDetectionSubmitSourceCode(CopyleaksAuthToken $authToken) {
190-
$sampleCode = "def add(a, b):\n" .
191-
" return a + b\n" .
192-
"\n" .
193-
"def multiply(a, b):\n" .
194-
" return a * b\n" .
195-
"\n" .
196-
"def main():\n" .
197-
" x = 5\n" .
198-
" y = 10\n" .
199-
" sum_result = add(x, y)\n" .
200-
" product_result = multiply(x, y)\n" .
201-
" print(f'Sum: {sum_result}')\n" .
202-
" print(f'Product: {product_result}')\n" .
203-
"\n" .
204-
"if __name__ == '__main__':\n" .
205-
" main();";
206-
207-
$submission = new CopyleaksSourceCodeSubmissionModel(
208-
$sampleCode,
209-
'sampleCode.py'
210-
);
211-
212-
$submission->sandbox = true;
213-
214-
$response = $this->copyleaks->aiDetectionClient->submitSourceCode($authToken, time(), $submission);
215-
$this->logInfo('AI Detection - submitSourceCode', $response);
216-
}
217-
218190
private function TEST_writingAssistant(CopyleaksAuthToken $authToken) {
219191
$sampleText = "Lions are the only cat that live in groups, called pride. A prides typically consists of a few adult males, several feales, and their offspring. This social structure is essential for hunting and raising young cubs. Female lions, or lionesses are the primary hunters of the prid. They work together in cordinated groups to take down prey usually targeting large herbiores like zbras, wildebeest and buffalo. Their teamwork and strategy during hunts highlight the intelligence and coperation that are key to their survival.";
220192

@@ -271,23 +243,24 @@ private function TEST_MISC() {
271243
}
272244
private function TEST_textModeration(CopyleaksAuthToken $authToken) {
273245

246+
$labelsArray=[
247+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::ADULT_V1),
248+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::TOXIC_V1),
249+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::VIOLENT_V1),
250+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::PROFANITY_V1),
251+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::SELF_HARM_V1),
252+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::HARASSMENT_V1),
253+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::HATE_SPEECH_V1),
254+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::DRUGS_V1),
255+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::FIREARMS_V1),
256+
new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::CYBERSECURITY_V1)
257+
]; // labels
258+
274259
$textModerationRequest = new CopyleaksTextModerationRequestModel(
275260
"This is some text to scan.", // text
276261
true, // sandbox mode
277-
"en", // language
278-
[
279-
["id" => "other-v1"],
280-
["id" => "adult-v1"],
281-
["id" => "toxic-v1"],
282-
["id" => "violent-v1"],
283-
["id" => "profanity-v1"],
284-
["id" => "self-harm-v1"],
285-
["id" => "harassment-v1"],
286-
["id" => "hate-speech-v1"],
287-
["id" => "drugs-v1"],
288-
["id" => "firearms-v1"],
289-
["id" => "cybersecurity-v1"]
290-
] // labels
262+
CopyleaksTextModerationLanguages::ENGLISH, // language
263+
$labelsArray
291264
);
292265

293266
$response = $this->copyleaks->textModerationClient->submitText($authToken, time(), $textModerationRequest);

src/Models/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
include_once('submissions/index.php');
3434

3535
include_once('exports/index.php');
36-
include_once('constants/Index.php');
3736
include_once('exceptions/Index.php');
3837
include_once('textModeration/index.php');
38+
include_once('constants/index.php');

0 commit comments

Comments
 (0)