Skip to content

Commit 6ccc114

Browse files
author
Chris Park
committed
text-embedding debug
- fixed unit tests (passed) - fixed syntax errors - fixed text_embedding example to use correct endPoint syntax
1 parent cc3232e commit 6ccc114

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

examples/text_embedding.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parser.addArgument(["--url"], {help: "Rosette API alt-url", required: false});
1212
var args = parser.parseArgs();
1313

1414
var api = new Api(args.key, args.url);
15-
var endpoint = "text-embedding";
15+
var endpoint = "textEmbedding";
1616
var embeddings_data = 'Cambridge, Massachusetts'
1717

1818
api.parameters.content = embeddings_data;

lib/textEmbedding.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ function textEmbedding() {
3636
* @param {string} serviceURL - The base service URL to be used to access the Rosette API
3737
* @param {function} callback - Callback function to be exectuted after the function to which it is passed is complete
3838
*/
39-
entities.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) {
39+
textEmbedding.prototype.getResults = function(parameters, userKey, protocol, serviceURL, callback) {
4040

4141
if (parameters.documentFile != null) {
4242
parameters.loadFile(parameters.loadParams().documentFile, parameters, userKey, protocol, serviceURL, "text-embedding", callback);
43-
}
44-
45-
46-
4743
} else {
4844

4945
// validate parameters
@@ -53,14 +49,9 @@ entities.prototype.getResults = function(parameters, userKey, protocol, serviceU
5349
return callback(new RosetteException("badArgument", "Cannot supply both Content and ContentUri", "bad arguments"));
5450
} else {
5551
// configure URL
56-
if (parameters.loadParams().linked == true) {
57-
urlParts = URL.parse(serviceURL + "text-embedding");
58-
}
59-
60-
52+
var urlParts = URL.parse(serviceURL + "text-embedding");
6153
var req = new rosetteRequest();
6254
req.makeRequest('POST', userKey, protocol, urlParts, parameters, callback);
63-
6455
}
6556
}
6657

tests/unittests.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,60 @@ describe("Sentences Endpoint", function() {
615615

616616
});
617617

618+
describe("Text Embedding Endpoint", function() {
619+
beforeEach(function(done) {
620+
var mockResponse = JSON.stringify({'name': 'Rosette API', 'versionChecked': true});
621+
622+
nock('https://api.rosette.com', {"encodedQueryParams": true })
623+
.post('/rest/v1/text-embedding')
624+
.query({"clientVersion": "1.1"})
625+
.reply(200, JSON.parse(mockResponse));
626+
done();
627+
});
628+
629+
afterEach(function(done) {
630+
nock.cleanAll();
631+
done();
632+
});
633+
634+
it("successfully calls the textEmbedding endpoint", function(done) {
635+
var api = new Api('123456789', 'https://api.rosette.com/rest/v1');
636+
api.parameters.content = "Some Content";
637+
638+
api.rosette("textEmbedding", function(err, res) {
639+
chai.expect(err).to.be.null;
640+
chai.expect(res.name).to.equal('Rosette API');
641+
done();
642+
});
643+
644+
});
645+
646+
it("detects content and contentUri are defined", function(done) {
647+
var api = new Api('123456789', 'https://api.rosette.com/rest/v1');
648+
api.parameters.content = "Sample Content";
649+
api.parameters.contentUri = "http://some.url.com";
650+
651+
api.rosette("textEmbedding", function(err, res) {
652+
chai.expect(err).to.not.be.null;
653+
chai.expect(err.name).to.equal('RosetteException');
654+
chai.expect(err.message).to.contain('badArgument');
655+
done();
656+
});
657+
});
658+
659+
it("detects neither content nor contentUri are defined", function(done) {
660+
var api = new Api('123456789', 'https://api.rosette.com/rest/v1');
661+
662+
api.rosette("textEmbedding", function(err, res) {
663+
chai.expect(err).to.not.be.null;
664+
chai.expect(err.name).to.equal('RosetteException');
665+
chai.expect(err.message).to.contain('badArgument');
666+
done();
667+
});
668+
});
669+
670+
});
671+
618672
describe("Info Endpoint", function() {
619673
beforeEach(function(done) {
620674
var mockResponse = JSON.stringify({'name': 'Rosette API', 'versionChecked': true});

0 commit comments

Comments
 (0)