Accept pathlib model path
See original GitHub issueDescription of Problem: I am fond of pathlib and of this particular snippet to load the newest model I have:
import pathlib
from rasa.core.agent import Agent
models_folder = pathlib.Path("models")
latest_model = max(models_folder.glob("*.tar.gz"), key=lambda p: p.stat().st_ctime)
agent = Agent.load(str(latest_model))
The only friction here is str(latest_model)
. Adding support for pathlib paths would be quite convenient.
Overview of the Solution:
Since os.path
functions are compatible with pathlib
, the only change we would need to do is right there https://github.com/RasaHQ/rasa/blob/master/rasa/core/agent.py#L355:
model_path = get_model(str(model_path))
I could submit a PR if the feedback is positive.
The interrogation left would be about the type hints: model_path
is a Text
right now, would a Union[Text, Path]
type be acceptable?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >Python 3's pathlib Module: Taming the File System
In this tutorial, you will see how to work with file paths—names of directories and files—in Python. You will learn new ways to...
Read more >Python Path – How to Use the Pathlib Module with Examples
In this example, we import the Pathlib module. Then, we create a new variable called p to store the path. Here, we use...
Read more >Accept pathlib model path · Issue #4341 · RasaHQ/rasa - GitHub
Description of Problem: I am fond of pathlib and of this particular snippet to load the newest model I have: import pathlib from ......
Read more >Pathlib module in Python - GeeksforGeeks
This method is used to check whether the path is absolute or not. This method returns True if the path is absolute otherwise...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @silvasara and @Henrike100, it works like a charm 👍 I am closing the issue.
That’s great @silvasara. Please let us know if you need any help with this.