How to import knowledge base through api? - google-cloud-platform

https://cloud.google.com/dialogflow/es/docs/reference/rest/v2beta1/projects.knowledgeBases.documents/import
Consider I'm having an csv file to be imported in a cloud storage, How exactly do I execute this above API request and import the knowledge base qna's, I've added the documentation link above, I'm getting the below error too

Change the parent to projects/your-project-id/knowledgeBases/xxxxxx and import should accept it.
But I suggest to use projects.knowledgeBases.documents.create if you are planning to create a knowledge base from scratch using a CSV file. See sample request via projects.knowledgeBases.documents.create:
parent: projects/your-project-id/knowledgeBases/xxxxx
importGcsCustomMetadata: false
Request Body:
{
"contentUri": "gs://my-bucket/faq.csv",
"displayName": "test_csv",
"knowledgeTypes": [
"FAQ"
],
"mimeType": "text/csv"
}
Returns HTTP 200:
{
"name": "projects/your-project-id/locations/us/operations/document-create-20210829-21261630297603-6127fbb9-0000-21dc-bec9-240588717654"
}
Created knowledge base in Dialogflow console:

Related

Create a Sharepoint list in a specific folder with Microsoft graph api

Premise:
I have a folder under the sharepoint site for e.g.
https://... <mycompany-sharepoint-site.com>/
under which we have folder so my url is something like
https://... <mycompany-sharepoint-site.com>/Documents/Sub_folder_1/Sub_folder_2
pertaining to our project.
I need to be able to create a Sharepoint list in the Sub_folder_2 - folder and not at the root level.
With Sharepoint - GraphApi - create list api url
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists
I will ONLY be able to create at the <mycompany-sharepoint-site.com> level (i.e. at the root level) which is not what I want.
FYI, I already tried (on Postman) to go with the drives//items/<folder_id> - route or I should say attempted to do so but failed.
Any help is greatly appreciated.
If you want to use Graph API to create a folder in SharePoint, please use the following query:
POST /groups/{group-id}/drive/items/{parent-item-id}/children
For more information: https://learn.microsoft.com/en-us/graph/api/driveitem-post-children?view=graph-rest-1.0&tabs=http#http-request
Hope this is helpful.
I don't think that SharePoint supports creating a list inside the folder but you can at least try to create a list and specify the path in the parent reference.
You need to find out the drive id.
POST https://graph.microsoft.com/v1.0/sites/{site_id}/lists
{
"displayName": "Test",
"columns": [
{
"name": "Column1",
"text": {}
},
{
"name": "Column2",
"number": {}
}
],
"list": {
"template": "genericList"
},
"parentReference": {
"driveType": "documentLibrary",
"driveId": "{drive_id}",
"path": "/drives/{drive_id}/root:/Documents/Sub_folder_1/Sub_folder_2"
# or
# "path": "/drives/{drive_id}/root:/Sub_folder_1/Sub_folder_2"
}
}
I don't think it's even possible at all, did you succeed that manually?

Google Cloud Vision Api only return "name"

I am trying to use Google Cloud Vision API.
I am using the REST API in this link.
POST https://vision.googleapis.com/v1/files:asyncBatchAnnotate
My request is
{
"requests": [
{
"inputConfig": {
"gcsSource": {
"uri": "gs://redaction-vision/pdf_page1_employment_request.pdf"
},
"mimeType": "application/pdf"
},
"features": [
{
"type": "DOCUMENT_TEXT_DETECTION"
}
],
"outputConfig": {
"gcsDestination": {
"uri": "gs://redaction-vision"
}
}
}
]
}
But the response is always only "name" like below:
{
"name": "operations/a7e4e40d1e1ac4c5"
}
My "gs" location is valid.
When I write the wrong path in "gcsSource", 404 not found error is coming.
Who knows why my response is weird?
This is expected, it will not send you the output as a HTTP response. To see what the API did, you need to go to your destination bucket and check for a file named "xxxxxxxxoutput-1-to-1.json", also, you need to specify the name of the object in your gcsDestination section, for example: gs://redaction-vision/test.
Since asyncBatchAnnotate is an asynchronous operation, it won't return the result, it instead returns the name of the operation. You can use that unique name to call GetOperation to check the status of the operation.
Note that there could be more than 1 output file for your pdf if the pdf has more pages than batchSize and the output json file names change depending on the number of pages. It isn't safe to always append "output-1-to-1.json".
Make sure that the uri prefix you put in the output config is unique because you have to do a wildcard search in gcs on the prefix you provide to get all of the json files that were created.

how to use google cloud vision to extract multiple text language in android studio

I am trying to build an android application (in android studio platform) which extracts different text languages from image using google cloud vision, but I have a problem in starting.
I don't know how to use google cloud files. Which files do I need to create or download and how to direct my API to extract multiple languages?
I got the API and this source code :
POST https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY
{
"requests": [
{
"image": {
"content": "/9j/7QBEUGhvdG9zaG9...base64-encoded-image-content...fXNWzvDEeYxxxzj/Coa6Bax//Z"
},
"features": [
{
"type": "TEXT_DETECTION"
}
]
}
]
}
public static void detectText(String filePath, PrintStream out) throws Exception, IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Type.TEXT_DETECTION).build();
AnnotateImageRequest request =
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
out.printf("Error: %s\n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
out.printf("Text: %s\n", annotation.getDescription());
out.printf("Position : %s\n", annotation.getBoundingPoly());
}
}
}
}
I would suggest you to try your image data on the Cloud Vision Api Explorer [1]. You can try the API directly on the web browser with an Oauth2 authentication. Follow the steps below:
Enable the API on Google Cloud Console -> APIs and Services -> Libraries
Set the scopes on the API Explorer checkbox:
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/cloud-vision
{
"requests": [
{
"features": [
{
"type": "TEXT_DETECTION"
}
],
"image": {
"source": {
"imageUri": "http://dps.usc.edu/files/2015/07/text-alerts.png"
},
},
"imageContext": {
"languageHints": [
"en"
]
}
]
}
Set de “imageContext”. There you can set language hints, but the API might detect the language automatically. Check this [2] for available language hints.
In the source you could use an image from your Google Cloud Storage bucket changing “imageUri” by: "gcsImageUri": "gs://your-bucket/text-alerts.png" as your image uri. Note the change in protocol.
You are using “content” instead of “source”, and this is for setting a base64 encoded string image. You can try to encode an image with Base64 copy the encode as plain text and try on the API Explorer to check that the encode is correct and works. Be careful when copying as you may get noise like \n, \t and things that might break your b64 encode. I share a python code that does the job:
import base64
f = open("text-alerts.png", "rb")
encoded = base64.b64encode(f.read())
print(encoded)
f.close()
fw = open('content.b64', "wb")
fw.write(encoded)
fw.close()
In your request:
{ "requests": [ { "image": { "content": "/9j/7QBEUGhvdG9zaG9...base64-encoded-image-content...fXNWzvDEeYxxxzj/Coa6Bax//Z" }, "features": [ { "type": "TEXT_DETECTION" } ] } ] }
The content tag is the image string in Base64:
"content":“/9j/7QBEUGhvdG9zaG9...base64-encoded-image-content...fXNWzvDEeYxxxzj/Coa6Bax//Z”
You can use a web tool to do the same and check that your Base64 works. You can load the file on the Android Studio.
Here [4] you can find a sample for Android, with a README that explains how to configure your App. You need to create your API Key here [3] and in the MainActivity you have a variable that must be set to your API Key that then is used for the request.
private static final String CLOUD_VISION_API_KEY = "YOUR_API_KEY";
The sample loads an image and converts it to Base64 before sending the request [5]. See the method callCloudVision, inside there is an AsyncTask that retrieves an image and converts it to Base64 before sending the request.
[1] https://cloud.google.com/vision/docs/quickstart
[2] https://cloud.google.com/vision/docs/languages
[3] https://console.cloud.google.com/apis/credentials?project=your-project-id
[4] https://github.com/GoogleCloudPlatform/cloud-vision/tree/master/android
[5] https://github.com/GoogleCloudPlatform/cloud-vision/blob/master/android/CloudVision/app/src/main/java/com/google/sample/cloudvision/MainActivity.java#L192

Amazon API Gateway swagger importer tool does not import minItems feild from swagger

I am trying the api gateway validation example from here https://github.com/rpgreen/apigateway-validation-demo . I observed that from the given swagger.json file, minItems is not imported into the models which got created during the swagger import.
"CreateOrders": {
"title": "Create Orders Schema",
"type": "array",
"minItems" : 1,
"items": {
"type": "object",
"$ref" : "#/definitions/Order"
}
}
Because of this when you give an empty array [ ] as input, instead of throwing an error about minimum items in an array, the api responds with a message 'created orders successfully'.
When I manually add the same from the API gateway console UI, it seems to work as expected. Am i missing something or this is a bug in the importer?
This is a known issue with the Swagger import feature of API Gateway.
From http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html
The maxItems and minItems tags are not included in simple request validation. To work around this, update the model after import before doing validation.

Choose language using views services in drupal 7

I use views services module with rest services. The views shows content using "current user's language" but when I get content always returns in the default language.
For example:
http://example.com/api1_rest/views/content_view?id_display=page&limit=10&offset=0
Returns
[
{
"vid":"300",
"uid":"4",
"title":"node title",
"log":"",
"status":"1",
"comment":"0",
"promote":"0",
"sticky":"0",
"nid":"2488",
"type":"news",
"language":"en",
"revision_timestamp":"1422900078",
"revision_uid":"1",
"body":{
"en":[
{
"value":"content body here",
"summary":"",
"format":"4"
}
]
},
}
]
I need choose language in rest petition.
From Services Views module page:
You can create exposed filters and pass them to your resource. For example if we created exposed filter "tags" call will be:
http://example.com//?tags=7
So you can create a exposed filter for language in your view and than just filter results by adding &lang=en to the url:
http://example.com/api1_rest/views/content_view?id_display=page&limit=10&offset=0&lang=en