Copilot commented on code in PR #6655:
URL: https://github.com/apache/texera/pull/6655#discussion_r3617812390


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/codegen/QaRankingCodegenSpec.scala:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.amber.operator.huggingFace.codegen
+
+import org.apache.texera.amber.pybuilder.PyStringTypes.EncodableString
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class QaRankingCodegenSpec extends AnyFlatSpec with Matchers {
+
+  private def makeCtx(
+      hfApiToken: EncodableString = "token",
+      modelId: EncodableString = "deepset/roberta-base-squad2",
+      promptColumn: EncodableString = "prompt",
+      resultColumn: EncodableString = "hf_response",
+      task: EncodableString = "question-answering",
+      systemPrompt: EncodableString = "You are a helpful assistant.",
+      safeMaxTokens: Int = 256,
+      safeTemp: Double = 0.7,
+      contextColumn: EncodableString = "context",
+      candidateLabels: EncodableString = "positive,negative",
+      sentencesColumn: EncodableString = "sentences"
+  ): CodegenContext =
+    CodegenContext(
+      hfApiToken = hfApiToken,
+      modelId = modelId,
+      promptColumn = promptColumn,
+      resultColumn = resultColumn,
+      task = task,
+      systemPrompt = systemPrompt,
+      safeMaxTokens = safeMaxTokens,
+      safeTemp = safeTemp,
+      contextColumn = contextColumn,
+      candidateLabels = candidateLabels,
+      sentencesColumn = sentencesColumn
+    )
+
+  "QaRankingCodegen.task" should "be the canonical question-answering string" 
in {
+    QaRankingCodegen.task shouldBe "question-answering"
+  }
+
+  "QaRankingCodegen.tasks" should "cover exactly the five QA/ranking task 
families" in {
+    QaRankingCodegen.tasks shouldBe Set(
+      "question-answering",
+      "table-question-answering",
+      "zero-shot-classification",
+      "sentence-similarity",
+      "text-ranking"
+    )
+  }
+
+  it should "include its primary task among the handled tasks" in {
+    QaRankingCodegen.tasks should contain(QaRankingCodegen.task)
+  }
+
+  "QaRankingCodegen.payloadPython" should "branch on each of the five tasks 
and an else fallback" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("""if task == "question-answering":""")
+    out should include("""elif task == "table-question-answering":""")
+    out should include("""elif task == "zero-shot-classification":""")
+    out should include("""elif task == "sentence-similarity":""")
+    out should include("""elif task == "text-ranking":""")
+    out should include("else:")
+  }
+
+  it should "build the question-answering payload from prompt_value and the 
context column" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("self.CONTEXT_COLUMN")
+    out should include("""payload = {"inputs": {"question": prompt_value, 
"context": ctx_val}}""")
+  }
+
+  it should "route table-question-answering through query and table_dict" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("""payload = {"inputs": {"query": prompt_value, 
"table": table_dict}}""")
+  }
+
+  it should "derive zero-shot candidate labels from the candidate-labels 
attribute" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("self.CANDIDATE_LABELS")
+    out should include("candidate_labels")
+  }
+
+  it should "split the sentences column for sentence-similarity and 
text-ranking" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("self.SENTENCES_COLUMN")
+    out should include("source_sentence")
+    out should include(""""query": prompt_value""")
+    out should include(""""texts": sentences_list""")

Review Comment:
   These two assertions use invalid Scala string literals (multiple unescaped 
quotes). As written, this test file will not compile. Use an escaped string or 
a triple-quoted string to match the Python snippet substring.



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/codegen/QaRankingCodegenSpec.scala:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+
+package org.apache.texera.amber.operator.huggingFace.codegen
+
+import org.apache.texera.amber.pybuilder.PyStringTypes.EncodableString
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class QaRankingCodegenSpec extends AnyFlatSpec with Matchers {
+
+  private def makeCtx(
+      hfApiToken: EncodableString = "token",
+      modelId: EncodableString = "deepset/roberta-base-squad2",
+      promptColumn: EncodableString = "prompt",
+      resultColumn: EncodableString = "hf_response",
+      task: EncodableString = "question-answering",
+      systemPrompt: EncodableString = "You are a helpful assistant.",
+      safeMaxTokens: Int = 256,
+      safeTemp: Double = 0.7,
+      contextColumn: EncodableString = "context",
+      candidateLabels: EncodableString = "positive,negative",
+      sentencesColumn: EncodableString = "sentences"
+  ): CodegenContext =
+    CodegenContext(
+      hfApiToken = hfApiToken,
+      modelId = modelId,
+      promptColumn = promptColumn,
+      resultColumn = resultColumn,
+      task = task,
+      systemPrompt = systemPrompt,
+      safeMaxTokens = safeMaxTokens,
+      safeTemp = safeTemp,
+      contextColumn = contextColumn,
+      candidateLabels = candidateLabels,
+      sentencesColumn = sentencesColumn
+    )
+
+  "QaRankingCodegen.task" should "be the canonical question-answering string" 
in {
+    QaRankingCodegen.task shouldBe "question-answering"
+  }
+
+  "QaRankingCodegen.tasks" should "cover exactly the five QA/ranking task 
families" in {
+    QaRankingCodegen.tasks shouldBe Set(
+      "question-answering",
+      "table-question-answering",
+      "zero-shot-classification",
+      "sentence-similarity",
+      "text-ranking"
+    )
+  }
+
+  it should "include its primary task among the handled tasks" in {
+    QaRankingCodegen.tasks should contain(QaRankingCodegen.task)
+  }
+
+  "QaRankingCodegen.payloadPython" should "branch on each of the five tasks 
and an else fallback" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("""if task == "question-answering":""")
+    out should include("""elif task == "table-question-answering":""")
+    out should include("""elif task == "zero-shot-classification":""")
+    out should include("""elif task == "sentence-similarity":""")
+    out should include("""elif task == "text-ranking":""")
+    out should include("else:")
+  }
+
+  it should "build the question-answering payload from prompt_value and the 
context column" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("self.CONTEXT_COLUMN")
+    out should include("""payload = {"inputs": {"question": prompt_value, 
"context": ctx_val}}""")
+  }
+
+  it should "route table-question-answering through query and table_dict" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("""payload = {"inputs": {"query": prompt_value, 
"table": table_dict}}""")
+  }
+
+  it should "derive zero-shot candidate labels from the candidate-labels 
attribute" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("self.CANDIDATE_LABELS")
+    out should include("candidate_labels")
+  }
+
+  it should "split the sentences column for sentence-similarity and 
text-ranking" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("self.SENTENCES_COLUMN")
+    out should include("source_sentence")
+    out should include(""""query": prompt_value""")
+    out should include(""""texts": sentences_list""")
+  }
+
+  it should "fall back to shipping the raw prompt as inputs" in {
+    val out = QaRankingCodegen.payloadPython(makeCtx())
+    out should include("""payload = {"inputs": prompt_value}""")
+  }
+
+  "QaRankingCodegen.parsePython" should "extract the answer field for both QA 
variants" in {
+    val out = QaRankingCodegen.parsePython(makeCtx())
+    out should include("""if task == "question-answering":""")
+    out should include("""elif task == "table-question-answering":""")
+    out should include("""body.get("answer"""")

Review Comment:
   This assertion has a malformed triple-quoted string literal (unbalanced 
quotes), which will prevent the test from compiling. Match a valid substring 
from QaRankingCodegen.parsePython instead (e.g., the `body.get("answer", ...)` 
call).



-- 
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