{% extends shell('app') %} {% block title %}{{ _('Your session') }}{% endblock %} {% macro badge(part, value, progress=none) %}{% if value == 'ready' %}{{ _('Ready') }}{% elif value == 'failed' %}{{ _('Failed') }}{% elif progress is not none %}{{ progress }} %{% else %}{{ _('Starting…') }}{% endif %}{% endmacro %} {% block content %} {# reservations gives where to change the booking (longer, shorter); an older one without it gives nothing and the links are left out. #} {% set change_url = reservations_change_url(reservation) if reservations_change_url is defined else none %}

{{ _('Your session') }}

{{ reservation.model if reservation.mode == 'model' else _('JupyterLab with the GPU') }} · {{ nodes_label(reservation.node_list) if nodes_label is defined else reservation.nodes }} · {{ _('%(gb)s GB', gb=reservation.memory_gb) }} · {{ _('until %(time)s', time=pretty(reservation.end, false)) }}{% if change_url %} · {{ _('change') }}{% endif %}

{{ _('What is running') }}

{% if reservation.mode == 'model' %}
{{ _('The model') }}
{% set p = state.progress if state.model == 'starting' else none %}
{{ badge('model', state.model, state.progress) }}
{% endif %}
JupyterLab
{{ badge('console', state.console) }}
{% if resumed %}

{{ _('This session continues session %(num)s: its files are in your home.', num=resumed) }}

{% endif %} {% if reservation.node_list|length > 1 %}

{{ _('Only the first machine of the booking is used.') }}

{% endif %}
{{ _('Open JupyterLab') }} {% if reservation.mode == 'model' and not is_embedding(reservation.model) %} {{ _('Chat with the model') }} {% endif %} {% set r = reservation %}{% set back = url_for('lab_sessions.mine') %}{% set small = false %} {% if change_url %}{{ _('More or less time') }}{% endif %} {% include 'lab_sessions/_end_form.html' %}
{% if reservation.mode != 'model' and local_models %}

{{ _('Models on this machine') }} models-readonly/

{% for m in local_models %} {% set kind = 'GGUF' if ':' in m.name else ('embedding' if is_embedding(m.name) else '') %} {% endfor %}
{{ m.name }} {{ '%.1f'|format(m.gib) if m.gib else '—' }} {{ kind }}
{% endif %} {% if reservation.mode == 'model' %}

{{ _('The API') }}

{{ _('OpenAI-compatible. Already set in JupyterLab as OPENAI_BASE_URL, OPENAI_API_KEY and MODEL.') }}

{{ base_url }}
{{ api_key }}
{{ reservation.model }}
{% if is_embedding(reservation.model) %}
curl {{ base_url }}/embeddings \
  -H "Authorization: Bearer {{ api_key }}" \
  -H "Content-Type: application/json" \
  -d '{"model": "{{ reservation.model }}", "input": ["Hola", "Buenos días"]}'
from openai import OpenAI

client = OpenAI(base_url="{{ base_url }}", api_key="{{ api_key }}")
result = client.embeddings.create(
    model="{{ reservation.model }}",
    input=["Hola", "Buenos días"],
)
print(len(result.data[0].embedding))
{% else %}
curl {{ base_url }}/chat/completions \
  -H "Authorization: Bearer {{ api_key }}" \
  -H "Content-Type: application/json" \
  -d '{"model": "{{ reservation.model }}", "messages": [{"role": "user", "content": "Hola"}]}'
from openai import OpenAI

client = OpenAI(base_url="{{ base_url }}", api_key="{{ api_key }}")
reply = client.chat.completions.create(
    model="{{ reservation.model }}",
    messages=[{"role": "user", "content": "Hola"}],
)
print(reply.choices[0].message.content)
{% endif %}
{% endif %}

{{ _('Your files') }}

{% endblock %} {% block scripts %} {% endblock %}