Skip to content

Commit d53db76

Browse files
author
Julien Salinas
committed
Implement the code generation and article generation endpoints.
1 parent 9e1f3ff commit d53db76

3 files changed

Lines changed: 60 additions & 4 deletions

File tree

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is the PHP client for the [NLP Cloud](https://nlpcloud.io) API. See the [documentation](https://docs.nlpcloud.io) for more details.
44

5-
NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, dialogue summarization, paraphrasing, intent classification, product description and ad generation, chatbot, grammar and spelling correction, keywords and keyphrases extraction, text generation, question answering, machine translation, language detection, semantic similarity, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API.
5+
NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, dialogue summarization, paraphrasing, intent classification, product description and ad generation, chatbot, grammar and spelling correction, keywords and keyphrases extraction, text generation, blog post generation, code generation, question answering, machine translation, language detection, semantic similarity, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API.
66

77
You can either use the NLP Cloud pre-trained models, fine-tune your own models, or deploy your own models.
88

@@ -137,7 +137,7 @@ use NLPCloud\NLPCloud;
137137
$client = new \NLPCloud\NLPCloud('<model>','<your token>', false, '<your language code>');
138138
```
139139

140-
### Product Description and Ad Generation
140+
### Ad Generation And Product Description Endpoint
141141

142142
Call the `adGeneration()` method and pass a list of keywords you want to generate you product description or ad from.
143143

@@ -147,7 +147,17 @@ $client->adGeneration(["Keyword 1", "Keyword 2", "Keyword 3", ...])
147147

148148
The above command returns a JSON object.
149149

150-
### Chatbot
150+
### Article Generation Endpoint
151+
152+
Call the `articleGeneration()` method and pass the title of the blog post your want to generate:
153+
154+
```php
155+
$client.articleGeneration("<Your title>")
156+
```
157+
158+
The above command returns a JSON object.
159+
160+
### Chatbot Endpoint
151161

152162
Call the `chatbot()` method and pass your input. As an option, you can also pass a conversation history that is an array of named arrays. Each named array is made of an `input` and a `response` from the chatbot.
153163

@@ -171,6 +181,16 @@ $client->classification("<Your block of text>", ["label 1", "label 2", ...], Tru
171181

172182
The above command returns a JSON object.
173183

184+
### Code Generation Endpoint
185+
186+
Call the `codeGeneration()` method and pass the description of your program:
187+
188+
```php
189+
$client.codeGeneration("<Your instruction>")
190+
```
191+
192+
The above command returns a JSON object.
193+
174194
### Dependencies Endpoint
175195

176196
Call the `dependencies()` method and pass the text you want to perform part of speech tagging (POS) + arcs on.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nlpcloud/nlpcloud-client",
3-
"description": "NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, paraphrasing, grammar and spelling correction, keywords and keyphrases extraction, chatbot, product description and ad generation, intent classification, text generation, question answering, machine translation, language detection, semantic similarity, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API. This is the PHP client for the API. More details here: https://nlpcloud.io. Documentation: https://docs.nlpcloud.io. Github: https://github.com/nlpcloud/nlpcloud-php",
3+
"description": "NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, paraphrasing, grammar and spelling correction, keywords and keyphrases extraction, chatbot, product description and ad generation, intent classification, text generation, blog post generation, code generation, question answering, machine translation, language detection, semantic similarity, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API. This is the PHP client for the API. More details here: https://nlpcloud.io. Documentation: https://docs.nlpcloud.io. Github: https://github.com/nlpcloud/nlpcloud-php",
44
"homepage": "http://github.com/nlpcloud/nlpcloud-php",
55
"license": "MIT",
66
"keywords": [

src/NLPCloud.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ public function ad_generation($keywords)
4848
return $response->body;
4949
}
5050

51+
public function articleGeneration($title)
52+
{
53+
$payload = array(
54+
'title' => $title
55+
);
56+
$response = \Httpful\Request::post($this->rootURL . '/' . 'article-generation', $payload)
57+
->expectsJson()
58+
->sendsJson()
59+
->addHeaders($this->headers)
60+
->send();
61+
62+
if ($response->code != 200) {
63+
throw new \Exception($response->code . ': ' . $response->body->detail);
64+
}
65+
66+
return $response->body;
67+
}
68+
5169
public function chatbot($input, $history = NULL)
5270
{
5371
$payload = array(
@@ -87,6 +105,24 @@ public function classification($text, $labels = NULL, $multiClass = True)
87105
return $response->body;
88106
}
89107

108+
public function codeGeneration($instruction)
109+
{
110+
$payload = array(
111+
'instruction' => $instruction
112+
);
113+
$response = \Httpful\Request::post($this->rootURL . '/' . 'code-generation', $payload)
114+
->expectsJson()
115+
->sendsJson()
116+
->addHeaders($this->headers)
117+
->send();
118+
119+
if ($response->code != 200) {
120+
throw new \Exception($response->code . ': ' . $response->body->detail);
121+
}
122+
123+
return $response->body;
124+
}
125+
90126
public function dependencies($text)
91127
{
92128
$payload = array(

0 commit comments

Comments
 (0)