pierrejeambrun commented on code in PR #74334:
URL: https://github.com/apache/airflow/pull/74334#discussion_r4256997567


##########
providers/common/ai/src/airflow/providers/common/ai/plugins/www/src/model-api.ts:
##########
@@ -0,0 +1,71 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { UsageInfo } from "src/types/model";
+
+function getApiBase(): string {
+  if (typeof document === "undefined") return "/api/v2";
+  const baseHref = document.querySelector("head > base")?.getAttribute("href") 
?? "";
+  const baseUrl = new URL(baseHref, globalThis.location.origin);
+  const basePath = baseUrl.pathname.replace(/\/$/, "") || "";
+  return basePath ? `${basePath}/api/v2` : "/api/v2";
+}
+
+const API_BASE = getApiBase();
+
+// Namespaced to match 
airflow.providers.common.ai.utils.logging.MODEL_NAME_XCOM_KEY --
+// avoids colliding with a user's own "model_name" XCom.
+const MODEL_NAME_XCOM_KEY = "__AIRFLOW__COMMON_AI_MODEL_NAME__";
+
+/** Read one XCom entry; returns `null` when the task hasn't pushed that key 
(404). */
+async function fetchXComValue<T>(
+  dagId: string,
+  runId: string,
+  taskId: string,
+  mapIndex: number,
+  key: string,
+): Promise<T | null> {
+  const path =
+    `${API_BASE}/dags/${encodeURIComponent(dagId)}` +
+    `/dagRuns/${encodeURIComponent(runId)}` +
+    `/taskInstances/${encodeURIComponent(taskId)}` +
+    `/xcomEntries/${encodeURIComponent(key)}`;
+  const res = await fetch(`${path}?map_index=${mapIndex}&deserialize=true`, {

Review Comment:
   Went with the lighter option for now: the "Model tab" entry in 
observability.rst now explains that with an offloading backend the tab shows 
the stored reference instead of the value, and fetchUsage 
   treats a non-object usage as missing, so the stat boxes are hidden rather 
than showing undefined. Writing these keys straight to the DB like 
skipmixin_key would mean using private core API, so I'd
   keep that for a follow-up if it turns out to matter in practice.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to