clarifai / clarifai-nodejs-grpc Goto Github PK
View Code? Open in Web Editor NEWClarifai gRPC NodeJS client
Home Page: https://docs.clarifai.com
License: Other
Clarifai gRPC NodeJS client
Home Page: https://docs.clarifai.com
License: Other
Hi!
Code example:
const {ClarifaiStub} = require("clarifai-nodejs-grpc");
const grpc = require("@grpc/grpc-js");
const stub = ClarifaiStub.insecureGrpc();
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + MY_API_KEY);
stub.PostModelOutputs(
{
model_id: 'ivp-model',
inputs: [{data: {image: {url: 'https://samples.clarifai.com/food.jpg'}}}]
},
metadata,
(err: any, response: any) => {
if (err) {
console.log("Error: " + err);
return;
}
if (response.status.code !== 10000) {
console.log("Received failed status: " + response.status.description + "\n" + response.status.details);
return;
}
for (const c of response.outputs[0].data.concepts) {
console.log(c.name + ": " + c.value);
}
}
I always get:
'Received failed status: Invalid request
Empty or malformed authorization header. Please provide an API key or session token.'
As I understood, I need to take MY_API_KEY from an application page on https://portal.clarifai.com/ in "API Keys" area.
What I do wrong?
ClarifaiStub
@rok-clarifai Thank you for this NodeJS Library! The Readme explains the basic "predict" functionality well.
I'm lost when it comes to working with the callback, though. Apart from inspecting test responses, it's not easy to determine what values are possible for the callback parameters. From the Readme:
(err, response) => { // What is the type of err and response?
if (err) {
console.log("Error: " + err);
return;
}
if (response.status.code !== 10000) {
console.log("Received failed status: " + response.status.description + "\n" + response.status.details);
return;
}
for (const c of response.outputs[0].data.concepts) {
console.log(c.name + ": " + c.value);
}
}
I am totally unfamiliar with gRPC, so I don't have any intuition about how this library behaves, so a .d.ts
file would be extremely helpful.
I believe that it should be possible to automatically generate TS definitions for the ClarifaiStub
, at least this post seems to say so in the section "Generating gRPC clients and types from proto files"
Is this something the authors can do?
in this line you import the types from grpc
. But grpc
is the deprecated version with not type declarations.
fix: import * as grpc from "@grpc/grpc-js";
Hello!
I am encountering an issue when importing this library into my next.js application.
This occurs when I load the page on which I am importing clarifai-nodejs-grpc
./node_modules/@grpc/grpc-js/build/src/channel-credentials.js:20:0
Module not found: Can't resolve 'tls'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/@grpc/grpc-js/build/src/index.js
./node_modules/clarifai-nodejs-grpc/src/index.js
./pages/admin.js
I am using next.js v13.5.4
and clarifai-nodejs-grpc v9.9.6
Any advice on what I could try to get this working would be much appreciated. Thank you!
This is printed when you try to do it:
(node:28003) UnhandledPromiseRejectionWarning: Error: Error: 1 CANCELLED: undefined
...
Currently, the JSON channel doesn't respect the page
and the perPage
fields.
After I import your library and trying to build, following error occurs
node_modules/clarifai-nodejs-grpc/proto/clarifai/api/service_grpc_pb.d.ts:7:23 - error TS2307: Cannot find module 'grpc' or its corresponding type declarations.
7 import * as grpc from "grpc";
~~~~~~
Found 1 error.
Currently, a concept with no value will default to 1.0 in the JSON channel. This is inconsistent with the gRPC channel where it'll default to 0.0.
Make JSON channel default to 0.0 (this is also what JSON channels in Java and Python do).
I want to expose the CRUD API for inputs, annotations and concepts. I am unable to find how to delete concepts using the gRCP node client (V7.4)
I want to delete concepts having only the concept's id
There seems to be a way to delete concepts using inputs : https://docs.clarifai.com/api-guide/data/create-get-update-delete
The docs do not reveal how to delete concepts : https://docs.clarifai.com/portal-guide/concept/concepts
Thank you for helping me
Using a similar call:
// This will be used by every Clarifai endpoint call.
const metadata = new grpc.Metadata()
metadata.set('authorization', 'Key XXXXX')
stub.PostInputs(
{
inputs: [{data: {
image: {url: "https://samples.clarifai.com/puppy.jpeg", allow_duplicate_url: true},
metadata: {id: "id001", type: "animal", size: 100}
}}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
Metadata is not attached to the input when you check via the Portal or any other method. This seems to happen only with this gRPC client.
Hi
After importing the clarifai-nodejs-grpc package, I get this error:
./node_modules/@grpc/grpc-js/build/src/server.js
Module not found: Can't resolve 'http2' in 'C:\Users\Nene\Desktop\WebWork\face-recognition-app\node_modules@grpc\grpc-js\build\src'
Thanks
Been trying to figure this out for the past hour. I followed all instructions on Clarify website.
added:
const {ClarifaiStub, grpc} = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key API Key");
stub.PostModelOutputs(
{
// This is the model ID of a publicly available General model. You may use any other public or custom model ID.
model_id: "aaa03c23b3724a16a56b629203edc62c",
inputs: [{data: {image: {url: "https://samples.clarifai.com/dog2.jpeg"}}}]
},
metadata,
(err, response) => {
if (err) {
console.log("Error: " + err);
return;
}
if (response.status.code !== 10000) {
console.log("Received failed status: " + response.status.description + "\n" + response.status.details);
return;
}
console.log("Predicted concepts, with confidence values:")
for (const c of response.outputs[0].data.concepts) {
console.log(c.name + ": " + c.value);
}
}
);
after saving there were errors and I tried resolving. now all I receive is Failed to compile
./node_modules/@grpc/grpc-js/build/src/resolver-dns.js
Module not found: Can't resolve 'dns'
a bit new and still trying to learn.
Thank you for the great new Typescript definitions in v7.
However, I can't find a Changelog or Release notes. What has changed in this library's API? What's new? Where will code consuming v6 break with v7?
tried : npm install http2
got error again: Error: Cannot find module './framer'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.