|
| 1 | +{{/* vim: set filetype=mustache: */}} |
| 2 | + |
| 3 | +{{/* Create the name of the secret AI Assistant to use (Jupyter) */}} |
| 4 | +{{- define "library-chart.secretNameAssistantJupyter" -}} |
| 5 | +{{- $aiAssistant := include "library-chart.aiAssistant" . | fromJson -}} |
| 6 | +{{- if $aiAssistant.enabled }} |
| 7 | +{{- $name := printf "%s-secretassistant" (include "library-chart.fullname" .) }} |
| 8 | +{{- default $name $aiAssistant.secretName }} |
| 9 | +{{- else }} |
| 10 | +{{- default "default" $aiAssistant.secretName }} |
| 11 | +{{- end }} |
| 12 | +{{- end }} |
| 13 | + |
| 14 | +{{/* Template to generate the jupyter-ai config secret (uses the active provider) */}} |
| 15 | +{{- define "library-chart.secretAssistantJupyter" -}} |
| 16 | +{{- $aiAssistant := include "library-chart.aiAssistant" . | fromJson -}} |
| 17 | +{{- if $aiAssistant.enabled -}} |
| 18 | +{{- $active := $aiAssistant.activeProvider | default dict -}} |
| 19 | +{{/* Fall back to the legacy flat structure (userPreferences.aiAssistant) */}} |
| 20 | +{{- $model := $active.selectedModel | default $aiAssistant.model | default "" -}} |
| 21 | +{{- $apiBase := $active.apiBase | default $aiAssistant.apiBase | default "" -}} |
| 22 | +{{- $modelProvider := $aiAssistant.modelProvider | default "openai-chat" -}} |
| 23 | +{{- $embeddingsProvider := $aiAssistant.embeddingsProvider | default "" -}} |
| 24 | +{{- $fields := dict -}} |
| 25 | +{{- $embeddingsFields := dict -}} |
| 26 | +{{- if $apiBase }} |
| 27 | +{{- $_ := set $fields (printf "%s:" $modelProvider) (dict "openai_api_base" $apiBase) -}} |
| 28 | +{{- if $model }} |
| 29 | +{{- $_ := set $fields (printf "%s:%s" $modelProvider $model) (dict "openai_api_base" $apiBase) -}} |
| 30 | +{{- end }} |
| 31 | +{{- if and $embeddingsProvider $model }} |
| 32 | +{{- $_ := set $embeddingsFields (printf "%s:%s" $embeddingsProvider $model) (dict "openai_api_base" $apiBase) -}} |
| 33 | +{{- end }} |
| 34 | +{{- end }} |
| 35 | +{{/* No api_keys here: jupyter-ai falls back to the OPENAI_API_KEY env var injected by the statefulset */}} |
| 36 | +{{- $config := dict |
| 37 | + "model_provider_id" (empty $model | ternary nil (printf "%s:%s" $modelProvider $model)) |
| 38 | + "embeddings_provider_id" (or (empty $embeddingsProvider) (empty $model) | ternary nil (printf "%s:%s" $embeddingsProvider $model)) |
| 39 | + "send_with_shift_enter" false |
| 40 | + "fields" $fields |
| 41 | + "api_keys" (dict) |
| 42 | + "completions_model_provider_id" nil |
| 43 | + "completions_fields" (dict) |
| 44 | + "embeddings_fields" $embeddingsFields |
| 45 | +-}} |
| 46 | +apiVersion: v1 |
| 47 | +kind: Secret |
| 48 | +metadata: |
| 49 | + name: {{ include "library-chart.secretNameAssistantJupyter" . }} |
| 50 | + labels: |
| 51 | + {{- include "library-chart.labels" . | nindent 4 }} |
| 52 | +stringData: |
| 53 | + config.json: | |
| 54 | +{{ $config | toPrettyJson | indent 4 }} |
| 55 | +{{- end }} |
| 56 | +{{- end }} |
0 commit comments