HTTP API: how to load recently trained model

Hi, I am using HTTP API to train the model. I get the whole model tar file in response of the train api. Is there a way to get the model name of currently trained model so that I can load that model using API.

Currently, you cannot obtain the filename of the trained model from the response. I opened a Pull Request (/model/train: add filename to response header by tabergma · Pull Request #3872 · RasaHQ/rasa · GitHub) to fix this. So, in the next release you can get the model filename from the response headers.

The trained model is stored in the directory you provide via out in the request body or in the default model directory models. For now, you can just take the latest model file in that directory and assume that it is the model you just trained.

1 Like

Hi @Tanja

Is the feature updated. if so how can i get the filename form response header ??

Yes, the feature is updated. You can get the response header by doing something similar like this: Python’s Requests Library (Guide) – Real Python

what is returned by the train API is a byte array

model = requests.post(‘http://localhost:8003/model/train’,headers=headers,data=json.dumps(data)).content

something like

b’\x1f\x8b\x08\x08 \xfa\xa6]\x02\xff20191016-163816.tar\x00\xec\xbdY\x8f\xabZ\xba \x98\xcf\xf9\x1fZ\x8aJ\xa9\x95U\xf2\xc9c\xf0\x88S}\xfa6`\xb0\x99lFc\*ma\xc0\x183\x1a0\x06J%\xf5K\xff\x88~\xec\x7f\xda\x0b\xec\x18w8\x8c\xed\xd8\xe7\xde\xea\xce-\x9d\x13\x11\x0c\x8b\xf5\xad\xf5\xcd\xd32\xc2\xd8j\xff\xe5\xd7\xfe\x83\xc0\xbf\xe1\xb0\xff\x97\xff\x13\xfc\xfe\xbf\xfc\xdf\xff\xd7\xff\xf3\xfc\x13z\xfd\xf7\x17\xb8\xdb\xef\xc3\xfda\x1f\xeaA\x7f\x81\xe0N\x0f<\xfe\xd4\xff\xcb\x9f\xf0\xef\x90\xa4z\xfc\xf4\xf4\x17\xb8\xd7\x85\xa1\xce\xe0\xe2s\xd7\xee?\x03\xf2\xfc\xf3…

what i want is the name alone so that i can persist that tar file somewhere else with same name with timestamp

how can i extract out the filename alone ??

You can do something like this:

import requests

url = "http://localhost:5005/model/train"

payload = "{\n  \"domain\": \"intents:\\n  - greet\\n  - goodbye\\n  - affirm\\n  - deny\\n  - mood_great\\n  - mood_unhappy\\n\\nactions:\\n  - utter_greet\\n  - utter_cheer_up\\n  - utter_did_that_help\\n  - utter_happy\\n  - utter_goodbye\\n\\ntemplates:\\n  utter_greet:\\n  - text: \\\"Hey! How are you?\\\"\\n\\n  utter_cheer_up:\\n  - text: \\\"Here is something to cheer you up:\\\"\\n    image: \\\"https://i.imgur.com/nGF1K8f.jpg\\\"\\n\\n  utter_did_that_help:\\n  - text: \\\"Did that help you?\\\"\\n\\n  utter_happy:\\n  - text: \\\"Great carry on!\\\"\\n\\n  utter_goodbye:\\n  - text: \\\"Bye\\\"\",\n  \"config\": \"language: en\\npipeline: supervised_embeddings\\npolicies:\\n  - name: MemoizationPolicy\\n  - name: KerasPolicy\",\n  \"nlu\": \"## intent:greet\\n- hey\\n- hello\\n- hi\\n## intent:goodbye\\n- bye\\n- goodbye\\n- have a nice day\\n- see you\\n## intent:affirm\\n- yes\\n- indeed\\n## intent:deny\\n- no\\n- never\\n## intent:mood_great\\n- perfect\\n- very good\\n- great\\n## intent:mood_unhappy\\n- sad\\n- not good\\n- unhappy\",\n  \"stories\": \"## happy path\\n* greet\\n\\n  - utter_greet\\n\\n* mood_great\\n\\n  - utter_happy\\n\\n## sad path 1\\n* greet\\n\\n  - utter_greet\\n\\n* mood_unhappy\\n\\n  - utter_cheer_up\\n\\n  - utter_did_that_help\\n\\n* affirm\\n\\n  - utter_happy\\n\\n## sad path 2\\n* greet\\n\\n  - utter_greet\\n\\n* mood_unhappy\\n\\n  - utter_cheer_up\\n\\n  - utter_did_that_help\\n\\n* deny\\n\\n  - utter_goodbye\\n\\n## say goodbye\\n* goodbye\\n\\n  - utter_goodbye\",\n  \"out\": \"models\",\n  \"force\": false\n}"
headers = {
    'accept': "application/octet-stream",
    'Content-Type': "application/json",
    'User-Agent': "PostmanRuntime/7.17.1",
    'Cache-Control': "no-cache",
    'Postman-Token': "71989a1f-1e03-4808-bec9-6770dfc9475e,bc8da177-85d5-4f24-b50e-bfced6969a62",
    'Host': "localhost:5005",
    'Accept-Encoding': "gzip, deflate",
    'Content-Length': "1428",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.headers["filename"])

Hey, can you tell me how to load new model using API after train?