Skip to main content

Prompt Engineering

Prompt Engineering - 提示工程

生成式 AI 應用程式傳回的回應品質不僅取決於模型本身,也取決於其所提供的提示類型。 「提示工程」一詞描述提示改善的流程。 設計應用程式的開發人員和使用這些應用程式的取用者,都可以考慮使用提示工程來改善生成式 AI 的回應品質。

提示是我們告知應用程式預期執行操作的方式。 工程師可以利用提示來新增程式的指示。 例如,開發人員可以為教師建置生成式 AI 應用程式,以建立與學生閱讀文字相關的複選問題。 在應用程式開發期間,開發人員可以新增其他規則,定義程式應該根據收到的提示執行哪些操作。

Prompt Writing
    提示工程指南 | Prompt Engineering Guide (promptingguide.ai) Prompt library (anthropic.com) Prompt engineering techniques with Azure OpenAI - Azure OpenAI Service | Microsoft Learn Prompt 高阶 | 链与框架 gemini-for-google-workspace-prompting-guide-101.pdf 提問(Prompt)的藝術:如何引導AI準確回答你的需求. 本文內容難度: ★ ☆ ☆ ☆ ☆ | by Simon Liu | InfuseAI
    Prompt Dev
    For Code LLMs

    Instruct

    # Prompt
    You are an expert programmer that writes simple, concise code and explanations. Write a python function to generate the nth fibonacci number.

    Response:

    Here is a Python function that generates the nth Fibonacci number:
    
    def fib(n):
        if n <= 1:
            return n
        else:
            return fib(n-1) + fib(n-2)
    
    This function uses the recursive formula for the Fibonacci sequence, which is:
    
    fib(n) = fib(n-1) + fib(n-2)

    Code Review

    # Prompt
    Where is the bug in this code?
    
    def fib(n):
        if n <= 0:
            return n
        else:
            return fib(n-1) + fib(n-2)

    Response:

    The bug in this code is that it does not handle the case where `n` is equal to 1.

    Unit Tests

    # Prompt
    write a unit test for this function: $(cat fib.py)

    Response:

    Here's an example of how you could write a unit test for the `fib` function:
    
    ```
    import unittest
    
    class TestFib(unittest.TestCase):
        def test_fib(self):
            self.assertEqual(fib(0), 0)
            self.assertEqual(fib(1), 1)
            self.assertEqual(fib(2), 1)
            self.assertEqual(fib(3), 2)
            self.assertEqual(fib(4), 3)
            self.assertEqual(fib(5), 5)
            self.assertEqual(fib(6), 8)
            self.assertEqual(fib(7), 13)
            self.assertEqual(fib(8), 21)
            self.assertEqual(fib(9), 34)
    if __name__ == '__main__':
        unittest.main()
    ```
    
    This test case covers all the cases where the input is an integer between 0 and 9, inclusive.

    Code Completion

    # Prompt
    # A simple python function to remove whitespace from a string:

    Response:

    def remove_whitespace(s):
        return ''.join(s.split())

    Infill: <PRE> {prefix} <SUF>{suffix} <MID>

    # Prompt
    <PRE> def compute_gcd(x, y): <SUF>return result <MID>

    Response:

      if x == y:
            return x
    
        if x > y:
            x = x - y
        else:
            y = y - x
    
        result = compute_gcd(x, y)