Hello guys! I am a user of your Kedro Boot librar...
# questions
e
Hello guys! I am a user of your Kedro Boot library, and I have a question regarding input definition. An endpoint in my API receives a JSON as input, but I need to register it in the catalog, right? Is there a good approach I can use in the catalog to avoid always saving the value received by the API? Would it have to be a memory dataset? The downside of using a memory dataset is that I always have to convert it to JSON... I appreciate your help! Thank you!
h
Someone will reply to you shortly. In the meantime, this might help:
l
Hey Erick, there's a JSON Dataset that comes with the kedro-datasets plugin. Would that help you? https://github.com/kedro-org/kedro-plugins/blob/main/kedro-datasets/kedro_datasets/json/json_dataset.py
e
Hi @Laura Couto! Thanks! I tested that dataset, but it requires a filepath, so it'll be saved locally...
l
Other than that I think a MemoryDataset would be the most straightforward solution, with the caveat that you pointed about having to convert it every time.
👍 1
e
Alright! Thanks Laura!
t
Hi Erick ! What do mean by « always saving the value received by the API » ? Your request body can be injected in your dataset in the following manner
your_session.run(inputs={‘your_kedro_dataset’:your_endpoint_data})
From there it’s up to you to define the right dataset type, depending on the data that would be injected in it. Could you please elaborate more on your use case or share with us your code ?
e
Yes, sure! @Takieddine Kadiri consider that I have a JSON dataset called "messages," and it is used in my API. However, JSON-type datasets require a filepath, so my question is about this filepath: will it imply that the request body is saved in some way? Example: Catalog: "{namespace}.messages": type: json.JSONDataset filepath: request credentials: az_stg_credentials Api: @router.post('/query') async def generate_response(messages: Messages): result = await asyncio.to_thread( kedro_boot_session.run, namespace='api', inputs={'chat_history': chat_history} ) return JSONResponse( status_code=status.HTTP_200_OK, content=result )
👍 1
The message comes from the user, who sends a request to the api
t
You can directly put your user provided messages in your kedro dataset ‘messages’ as follow
inputs={'messages': messages}
With maybe some formating of your Messages object into a json object before running the session. Under the hood kedro-boot replace your json dataset with a memorydataset containing your endpoint messages data. This is done at every API requests, in fact an all new catalog is created at every API request. So there is no need to persist you data so the Json dataset could access it. Let me know if it’s clear and if it’s works for you
👍 1
e
Alright! Thanks! 😁