生成式 AI 巨集函數

生成式 AI 概論

結構化工具可由三個途徑使用 生成式 AI 工具

  1. LLM 控制項 可制定提示詞預設使用 Llama3.1 8B 模型推論,詳見 LLM 控制項說明

  2. 巨集按鈕 使用 LLMQUERY() 函數指定,可選用不同語言模型: 詳見 LLMQUERY 函數 說明。

  3. 使用 AI 小助手 : 開箱即用體驗 LLM 預設功能,也可選用其他助手表單,詳見 AI 小助手 說明。

LLMQUERY 函數

LLMQUERY 函數 是一種用於調用大型語言模型(LLM)進行文本生成的函數。本函數僅能使用在巨集按鈕。它根據指定的提示(prompt)和模型配置生成相應的文本,並將結果存儲在指定的單元格中。

函數說明

  1. 函數名稱LLMQUERY

  2. 用法

LLMQUERY(id, prompt, model)
  1. 參數

  • id:目標單元格的標識,文本生成結果將存儲在這個單元格中。

  • prompt:提示,包含需要模型生成的內容描述

  • model:(選填) 本院部署以下三個系列大語言模型 (Multiple Models),使用者可依工作任務需求選填設定,調用偏好模型:

    • Llamma 系列

      • 未設定 : 會預設使用 Llama3.1 8B 模型,可處理的上下文長度 32K, 擅長英文問答,推論速度快。

      • 設定 "70b": 會使用 Llama 3.3 70B 模型,可處理的上下文長度 32K,效能與參數規模達 405B 的 Llama 3.1 相當,可使用 JSON tooling 以及 structured output

    • Google 模型系列

      • 設定 "tw" or "math" : 會使用 Gemma2 模型,可處理的上下文長度 8K,擅長中文問答,數學計算以及 JSON資料處理。 (參見 範例 2)。

      • 設定 "gemma3": 會使用 Gemma3:4b 模型,可處理的上下文長度 16K。

      • 設定 "gemma3_12b": 會使用 Gemma3:12b 模型,可處理的上下文長度 16K。

      • 設定 "gemma3_27b": 會使用 Gemma3:27b 模型,可處理的上下文長度 16K。

      • 設定 "medgemma" : 會使用 medgemma:4b 模型,可處理的上下文長度 16K。(Gemma 3 variants that are trained for performance on medical text and image comprehension.)

      • 設定 "medgemma:27b": 會使用 medgemma:27b 模型,可處理的上下文長度 16K。 (Gemma 3 variant optimized for medical text)

    • Qwen3 模型系列

      • 設定 "qwen332b" : 會使用 qwen3:32b 模型,可處理的上下文長度32K,非思考模式。

      • 設定 "qwen3a3b": 會使用 qwen3:30b-a3b-q4_K_M 模型,可處理的上下文長度 32K,非思考模式。

      • 設定 "tqwen332b", "tqwen3a3b": 會使用 思考模式(Thinking Mode),適用於需要深度推理的複雜任務,模型會逐步推理以提供更精確的答案。

    • 設定 "phi4": 會使用 Microsoft Phi-4 14b 模型,可處理的上下文長度 16K。

綜合範例

範例 1 :

以下的範例,使用 批次多函數指令執行 和 MACRO 巨集專用函數

// 綜合範例 1

// 將 IF 函數結果帶回 item 60
MACRO(60,
IF(A61=0, "normal", "abnormal")
)

// 將 'IF you are good' 帶回 item 60
MACRO(60,
'IF you are good'
)

範例 2

以下的範例,使用 批次多函數指令執行 和 LLMQUERY 巨集專用函數

// 綜合範例 3

LLMQUERY(39,IF(LEN(A16) < 10,"response not available",
7 CONCATENATE("remove previous memory, and analysis the following medical records: ",A16," Now, summarize only the information from the above record into summary of present illness, past history, and active problem, please response not available if there is no related information. Only provide the answer, and ignore opening or additional content."))),

LLMQUERY(32, IF(LEN(A41) < 10,"clinical question not available",
CONCATENATE(A39, " According the above medical record, answer the clinical question: what is the the most appropriate imaging study to evaluate his/her ", A41, " and associated symptoms base on the ACR Select criteria? please also explain the reason")))

範例 2 解析

  1. 使用 批次多函數指令執行 接續執行兩個 LLMQUERY 巨集專用函數

  2. 由於未指定 LLM,預設使用 Llama3.1 8B 模型,進行病歷整理,將結果放到控制項 39

  3. 再利用 Llama3.1 8B 模型 依照 控制項 39 的結果,詢問臨床問題以及建議的檢查,在將結果放回 控制項 32。

範例 3

以下的範例,使用 批次多函數指令執行 LLMQUERY、MACRO 巨集專用函數 來按順序執行多個步驟,並根據公式計算結果動態更新元素內容。

// 綜合範例 2

LLMQUERY(2,"what is metabolic syndrome"),
MACRO(4, A2),
LLMQUERY(6, 
  CONCATENATE("請用繁體中文翻譯以下說明: ", A4),
  "tw"    // 指定中文模型
)

範例 3 解析

  1. 接續執行三個函數

  2. 設定參數先調用 生成式AI工具,回答代謝症候群說明,將結果放到控制項 2

  3. 再利用 MACRO 將前面的結果複製到 控制項 4,

  4. 模型設定 "tw" 會利用 Google Gemma2 模型 將控制項 4內容 進行中文翻譯,在將結果放到 控制項 6。

範例 4

// 綜合範例 4

LLMQUERY(16, CONCATENATE("remove previous memory, and analyze the following medical records: ", A9, " year-old ", A10, "ER record: Vital signs:", A2, "Let\'s think step by step like a medical doctor. Extract only the information from the above ER record, and make a comprehensive list including 1. chief complaints, 2. associated symptoms, 3. negative findings, 4. underlying chronic diseases, 5. Lab and image study results, 6. treatment provided at ER, 7. further treatment plan. Please follow the requirements carefully and to the letter."),"70b"),

LLMQUERY(6, CONCATENATE(A9, "year-old, gender:", A10, A16, "Based on only the information from the above record, automatically generate a narrative Present Illness section from the emergency room (ER) record provided above, using a specific template. The model should strictly use information from the input without adding any assumptions or independent judgments. The output must be professional, concise, and utilize medical terminology correctly to ensure clarity and precision for medical practitioners. Ensure that the model extracts and structures the required information based on the data explicitly mentioned in the ER records and treatment notes, adhering to the provided template. You must output the response only the answer text content. no heading, explanation, or comment is needed. just provide the answer. Template for output: A [age]-year-old [gender] with a history of [underlying chronic diseases] was admitted to this hospital because of [chief complaint]. The patient had been in [his/her] usual state of health until approximately [duration] before admission, when [he/she] experienced [chief complaint]. [Associated symptoms] [Relative complaints] [He/She] had no [negative findings mentioned in input]. Upon arrival at our emergency room, [important lab and exam results at ER] were noted, and [important treatments at ER] were administered. Subsequently, [he/she] was admitted to our ward for further treatment."),"70b"),

MACRO(6, A2),
MACRO(4, A2)

範例 4 解析

  1. 第一步LLMQUERY(16, CONCATENATE(...),"70b")模型指定 "70b"使用 Llama 3.3 70B 模型進行文本生成。它首先將多個單元格內容連接起來,形成一個完整的提示,然後將這個提示發送給 Llama 3.3 70B 模型進行處理。結果將存儲在指定的單元格中。

  2. 第二步LLMQUERY(6, CONCATENATE(...),"70b")調用 Llama 3.3 70B 模型,基於第一步的結果進行進一步的文本生成。提示包含了患者的年齡、性別等信息,並要求模型生成一個完整的病史敘述。

  3. 第三步MACRO(6, A2)將單元格 A2 的值設置到元素(itemid=6)中,並觸發相關事件。

  4. 第四步MACRO(4, A2)將單元格 A2 的值設置到另一個元素(itemid=4)中,並觸發相關事件。

以上範例使用者僅須按一個按鈕,就可以自動依序執行所有步驟,得到結果。

Last updated