Is the listModels request limited to the number of returned records by default? - clarifai

For the following call
client.listModels(ListModelsRequest.newBuilder().build());
will all of the models be returned or just some subset?

As per Clarifai Swagger UI, the default page size is 128, so only the first 128 models will be returned. If you wish to get all the models, then you need to paginate it using page parameter.

Related

Shopware 6 Product API limit with offset

When using Shopware 6 /api/product REST-API I do get an timeout.
I found out i can set an limit and an offset.
When I call the API with /api/product?limit=240&offset=240 I still get the first 240 products.
Also tried using Shopware 5 offset variant, where you use start instead of offset.
Both give the same result.
I also tried doing an POST instead of an GET request, also no success.
I even using /api/search/product...
Does anyone know how to correctly perform an offset?
In the shopware 6 API you can request paginated data by using limit and page parameters. The page roughly translates to the offset that is being used, instead of doing a request with an offset of 240 (as in your example) you would request the page=2 with a limit of 240 this would give you the results 241-480.
So instead of
/api/product?limit=240&offset=240
you should use
/api/product?limit=240&page=2
The limit and page parameters can be used in GET-Requests, but also in POST-Request in the JSON-Body or in the search endpoint.
Take a look at the official docs for reference.

What is the proper way to format a GET request to retrieve all media items of the Instagram user "self"?

Looking at https://www.instagram.com/developer/endpoints/users/ I have gathered that calling https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN will return "the most recent media published by the owner of the access_token."
In sandbox mode I understand that I will receive a maximum of 20 media items from this call. I also realize that the response code has a pagination object that I can use to retrieve up to 20 more media items (see below)
"pagination": {
"next_max_tag_id": "1387272337517",
"deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead",
"next_max_id": "1387272337517",
"next_min_id": "1387272345517",
"min_tag_id": "1387272345517",
"next_url": "https://api.instagram.com/v1/tags/cats/media/recent?access_token=xxx&max_tag_id=1387272337517"
}
These are the listed parameters of this Request.
PARAMETERS
ACCESS_TOKEN A valid access token.
MAX_ID Return media earlier than this max_id.
MIN_ID Return media later than this min_id.
COUNT Count of media to return.
My question is: Is there a way to structure my GET request in a way that returns all media items from a single call? I understand that this is not possible in sandbox mode, given a user with more than 20 media items. If possible please provide a detailed explanation of the COUNT parameter.
I imagine a possible GET request would look like https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN?COUNT=X
Thank you. <3
When you go live mode you can use the count= param to get more than 20 in one API call, however I have noticed that count=33 is the maximum you can get for this API call, even if you anything more than 33, it only returns 33.
You still have to use the pagination in JSON response to get the next set of media items, easiest way is to use the pagination.next_url to make API call and get next set of media items

How to get extracts for all returned pages by Wikipedia API?

I am using the sandbox to find out how I can use extracts property to retrieve the first sentence in all pages (limit 10) with title Amsterdam, but as you can see in the sandbox the extracts property is only working on the first retrieved page.
How can I get extracts for all the returned pages?
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&format=json&prop=info|extracts&generator=search&exsentences=1&exintro=1&gsrsearch=Amsterdam&gsrnamespace=0&gsrlimit=10
You need to use exlimit for prop=extracts (max value is 20, default is 1):
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&format=json&prop=info|extracts&generator=search&exsentences=1&exintro=1&gsrsearch=Amsterdam&gsrnamespace=0&gsrlimit=10&exlimit=10

Content-Range configuration for Django Rest Pagination

6.30.15 - HOW CAN I MAKE THIS QUESTION BETTER AND MORE HELPFUL TO OTHERS? FEEDBACK WOULD BE HELPFUL. THANKS!
I need to send a content-range header to a dojo/dgrid request:
I cannot find any examples of HOW to do this. I'm not exactly sure where this setting goes (Content-Range: items 0-9/*). I have been given a great linkheaderpagination example on this question: Django Rest Framework Pagination Settings - Content-Range But I don't know how to make this work to produce a Content-Range response. Any takers or does anyone know of any good resources or examples??
UPDATE: I am trying to create pagination in Dojo/grid. I have am using a server-side api (Django Rest Framework) to supply to data to the Dojo/Dgrid. Django Rest Framework does not automatically sent content-range headers when it gets a response from Dojo. Dojo sends a range request when formatted to have pagination. I don't know now to configure the Django Rest Framework API to send a content-range header when it gets a request from Dojo. Unfortunately, I'm trying to do something very specific and just general settings on either side doesn't work.
Including Content-Range Header in response:
You just need to create a headers dictionary with Content-Range as the key and value as how many items are being returned and how many total items exist.
For example:
class ContentRangeHeaderPagination(pagination.PageNumberPagination):
"""
A custom Pagination class to include Content-Range header in the
response.
"""
def get_paginated_response(self, data):
"""
Override this method to include Content-Range header in the response.
For eg.:
Sample Content-Range header value received in the response for
items 11-20 out of total 50:
Content-Range: items 10-19/50
"""
total_items = self.page.paginator.count # total no of items in queryset
item_starting_index = self.page.start_index() - 1 # In a page, indexing starts from 1
item_ending_index = self.page.end_index() - 1
content_range = 'items {0}-{1}/{2}'.format(item_starting_index, item_ending_index, total_items)
headers = {'Content-Range': content_range}
return Response(data, headers=headers)
Suppose this is the header received:
Content-Range: items 0-9/50
This indicates that first 10 items are returned out of total 50.
Note: You can also use * instead of total_items if calculating total is expensive.
Content-Range: items 0-9/* # Use this if total is expensive to calculate
If you are talking about providing Content-Range in the response, I mentioned in an answer to another SO question (which I believe may also have originated from your team?) that there is one alternative to this header: if your response format is an object (not just an array of items), it can specify a total property indicating the total number of items instead.
Again looking for a few minutes at the DRF documentation, it appears it should be possible to customize the format of the response.
Based on the docs and reading the source of LimitOffsetPagination (which you want to be using to work with dstore, as already discussed in a previous question), if I had to take a wild guess, you should be able to do the following server-side:
class CustomPagination(pagination.LimitOffsetPagination):
def get_paginated_response(self, data):
return Response(OrderedDict([
('total', self.count),
('next', self.get_next_link()),
('previous', self.get_previous_link()),
('items', data)
]))
This purposely assigns the count to total and the data to items to align with the expectations of dstore/Request. (next and previous are entirely unnecessary as far as dstore is concerned, so you could take or leave them, depending if you have any use for them elsewhere.)

querying categorymembers with wikimedia and the size

I try to get the page sizes of all category members through the wikimedia api with only one request.(or less then 10).
I know I would get the sizes of pages by:
(1) Requesting every page separately and get the size
or
(2) A search query like this:
http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=physics
The result is several pages with the size and word count property.
Now how can I get the size and word count for a category member with a query like this or with another trick ?
http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Physics
Any hints shared would be appreciated.
You can use a category query as a generator, using generator=categorymember and gcmtitle=Category:Physics. This will execute the query action for each and every page in that category:
api.php?action=query
&generator=categorymembers
&gcmtitle=Category:Lakes
&prop=info
In the docs you can see what properties can be used as generators: categories, links and templates. Also, more or less every list module can be used as a generator in the same fashion.
Note that parameter names are prefixed with a g when used for a generator, so that cmtitle in the example above becomes gcmtitle, to distinguish them from parameters to the query action (that is applied to every page returned by the generator), prop and inprop, parameters