Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escaping: Escape characters +-&|!(){}[]^"~*?:\ with \, e.g. \+
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
Is There A Way To Programatically Define Api_Host/Web_Host?

Is there a way to programatically define api_host/web_host?

  
  
Posted 3 years ago
Votes Newest

Answers 16


I need this as I want to write a wrapper for internal use.

I need to block the default behavior that link to public server automatically when user has no configuration file.

  
  
Posted 3 years ago

Hi EnviousStarfish54 ,

You can add environment vars in you code, and trains will use those (no configuration file is needed)

import os os.environ["TRAINS_API_HOST"] = "YOUR API HOST " os.environ["TRAINS_WEB_HOST"] = "YOUR WEB HOST " os.environ["TRAINS_FILES_HOST"] = "YOUR FILES HOST "Can this do the trick?

  
  
Posted 3 years ago

currently I do it in a hacky way. I call trains.backend_api Session, and check if 'demoapp' in web server URL.

  
  
Posted 3 years ago

is it possible to overwrite if trains.conf did exist

  
  
Posted 3 years ago

You can add something like:

import os from trains.backend_config.defs import LOCAL_CONFIG_FILES if not os.path.exists(LOCAL_CONFIG_FILES[0]): Task.set_offline(offline_mode=True)
notice that LOCAL_CONFIG_FILES is a list
if the conf file doesnt exists, turn on offline mode (will save you task locally).

  
  
Posted 3 years ago

AgitatedDove14 Thanks! This seems to be a more elegant solution

  
  
Posted 3 years ago

is that possible?

  
  
Posted 3 years ago

is it possible to overwrite if trains.conf did exist

Yes, you can choose specific configuration file with TRAINS_CONFIG_FILE environment var.

  
  
Posted 3 years ago

So if you have ~/trains.conf work with it, if you don't, work offline?

  
  
Posted 3 years ago

Thanks for the help!

  
  
Posted 3 years ago

I mean, once I add environment variable, can trains.conf overwrite it? I am guessing environment variable will have a higher hierarchy.

The things that I want to achieve is:
Block user to access to public server If they configure trains.conf, then it's fine

import os os.environ["TRAINS_API_HOST"] = "YOUR API HOST " os.environ["TRAINS_WEB_HOST"] = "YOUR WEB HOST " os.environ["TRAINS_FILES_HOST"] = "YOUR FILES HOST "

  
  
Posted 3 years ago

I don't want to mess with the standard setup.

  
  
Posted 3 years ago

This will cause a redundant Trains session, I guess.

  
  
Posted 3 years ago

I just need a way to check if the web/app host is configured.

If yes, go ahead. If not, offline/throw an error

  
  
Posted 3 years ago

I want a reliable way, so I don't want to hardcode to check if trains.conf exist in a certain path

  
  
Posted 3 years ago

EnviousStarfish54 you can use Use Task.set_credentials
Notice that OS environment or trains.conf will override the programmatic credentials
https://allegro.ai/docs/task.html#trains.task.Task.set_credentials

  
  
Posted 3 years ago
603 Views
16 Answers
3 years ago
one year ago
Tags
Similar posts