code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def check_predict(db, llm): """Test whether db can call model prediction normally.""" db.apply(llm) result = llm.predict("1+1=") assert isinstance(result, str)
Test whether db can call model prediction normally.
check_predict
python
superduper-io/superduper
test/unittest/ext/llm/utils.py
https://github.com/superduper-io/superduper/blob/master/test/unittest/ext/llm/utils.py
Apache-2.0
def check_llm_as_listener_model(db, llm): """Test whether the model can predict the data in the database normally""" collection_name = "question" db.create(question) datas = [ Document({"question": f"1+{i}=", "id": str(i), '_fold': 'train'}) for i in range(10) ] db[collection_n...
Test whether the model can predict the data in the database normally
check_llm_as_listener_model
python
superduper-io/superduper
test/unittest/ext/llm/utils.py
https://github.com/superduper-io/superduper/blob/master/test/unittest/ext/llm/utils.py
Apache-2.0
def first_container_with_errors(self, errors): """ Returns the first container with errors, otherwise returns None. """ for tab in self.fields: errors_here = any(error in tab for error in errors) if errors_here: return tab return None
Returns the first container with errors, otherwise returns None.
first_container_with_errors
python
django-crispy-forms/django-crispy-forms
crispy_forms/bootstrap.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/bootstrap.py
MIT
def open_target_group_for_form(self, form): """ Makes sure that the first group that should be open is open. This is either the first group with errors or the first group in the container, unless that first group was originally set to active=False. """ target = se...
Makes sure that the first group that should be open is open. This is either the first group with errors or the first group in the container, unless that first group was originally set to active=False.
open_target_group_for_form
python
django-crispy-forms/django-crispy-forms
crispy_forms/bootstrap.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/bootstrap.py
MIT
def render_link(self, template_pack=TEMPLATE_PACK, **kwargs): """ Render the link for the tab-pane. It must be called after render so css_class is updated with active if needed. """ link_template = self.link_template % template_pack return render_to_string(link_template, ...
Render the link for the tab-pane. It must be called after render so css_class is updated with active if needed.
render_link
python
django-crispy-forms/django-crispy-forms
crispy_forms/bootstrap.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/bootstrap.py
MIT
def all(self): """ Returns all layout objects of first level of depth """ self._check_layout() return LayoutSlice(self.layout, slice(0, len(self.layout.fields), 1))
Returns all layout objects of first level of depth
all
python
django-crispy-forms/django-crispy-forms
crispy_forms/helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/helper.py
MIT
def filter(self, *LayoutClasses, max_level=0, greedy=False): """ Returns a LayoutSlice pointing to layout objects of type `LayoutClass` """ self._check_layout() filtered_layout_objects = self.layout.get_layout_objects(LayoutClasses, max_level=max_level, greedy=greedy) re...
Returns a LayoutSlice pointing to layout objects of type `LayoutClass`
filter
python
django-crispy-forms/django-crispy-forms
crispy_forms/helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/helper.py
MIT
def filter_by_widget(self, widget_type): """ Returns a LayoutSlice pointing to fields with widgets of `widget_type` """ self._check_layout_and_form() layout_field_names = self.layout.get_field_names() # Let's filter all fields with widgets like widget_type filter...
Returns a LayoutSlice pointing to fields with widgets of `widget_type`
filter_by_widget
python
django-crispy-forms/django-crispy-forms
crispy_forms/helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/helper.py
MIT
def exclude_by_widget(self, widget_type): """ Returns a LayoutSlice pointing to fields with widgets NOT matching `widget_type` """ self._check_layout_and_form() layout_field_names = self.layout.get_field_names() # Let's exclude all fields with widgets like widget_type ...
Returns a LayoutSlice pointing to fields with widgets NOT matching `widget_type`
exclude_by_widget
python
django-crispy-forms/django-crispy-forms
crispy_forms/helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/helper.py
MIT
def __getitem__(self, key): """ Return a LayoutSlice that makes changes affect the current instance of the layout and not a copy. """ # when key is a string containing the field name if isinstance(key, str): # Django templates access FormHelper attributes usin...
Return a LayoutSlice that makes changes affect the current instance of the layout and not a copy.
__getitem__
python
django-crispy-forms/django-crispy-forms
crispy_forms/helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/helper.py
MIT
def render_layout(self, form, context, template_pack=TEMPLATE_PACK): """ Returns safe html of the rendering of the layout """ form.rendered_fields = set() form.crispy_field_template = self.field_template # This renders the specified Layout strictly html = self.la...
Returns safe html of the rendering of the layout
render_layout
python
django-crispy-forms/django-crispy-forms
crispy_forms/helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/helper.py
MIT
def get_attributes(self, template_pack=TEMPLATE_PACK): """ Used by crispy_forms_tags to get helper attributes """ attrs = self.attrs.copy() if self.attrs else {} if self.form_action: attrs["action"] = self.form_action.strip() if self.form_id: attrs...
Used by crispy_forms_tags to get helper attributes
get_attributes
python
django-crispy-forms/django-crispy-forms
crispy_forms/helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/helper.py
MIT
def __getattr__(self, name): """ This allows us to access self.fields list methods like append or insert, without having to declare them one by one """ # Check necessary for unpickling, see #107 if "fields" in self.__dict__ and hasattr(self.fields, name): retu...
This allows us to access self.fields list methods like append or insert, without having to declare them one by one
__getattr__
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout.py
MIT
def get_layout_objects(self, *LayoutClasses, index=None, max_level=0, greedy=False): """ Returns a list of Pointers pointing to layout objects of any type matching `LayoutClasses`:: [ Pointer([0,1,2], 'div']), Pointer([0,3], 'field_name'), ...
Returns a list of Pointers pointing to layout objects of any type matching `LayoutClasses`:: [ Pointer([0,1,2], 'div']), Pointer([0,3], 'field_name'), ] :param max_level: An integer that indicates max level depth to reach when tr...
get_layout_objects
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout.py
MIT
def render(self, form, context, template_pack=TEMPLATE_PACK, **kwargs): """ Renders an `<input />` if container is used as a Layout object. Input button value can be a variable in context. """ self.value = Template(str(self.value)).render(context) template = self.get_temp...
Renders an `<input />` if container is used as a Layout object. Input button value can be a variable in context.
render
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout.py
MIT
def wrapped_object(self, LayoutClass, fields, *args, **kwargs): """ Returns a layout object of type `LayoutClass` with `args` and `kwargs` that wraps `fields` inside. """ if args: if isinstance(fields, list): fields = tuple(fields) else: ...
Returns a layout object of type `LayoutClass` with `args` and `kwargs` that wraps `fields` inside.
wrapped_object
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout_slice.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout_slice.py
MIT
def pre_map(self, function): """ Iterates over layout objects pointed in `self.slice` executing `function` on them. It passes `function` penultimate layout object and the position where to find last one """ if isinstance(self.slice, slice): for i in range(*self.slice....
Iterates over layout objects pointed in `self.slice` executing `function` on them. It passes `function` penultimate layout object and the position where to find last one
pre_map
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout_slice.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout_slice.py
MIT
def wrap(self, LayoutClass, *args, **kwargs): """ Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with `args` and `kwargs` passed. """ def wrap_object(layout_object, j): layout_object.fields[j] = self.wrapped_object(LayoutClass, layou...
Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with `args` and `kwargs` passed.
wrap
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout_slice.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout_slice.py
MIT
def wrap_once(self, LayoutClass, *args, **kwargs): """ Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with `args` and `kwargs` passed, unless layout object's parent is already a subclass of `LayoutClass`. """ def wrap_object_once(layout_...
Wraps every layout object pointed in `self.slice` under a `LayoutClass` instance with `args` and `kwargs` passed, unless layout object's parent is already a subclass of `LayoutClass`.
wrap_once
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout_slice.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout_slice.py
MIT
def wrap_together(self, LayoutClass, *args, **kwargs): """ Wraps all layout objects pointed in `self.slice` together under a `LayoutClass` instance with `args` and `kwargs` passed. """ if isinstance(self.slice, slice): # The start of the slice is replaced ...
Wraps all layout objects pointed in `self.slice` together under a `LayoutClass` instance with `args` and `kwargs` passed.
wrap_together
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout_slice.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout_slice.py
MIT
def map(self, function): """ Iterates over layout objects pointed in `self.slice` executing `function` on them It passes `function` last layout object """ if isinstance(self.slice, slice): for i in range(*self.slice.indices(len(self.layout.fields))): f...
Iterates over layout objects pointed in `self.slice` executing `function` on them It passes `function` last layout object
map
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout_slice.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout_slice.py
MIT
def update_attributes(self, **original_kwargs): """ Updates attributes of every layout object pointed in `self.slice` using kwargs """ def update_attrs(layout_object): kwargs = original_kwargs.copy() if hasattr(layout_object, "attrs"): if "css_cla...
Updates attributes of every layout object pointed in `self.slice` using kwargs
update_attributes
python
django-crispy-forms/django-crispy-forms
crispy_forms/layout_slice.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/layout_slice.py
MIT
def render_field( field, form, context, template=None, labelclass=None, layout_object=None, attrs=None, template_pack=TEMPLATE_PACK, extra_context=None, **kwargs, ): """ Renders a django-crispy-forms field :param field: Can be a string or a Layout object like `Row`. ...
Renders a django-crispy-forms field :param field: Can be a string or a Layout object like `Row`. If it's a layout object, we call its render method, otherwise we instantiate a BoundField and render it using default template 'CRISPY_TEMPLATE_PACK/field.html' The field is added to a list...
render_field
python
django-crispy-forms/django-crispy-forms
crispy_forms/utils.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/utils.py
MIT
def render_crispy_form(form, helper=None, context=None): """ Renders a form and returns its HTML output. This function wraps the template logic in a function easy to use in a Django view. """ from crispy_forms.templatetags.crispy_forms_tags import CrispyFormNode if helper is not None: ...
Renders a form and returns its HTML output. This function wraps the template logic in a function easy to use in a Django view.
render_crispy_form
python
django-crispy-forms/django-crispy-forms
crispy_forms/utils.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/utils.py
MIT
def list_difference(left, right): """ Take the not-in-place difference of two lists (left - right), similar to sets but preserving order. """ blocked = set(right) difference = [] for item in left: if item not in blocked: blocked.add(item) difference.append(item) ...
Take the not-in-place difference of two lists (left - right), similar to sets but preserving order.
list_difference
python
django-crispy-forms/django-crispy-forms
crispy_forms/utils.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/utils.py
MIT
def crispy_addon(field, append="", prepend="", form_show_labels=True): """ Renders a form field using bootstrap's prepended or appended text:: {% crispy_addon form.my_field prepend="$" append=".00" %} You can also just prepend or append like so {% crispy_addon form.my_field prepend="$" %}...
Renders a form field using bootstrap's prepended or appended text:: {% crispy_addon form.my_field prepend="$" append=".00" %} You can also just prepend or append like so {% crispy_addon form.my_field prepend="$" %} {% crispy_addon form.my_field append=".00" %}
crispy_addon
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_field.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_field.py
MIT
def as_crispy_form(form, template_pack=TEMPLATE_PACK, label_class="", field_class=""): """ The original and still very useful way to generate a div elegant form/formset:: {% load crispy_forms_tags %} <form class="my-class" method="post"> {% csrf_token %} {{ myform|crisp...
The original and still very useful way to generate a div elegant form/formset:: {% load crispy_forms_tags %} <form class="my-class" method="post"> {% csrf_token %} {{ myform|crispy }} </form> or, if you want to explicitly set the template pack:: {{ my...
as_crispy_form
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_filters.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_filters.py
MIT
def as_crispy_errors(form, template_pack=TEMPLATE_PACK): """ Renders only form errors the same way as django-crispy-forms:: {% load crispy_forms_tags %} {{ form|as_crispy_errors }} or:: {{ form|as_crispy_errors:"bootstrap4" }} """ if isinstance(form, BaseFormSet): ...
Renders only form errors the same way as django-crispy-forms:: {% load crispy_forms_tags %} {{ form|as_crispy_errors }} or:: {{ form|as_crispy_errors:"bootstrap4" }}
as_crispy_errors
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_filters.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_filters.py
MIT
def as_crispy_field(field, template_pack=TEMPLATE_PACK, label_class="", field_class=""): """ Renders a form field like a django-crispy-forms field:: {% load crispy_forms_tags %} {{ form.field|as_crispy_field }} or:: {{ form.field|as_crispy_field:"bootstrap4" }} """ if not ...
Renders a form field like a django-crispy-forms field:: {% load crispy_forms_tags %} {{ form.field|as_crispy_field }} or:: {{ form.field|as_crispy_field:"bootstrap4" }}
as_crispy_field
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_filters.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_filters.py
MIT
def optgroups(field): """ A template filter to help rendering of fields with optgroups. Returns: A tuple of label, option, index label: Group label for grouped optgroups (`None` if inputs are not grouped). option: A dict containing information to render the option::...
A template filter to help rendering of fields with optgroups. Returns: A tuple of label, option, index label: Group label for grouped optgroups (`None` if inputs are not grouped). option: A dict containing information to render the option:: { ...
optgroups
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_filters.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_filters.py
MIT
def iterate(self): """ Updates values as if we had iterated over the for """ self.counter += 1 self.counter0 += 1 self.revcounter -= 1 self.revcounter0 -= 1 self.first = False self.last = self.revcounter0 == self.len_values - 1
Updates values as if we had iterated over the for
iterate
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_tags.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_tags.py
MIT
def get_render(self, context): """ Returns a `Context` object with all the necessary stuff for rendering the form :param context: `django.template.Context` variable holding the context for the node `self.form` and `self.helper` are resolved into real Python objects resolving them ...
Returns a `Context` object with all the necessary stuff for rendering the form :param context: `django.template.Context` variable holding the context for the node `self.form` and `self.helper` are resolved into real Python objects resolving them from the `context`. The `actual_form` c...
get_render
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_tags.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_tags.py
MIT
def get_response_dict(self, helper, context, is_formset): """ Returns a dictionary with all the parameters necessary to render the form/formset in a template. :param context: `django.template.Context` for the node :param is_formset: Boolean value. If set to True, indicates we are workin...
Returns a dictionary with all the parameters necessary to render the form/formset in a template. :param context: `django.template.Context` for the node :param is_formset: Boolean value. If set to True, indicates we are working with a formset.
get_response_dict
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_tags.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_tags.py
MIT
def do_uni_form(parser, token): """ You need to pass in at least the form/formset object, and can also pass in the optional `crispy_forms.helpers.FormHelper` object. helper (optional): A `crispy_forms.helper.FormHelper` object. Usage:: {% load crispy_tags %} {% crispy form form.he...
You need to pass in at least the form/formset object, and can also pass in the optional `crispy_forms.helpers.FormHelper` object. helper (optional): A `crispy_forms.helper.FormHelper` object. Usage:: {% load crispy_tags %} {% crispy form form.helper %} You can also provide the t...
do_uni_form
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_tags.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_tags.py
MIT
def specialspaceless(parser, token): """ Removes whitespace between HTML tags, and introduces a whitespace after buttons an inputs, necessary for Bootstrap to place them correctly in the layout. """ nodelist = parser.parse(("endspecialspaceless",)) parser.delete_first_token() return Spe...
Removes whitespace between HTML tags, and introduces a whitespace after buttons an inputs, necessary for Bootstrap to place them correctly in the layout.
specialspaceless
python
django-crispy-forms/django-crispy-forms
crispy_forms/templatetags/crispy_forms_utils.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templatetags/crispy_forms_utils.py
MIT
def test_passthrough_context(): """ Test to ensure that context is passed through implicitly from outside of the crispy form into the crispy form templates. """ form = SampleForm() form.helper.template = "custom_form_template_with_context.html" c = {"prefix": "foo", "suffix": "bar"} ht...
Test to ensure that context is passed through implicitly from outside of the crispy form into the crispy form templates.
test_passthrough_context
python
django-crispy-forms/django-crispy-forms
tests/test_form_helper.py
https://github.com/django-crispy-forms/django-crispy-forms/blob/master/tests/test_form_helper.py
MIT
def generate_share_image(distance, pace, time, date, client): """ Generates a share image with the given parameters. Args: distance: Distance of the run. pace: Pace of the run. time: Time taken for the run. date: Date of the run. """ base_prompt = "Create a running s...
Generates a share image with the given parameters. Args: distance: Distance of the run. pace: Pace of the run. time: Time taken for the run. date: Date of the run.
generate_share_image
python
yihong0618/running_page
run_page/auto_share_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/auto_share_sync.py
MIT
def generate_route_svg( polyline_str, output_filename=DEFAULT_OUTPUT_FILENAME, format="png" ): """ Generates a route visualization from a polyline string. Args: polyline_str: The encoded polyline string. output_filename: The base filename for the output file (without extension). ...
Generates a route visualization from a polyline string. Args: polyline_str: The encoded polyline string. output_filename: The base filename for the output file (without extension). format: Output format, either 'svg' or 'png'.
generate_route_svg
python
yihong0618/running_page
run_page/auto_share_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/auto_share_sync.py
MIT
def run_auto_sync(client, format="svg", date=None): """ if date is None, get the latest activity """ generator = Generator(SQL_FILE) activities_list = generator.load() if date: activity = next( ( activity for activity in activities_list ...
if date is None, get the latest activity
run_auto_sync
python
yihong0618/running_page
run_page/auto_share_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/auto_share_sync.py
MIT
def tcx_output(fit_array, run_data): """ If you want to make a more detailed tcx file, please refer to oppo_sync.py """ # route ID fit_id = str(run_data["id"]) # local time fit_start_time_local = run_data["start_time"] # zulu time utc = adjust_time_to_utc(to_date(fit_start_time_local...
If you want to make a more detailed tcx file, please refer to oppo_sync.py
tcx_output
python
yihong0618/running_page
run_page/codoon_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/codoon_sync.py
MIT
def do_wrap_device_info(origin_file): """ add customized device info to fit file, """ # if origin file is gpx file, skip if not is_fit_file(origin_file): return BytesIO(origin_file.read()) fit_file = FitFile.from_bytes(origin_file.read()) builder = FitFileBuilder(auto_define=True) ...
add customized device info to fit file,
do_wrap_device_info
python
yihong0618/running_page
run_page/garmin_device_adaptor.py
https://github.com/yihong0618/running_page/blob/master/run_page/garmin_device_adaptor.py
MIT
def get_to_generate_files(last_time): """ return to values one dict for upload and one sorted list for next time upload """ file_names = os.listdir(GPX_FOLDER) gpx_files = [] for f in file_names: if f.endswith(".gpx"): file_path = os.path.join(GPX_FOLDER, f) w...
return to values one dict for upload and one sorted list for next time upload
get_to_generate_files
python
yihong0618/running_page
run_page/gpx_to_strava_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpx_to_strava_sync.py
MIT
def parse_points_to_gpx( run_points_data, start_time, end_time, pause_list, heart_rate_data_string, altitude_data_string, interval=5, ): """ parse run_data content to gpx object TODO for now kind of same as `keep` maybe refactor later ...
parse run_data content to gpx object TODO for now kind of same as `keep` maybe refactor later :param run_points_data: [[latitude, longitude],...] :param pause_list: [[interval_index, pause_seconds],...] :param heart_rate_data_string: heart rate list in string...
parse_points_to_gpx
python
yihong0618/running_page
run_page/joyrun_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/joyrun_sync.py
MIT
def generate_gpx(title, latitude_data, longitude_data, elevation_data, heart_rate_data): """ Parses the latitude, longitude and elevation data to generate a GPX document Args: title: the title of the GPX document latitude_data: A list of dictionaries containing latitude data longitud...
Parses the latitude, longitude and elevation data to generate a GPX document Args: title: the title of the GPX document latitude_data: A list of dictionaries containing latitude data longitude_data: A list of dictionaries containing longitude data elevation_data: A list of dicti...
generate_gpx
python
yihong0618/running_page
run_page/nike_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/nike_sync.py
MIT
def update_points(points, update_data, update_name): """ Update the points dict list so that can easy create GPXTrackPoint Args: points: basic points list update_data: attr to update points which is a list update_name: attr name Returns: No...
Update the points dict list so that can easy create GPXTrackPoint Args: points: basic points list update_data: attr to update points which is a list update_name: attr name Returns: None (just update the points list)
update_points
python
yihong0618/running_page
run_page/nike_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/nike_sync.py
MIT
def parse_activity_data(activity): """ Parses a NRC activity and returns GPX XML Args: activity: a json document for a NRC activity Returns: gpx: the GPX XML doc for the input activity """ lat_index = None lon_index = None elevation_index = None heart_rate_index = No...
Parses a NRC activity and returns GPX XML Args: activity: a json document for a NRC activity Returns: gpx: the GPX XML doc for the input activity
parse_activity_data
python
yihong0618/running_page
run_page/nike_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/nike_sync.py
MIT
def map_oppo_fit_type_to_strava_activity_type(oppo_type): """ Note: should consider the supported strava activity type: Link: https://developers.strava.com/docs/reference/#api-models-ActivityType """ for case in switch(oppo_type): if case(1): # WALK return "Walk" if case...
Note: should consider the supported strava activity type: Link: https://developers.strava.com/docs/reference/#api-models-ActivityType
map_oppo_fit_type_to_strava_activity_type
python
yihong0618/running_page
run_page/oppo_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/oppo_sync.py
MIT
def prepare_track_points(sport_data, with_gpx): """ Convert run points data to GPX format. Args: sport_data (map of dict): A map of run data points. with_gpx (boolean): export to gpx file or not. Returns: points_dict_list (list): data with need to parse. """ other_data ...
Convert run points data to GPX format. Args: sport_data (map of dict): A map of run data points. with_gpx (boolean): export to gpx file or not. Returns: points_dict_list (list): data with need to parse.
prepare_track_points
python
yihong0618/running_page
run_page/oppo_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/oppo_sync.py
MIT
def get_to_generate_files(last_time): """ return to one sorted list for next time upload """ file_names = os.listdir(TCX_FOLDER) tcx = TCXReader() tcx_files = [ ( tcx.read(os.path.join(TCX_FOLDER, i), only_gps=False), os.path.join(TCX_FOLDER, i), ) ...
return to one sorted list for next time upload
get_to_generate_files
python
yihong0618/running_page
run_page/tcx_to_garmin_sync.py
https://github.com/yihong0618/running_page/blob/master/run_page/tcx_to_garmin_sync.py
MIT
def get_strava_last_time(client, is_milliseconds=True): """ if there is no activities cause exception return 0 """ try: activity = None activities = client.get_activities(limit=10) activities = list(activities) activities.sort(key=lambda x: x.start_date, reverse=True) ...
if there is no activities cause exception return 0
get_strava_last_time
python
yihong0618/running_page
run_page/utils.py
https://github.com/yihong0618/running_page/blob/master/run_page/utils.py
MIT
def sync(self, force): """ Sync activities means sync from strava TODO, better name later """ self.check_access() print("Start syncing") if force: filters = {"before": datetime.datetime.utcnow()} else: last_activity = self.session....
Sync activities means sync from strava TODO, better name later
sync
python
yihong0618/running_page
run_page/generator/__init__.py
https://github.com/yihong0618/running_page/blob/master/run_page/generator/__init__.py
MIT
def __init__(self, the_poster: Poster): """Init the CircularDrawer with default values for _rings and _ring_color Note that these can be overridden via arguments when calling.""" super().__init__(the_poster) self._rings = False self._ring_color = "darkgrey"
Init the CircularDrawer with default values for _rings and _ring_color Note that these can be overridden via arguments when calling.
__init__
python
yihong0618/running_page
run_page/gpxtrackposter/circular_drawer.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/circular_drawer.py
MIT
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): """Draw the circular Poster using distances broken down by time""" if self.poster.tracks is None: raise PosterError("No tracks to draw.") if self.poster.length_range_by_date is None: return years = self....
Draw the circular Poster using distances broken down by time
draw
python
yihong0618/running_page
run_page/gpxtrackposter/circular_drawer.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/circular_drawer.py
MIT
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): """For each track, draw it on the poster.""" if self.poster.tracks is None: raise PosterError("No tracks to draw.") cell_size, counts = compute_grid(len(self.poster.tracks), size) if cell_size is None or counts is No...
For each track, draw it on the poster.
draw
python
yihong0618/running_page
run_page/gpxtrackposter/grid_drawer.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/grid_drawer.py
MIT
def set_tracks(self, tracks): """Associate the set of tracks with this poster. In addition to setting self.tracks, also compute the necessary attributes for the Poster based on this set of tracks. """ self.tracks = tracks self.tracks_by_date = {} self.length_rang...
Associate the set of tracks with this poster. In addition to setting self.tracks, also compute the necessary attributes for the Poster based on this set of tracks.
set_tracks
python
yihong0618/running_page
run_page/gpxtrackposter/poster.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/poster.py
MIT
def draw(self, drawer, output): """Set the Poster's drawer and draw the tracks.""" self.tracks_drawer = drawer height = self.height width = self.width if self.drawer_type == "plain": height = height - 100 self.colors["background"] = "#1a1a1a" s...
Set the Poster's drawer and draw the tracks.
draw
python
yihong0618/running_page
run_page/gpxtrackposter/poster.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/poster.py
MIT
def m2u(self, m): """Convert meters to kilometers or miles, according to units.""" if self.units == "metric": return 0.001 * m return 0.001 * m / 1.609344
Convert meters to kilometers or miles, according to units.
m2u
python
yihong0618/running_page
run_page/gpxtrackposter/poster.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/poster.py
MIT
def u(self): """Return the unit of distance being used on the Poster.""" if self.units == "metric": return "km" return "mi"
Return the unit of distance being used on the Poster.
u
python
yihong0618/running_page
run_page/gpxtrackposter/poster.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/poster.py
MIT
def load_gpx(self, file_name): """ TODO refactor with load_tcx to one function """ try: self.file_names = [os.path.basename(file_name)] # Handle empty gpx files # (for example, treadmill runs pulled via garmin-connect-export) if os.path.get...
TODO refactor with load_tcx to one function
load_gpx
python
yihong0618/running_page
run_page/gpxtrackposter/track.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/track.py
MIT
def bbox(self): """Compute the smallest rectangle that contains the entire track (border box).""" bbox = s2.LatLngRect() for line in self.polylines: for latlng in line: bbox = bbox.union(s2.LatLngRect.from_point(latlng.normalized())) return bbox
Compute the smallest rectangle that contains the entire track (border box).
bbox
python
yihong0618/running_page
run_page/gpxtrackposter/track.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/track.py
MIT
def _load_gpx_extensions_item(self, gpx, item_name): """ Load a specific extension item from the GPX file. This is used to load specific data like distance, average speed, etc. """ gpx_extensions = ( {} if gpx.extensions is None else { ...
Load a specific extension item from the GPX file. This is used to load specific data like distance, average speed, etc.
_load_gpx_extensions_item
python
yihong0618/running_page
run_page/gpxtrackposter/track.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/track.py
MIT
def load_gpx_file(file_name, activity_title_dict={}): """Load an individual GPX file as a track by using Track.load_gpx()""" t = Track() t.load_gpx(file_name) file_id = os.path.basename(file_name).split(".")[0] if activity_title_dict: t.track_name = activity_title_dict.get(file_id, t.track_n...
Load an individual GPX file as a track by using Track.load_gpx()
load_gpx_file
python
yihong0618/running_page
run_page/gpxtrackposter/track_loader.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/track_loader.py
MIT
def load_tcx_file(file_name, activity_title_dict={}): """Load an individual TCX file as a track by using Track.load_tcx()""" t = Track() t.load_tcx(file_name) file_id = os.path.basename(file_name).split(".")[0] if activity_title_dict: t.track_name = activity_title_dict.get(file_id, t.track_n...
Load an individual TCX file as a track by using Track.load_tcx()
load_tcx_file
python
yihong0618/running_page
run_page/gpxtrackposter/track_loader.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/track_loader.py
MIT
def load_fit_file(file_name, activity_title_dict={}): """Load an individual FIT file as a track by using Track.load_fit()""" t = Track() t.load_fit(file_name) file_id = os.path.basename(file_name).split(".")[0] if activity_title_dict: t.track_name = activity_title_dict.get(file_id, t.track_n...
Load an individual FIT file as a track by using Track.load_fit()
load_fit_file
python
yihong0618/running_page
run_page/gpxtrackposter/track_loader.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/track_loader.py
MIT
def load_tracks(self, data_dir, file_suffix="gpx", activity_title_dict={}): """Load tracks data_dir and return as a List of tracks""" file_names = [x for x in self._list_data_files(data_dir, file_suffix)] print(f"{file_suffix.upper()} files: {len(file_names)}") tracks = [] load...
Load tracks data_dir and return as a List of tracks
load_tracks
python
yihong0618/running_page
run_page/gpxtrackposter/track_loader.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/track_loader.py
MIT
def __init__(self): """Inits YearRange with empty bounds -- to be built after init""" self.from_year = None self.to_year = None self.years_dict = dict()
Inits YearRange with empty bounds -- to be built after init
__init__
python
yihong0618/running_page
run_page/gpxtrackposter/year_range.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/year_range.py
MIT
def parse(self, s: str) -> bool: """Parse a plaintext range of years into a pair of years Attempt to turn the input string into a pair of year values, from_year and to_year. If one year is passed, both from_year and to_year will be set to that year. If a range like '2016-2018' is passed...
Parse a plaintext range of years into a pair of years Attempt to turn the input string into a pair of year values, from_year and to_year. If one year is passed, both from_year and to_year will be set to that year. If a range like '2016-2018' is passed, from_year will be set to 2016, and to_year...
parse
python
yihong0618/running_page
run_page/gpxtrackposter/year_range.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/year_range.py
MIT
def add(self, t: datetime.datetime): """For the given t, update from_year and to_year to include that timestamp""" if self.from_year is None: self.from_year = t.year self.to_year = t.year elif t.year < self.from_year: self.from_year = t.year elif t.yea...
For the given t, update from_year and to_year to include that timestamp
add
python
yihong0618/running_page
run_page/gpxtrackposter/year_range.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/year_range.py
MIT
def contains(self, t: datetime.datetime) -> bool: """Return True if current year range contains t, False if not""" if self.from_year is None: return True return self.from_year <= t.year <= self.to_year
Return True if current year range contains t, False if not
contains
python
yihong0618/running_page
run_page/gpxtrackposter/year_range.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/year_range.py
MIT
def count(self) -> Optional[int]: """Return number of years contained in the current range""" if self.from_year is None: return None return 1 + self.to_year - self.from_year
Return number of years contained in the current range
count
python
yihong0618/running_page
run_page/gpxtrackposter/year_range.py
https://github.com/yihong0618/running_page/blob/master/run_page/gpxtrackposter/year_range.py
MIT
def create_app(config_object=ProdConfig): """An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/. :param config_object: The configuration object to use. """ app = Flask(__name__.split('.')[0]) app.url_map.strict_slashes = False app.config.from_objec...
An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/. :param config_object: The configuration object to use.
create_app
python
gothinkster/flask-realworld-example-app
conduit/app.py
https://github.com/gothinkster/flask-realworld-example-app/blob/master/conduit/app.py
MIT
def clean_build_folders(): """clean build and *.egg-info folders before compiling""" path = os.getcwd() _ = os.listdir(path) rm_src = ['build', '*.egg-info'] _exists = [glob.glob(os.path.join(path, _)) for _ in rm_src] exists = [item[0] for item in _exists if len(item) > 0] for rm_item in ex...
clean build and *.egg-info folders before compiling
clean_build_folders
python
CubicZebra/informatics
setup.py
https://github.com/CubicZebra/informatics/blob/master/setup.py
Apache-2.0
def get_title() -> Text: """Get the title, with a rainbow effect.""" lines = TITLE.splitlines(keepends=True) return Text.assemble(*zip(lines, COLORS))
Get the title, with a rainbow effect.
get_title
python
Textualize/toolong
src/toolong/help.py
https://github.com/Textualize/toolong/blob/master/src/toolong/help.py
MIT
def scan_line_breaks( self, batch_time: float = 0.25 ) -> Iterable[tuple[int, list[int]]]: """Scan the file for line breaks. Args: batch_time: Time to group the batches. Returns: An iterable of tuples, containing the scan position and a list of offsets of ne...
Scan the file for line breaks. Args: batch_time: Time to group the batches. Returns: An iterable of tuples, containing the scan position and a list of offsets of new lines.
scan_line_breaks
python
Textualize/toolong
src/toolong/log_file.py
https://github.com/Textualize/toolong/blob/master/src/toolong/log_file.py
MIT
def size_changed(size: int, breaks: list[int]) -> None: """Callback when the file changes size.""" with self._lock: for offset, _ in enumerate(breaks, 1): self.get_line_from_index(self.line_count - offset) self.post_message(NewBreaks(self.log_file,...
Callback when the file changes size.
size_changed
python
Textualize/toolong
src/toolong/log_lines.py
https://github.com/Textualize/toolong/blob/master/src/toolong/log_lines.py
MIT
def _scan_file( cls, fileno: int, size: int, batch_time: float = 0.25 ) -> Iterable[tuple[int, list[int]]]: """Find line breaks in a file. Yields lists of offsets. """ if platform.system() == "Windows": log_mmap = mmap.mmap(fileno, size, access=mmap.ACCESS_READ) ...
Find line breaks in a file. Yields lists of offsets.
_scan_file
python
Textualize/toolong
src/toolong/log_lines.py
https://github.com/Textualize/toolong/blob/master/src/toolong/log_lines.py
MIT
def save(self, path: str, line_count: int) -> None: """Save visible lines (used to export merged lines). Args: path: Path to save to. line_count: Number of lines to save. """ try: with open(path, "w") as file_out: for line_no in range(...
Save visible lines (used to export merged lines). Args: path: Path to save to. line_count: Number of lines to save.
save
python
Textualize/toolong
src/toolong/log_lines.py
https://github.com/Textualize/toolong/blob/master/src/toolong/log_lines.py
MIT
def get_timestamp(self, line_index: int) -> datetime | None: """Get a timestamp for the given line, or `None` if no timestamp detected. Args: line_index: Index of line. Returns: A datetime or `None`. """ log_file, start, end = self.index_to_span(line_ind...
Get a timestamp for the given line, or `None` if no timestamp detected. Args: line_index: Index of line. Returns: A datetime or `None`.
get_timestamp
python
Textualize/toolong
src/toolong/log_lines.py
https://github.com/Textualize/toolong/blob/master/src/toolong/log_lines.py
MIT
def scan(self, line: str) -> datetime | None: """Scan a line. Args: line: A log line with a timestamp. Returns: A datetime or `None` if no timestamp was found. """ if len(line) > 10_000: line = line[:10000] for index, timestamp_format...
Scan a line. Args: line: A log line with a timestamp. Returns: A datetime or `None` if no timestamp was found.
scan
python
Textualize/toolong
src/toolong/timestamps.py
https://github.com/Textualize/toolong/blob/master/src/toolong/timestamps.py
MIT
def get_watcher() -> WatcherBase: """Return an Watcher appropriate for the OS.""" if platform.system() == "Darwin": from toolong.selector_watcher import SelectorWatcher return SelectorWatcher() else: from toolong.poll_watcher import PollWatcher return PollWatcher()
Return an Watcher appropriate for the OS.
get_watcher
python
Textualize/toolong
src/toolong/watcher.py
https://github.com/Textualize/toolong/blob/master/src/toolong/watcher.py
MIT
def scan_chunk(cls, chunk: bytes, position: int) -> list[int]: """Scan line breaks in a binary chunk, Args: chunk: A binary chunk. position: Offset within the file Returns: A list of indices with new lines. """ breaks: list[int] = [] ...
Scan line breaks in a binary chunk, Args: chunk: A binary chunk. position: Offset within the file Returns: A list of indices with new lines.
scan_chunk
python
Textualize/toolong
src/toolong/watcher.py
https://github.com/Textualize/toolong/blob/master/src/toolong/watcher.py
MIT
def __init__(self, uri): """ Initializes the deployment plugin, sets the triton model repo """ super(TritonPlugin, self).__init__(target_uri=uri) self.server_config = Config() triton_url, self.triton_model_repo = self._get_triton_server_config() # need to add othe...
Initializes the deployment plugin, sets the triton model repo
__init__
python
triton-inference-server/server
deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
BSD-3-Clause
def create_deployment(self, name, model_uri, flavor=None, config=None): """ Deploy the model at the model_uri to the Triton model repo. Associated config.pbtxt and *labels* files will be deployed. :param name: Name of the of the model :param model_uri: Model uri in format model:/<model-...
Deploy the model at the model_uri to the Triton model repo. Associated config.pbtxt and *labels* files will be deployed. :param name: Name of the of the model :param model_uri: Model uri in format model:/<model-name>/<version-or-stage> :param flavor: Flavor of the deployed model ...
create_deployment
python
triton-inference-server/server
deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
BSD-3-Clause
def delete_deployment(self, name): """ Delete the deployed model in Triton with the provided model name :param name: Name of the of the model with version number. For ex: "densenet_onnx/2" :return: None """ # Verify model is already deployed to Triton if not sel...
Delete the deployed model in Triton with the provided model name :param name: Name of the of the model with version number. For ex: "densenet_onnx/2" :return: None
delete_deployment
python
triton-inference-server/server
deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
BSD-3-Clause
def update_deployment(self, name, model_uri=None, flavor=None, config=None): """ Update the model deployment in triton with the provided name :param name: Name and version number of the model, <model_name>/<version>. :param model_uri: Model uri models:/model_name/version :param ...
Update the model deployment in triton with the provided name :param name: Name and version number of the model, <model_name>/<version>. :param model_uri: Model uri models:/model_name/version :param flavor: The flavor of the model :param config: Configuration parameters ...
update_deployment
python
triton-inference-server/server
deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
BSD-3-Clause
def list_deployments(self): """ List models deployed to Triton. :return: None """ resp = self.triton_client.get_model_repository_index() actives = [] for d in resp: if "state" in d and d["state"] == "READY": mlflow_meta_path = os.path....
List models deployed to Triton. :return: None
list_deployments
python
triton-inference-server/server
deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
BSD-3-Clause
def get_deployment(self, name): """ Get deployment from Triton. :param name: Name of the model. \n Ex: "mini_bert_onnx" - gets the details of active version of this model \n :return: output - Returns a dict with model info """ deployments = self.lis...
Get deployment from Triton. :param name: Name of the model. Ex: "mini_bert_onnx" - gets the details of active version of this model :return: output - Returns a dict with model info
get_deployment
python
triton-inference-server/server
deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
BSD-3-Clause
def _walk(self, path): """Walk a path like os.walk() if path is dir, return file in the expected format otherwise. :param path: dir or file path :return: root, dirs, files """ if os.path.isfile(path): return [(os.path.dirname(path), [], [os.path.basename(path...
Walk a path like os.walk() if path is dir, return file in the expected format otherwise. :param path: dir or file path :return: root, dirs, files
_walk
python
triton-inference-server/server
deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
BSD-3-Clause
def save_model( triton_model_path, path, mlflow_model=None, ): """ Save an Triton model to a path on the local file system. :param triton_model_path: File path to Triton model to be saved. :param path: Local path where the model is to be saved. :param mlflow_model: :py:mod:`mlflow.model...
Save an Triton model to a path on the local file system. :param triton_model_path: File path to Triton model to be saved. :param path: Local path where the model is to be saved. :param mlflow_model: :py:mod:`mlflow.models.Model` this flavor is being added to.
save_model
python
triton-inference-server/server
deploy/mlflow-triton-plugin/scripts/triton_flavor.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/scripts/triton_flavor.py
BSD-3-Clause
def log_model( triton_model_path, artifact_path, registered_model_name=None, await_registration_for=DEFAULT_AWAIT_MAX_SLEEP_SECONDS, ): """ Log an Triton model as an MLflow artifact for the current run. :param triton_model_path: File path to Triton model. :param artifact_path: Run-relat...
Log an Triton model as an MLflow artifact for the current run. :param triton_model_path: File path to Triton model. :param artifact_path: Run-relative artifact path. :param registered_model_name: (Experimental) If given, create a model version under ``registered_model...
log_model
python
triton-inference-server/server
deploy/mlflow-triton-plugin/scripts/triton_flavor.py
https://github.com/triton-inference-server/server/blob/master/deploy/mlflow-triton-plugin/scripts/triton_flavor.py
BSD-3-Clause
def setup_logger(): """ This function is to setup logging """ # Create a custom logger logger = logging.getLogger(__name__) # Set the log level logger.setLevel(logging.INFO) # Create handlers file_handler = logging.FileHandler("/tmp/docs.log") # Create formatters and add it to th...
This function is to setup logging
setup_logger
python
triton-inference-server/server
docs/generate_docs.py
https://github.com/triton-inference-server/server/blob/master/docs/generate_docs.py
BSD-3-Clause
def log_message(message): """ This function is for logging to /tmp - message: Message to log """ # Setup the logger logger = setup_logger() # Log the message logger.info(message)
This function is for logging to /tmp - message: Message to log
log_message
python
triton-inference-server/server
docs/generate_docs.py
https://github.com/triton-inference-server/server/blob/master/docs/generate_docs.py
BSD-3-Clause
def run_command(command): """ This function runs any command using subprocess and logs failures - command: Command to execute """ log_message(f"Running command: {command}") try: subprocess.run( command, shell=True, check=True, text=True, ...
This function runs any command using subprocess and logs failures - command: Command to execute
run_command
python
triton-inference-server/server
docs/generate_docs.py
https://github.com/triton-inference-server/server/blob/master/docs/generate_docs.py
BSD-3-Clause
def clone_from_github(repo, tag, org): """ This function clones from github, in-sync with build.py - repo: Repo Name - tag: Tag Name - org: Org Name """ # Construct the full GitHub repository URL repo_url = f"https://github.com/{org}/{repo}.git" # Construct the git clone command ...
This function clones from github, in-sync with build.py - repo: Repo Name - tag: Tag Name - org: Org Name
clone_from_github
python
triton-inference-server/server
docs/generate_docs.py
https://github.com/triton-inference-server/server/blob/master/docs/generate_docs.py
BSD-3-Clause
def replace_url_with_relpath(url, src_doc_path): """ This function replaces Triton Inference Server GitHub URLs with relative paths in following cases. 1. URL is a doc file, e.g. ".md" file. 2. URL is a directory which contains README.md and URL ends with "#<section>". Examples: https://git...
This function replaces Triton Inference Server GitHub URLs with relative paths in following cases. 1. URL is a doc file, e.g. ".md" file. 2. URL is a directory which contains README.md and URL ends with "#<section>". Examples: https://github.com/triton-inference-server/server/blob/main/docs/pr...
replace_url_with_relpath
python
triton-inference-server/server
docs/generate_docs.py
https://github.com/triton-inference-server/server/blob/master/docs/generate_docs.py
BSD-3-Clause
def replace_relpath_with_url(relpath, src_doc_path): """ This function replaces relative paths with Triton Inference Server GitHub URLs in following cases. 1. Relative path is a file that is not ".md" type inside the current repo. 2. Relative path is a directory but not (has "README.md" and ends with "#...
This function replaces relative paths with Triton Inference Server GitHub URLs in following cases. 1. Relative path is a file that is not ".md" type inside the current repo. 2. Relative path is a directory but not (has "README.md" and ends with "#<section>"). 3. Relative path does not exist (shows 404 ...
replace_relpath_with_url
python
triton-inference-server/server
docs/generate_docs.py
https://github.com/triton-inference-server/server/blob/master/docs/generate_docs.py
BSD-3-Clause
def replace_hyperlink(m, src_doc_path): """ TODO: Support of HTML tags for future docs. Markdown allows <link>, e.g. <a href=[^>]+>. Whether we want to find and replace the link depends on if they link to internal .md files or allows relative paths. I haven't seen one such case in our doc so sho...
TODO: Support of HTML tags for future docs. Markdown allows <link>, e.g. <a href=[^>]+>. Whether we want to find and replace the link depends on if they link to internal .md files or allows relative paths. I haven't seen one such case in our doc so should be safe for now.
replace_hyperlink
python
triton-inference-server/server
docs/generate_docs.py
https://github.com/triton-inference-server/server/blob/master/docs/generate_docs.py
BSD-3-Clause
def execute(self, requests): """This function is called on inference request.""" responses = [] for request in requests: in_0 = pb_utils.get_input_tensor_by_name(request, "INPUT0") out_tensor_0 = pb_utils.Tensor("OUTPUT0", in_0.as_numpy()) responses.append(pb...
This function is called on inference request.
execute
python
triton-inference-server/server
docs/examples/model_repository/simple_identity/1/model.py
https://github.com/triton-inference-server/server/blob/master/docs/examples/model_repository/simple_identity/1/model.py
BSD-3-Clause
def chat( self, request: CreateChatCompletionRequest ) -> CreateChatCompletionResponse | Iterator[str]: """ If request.stream is True, this returns an Iterator (or Generator) that produces server-sent-event (SSE) strings in the following form: 'data: {CreateChatCompletion...
If request.stream is True, this returns an Iterator (or Generator) that produces server-sent-event (SSE) strings in the following form: 'data: {CreateChatCompletionStreamResponse} ' ... 'data: [DONE] ' If request.stream is False, this returns a CreateChatC...
chat
python
triton-inference-server/server
python/openai/openai_frontend/engine/engine.py
https://github.com/triton-inference-server/server/blob/master/python/openai/openai_frontend/engine/engine.py
BSD-3-Clause
def completion( self, request: CreateCompletionRequest ) -> CreateCompletionResponse | Iterator[str]: """ If request.stream is True, this returns an Iterator (or Generator) that produces server-sent-event (SSE) strings in the following form: 'data: {CreateCompletionRespon...
If request.stream is True, this returns an Iterator (or Generator) that produces server-sent-event (SSE) strings in the following form: 'data: {CreateCompletionResponse} ' ... 'data: [DONE] ' If request.stream is False, this returns a CreateCompletionRespo...
completion
python
triton-inference-server/server
python/openai/openai_frontend/engine/engine.py
https://github.com/triton-inference-server/server/blob/master/python/openai/openai_frontend/engine/engine.py
BSD-3-Clause