# Few-shot 프롬프트 생성기

Fastcampus 오프라인 프롬프트 엔지니어링 수업은 매 주의 과제가 있습니다.

제출해 주시는 과제 중엔 함께 보면 좋을 프롬프트가 참 많습니다. 

그 중 소개하고 싶은 프롬프트가 있습니다.  `Few-shot 프롬프트 생성기`입니다. 

---

## Few-shot prompt  engineering 기법 

Few-shot prompt engineering 은 여러 개의 예제를 사용하는 기법입니다. 

예를 들어서, 한 단어를 영어로 번역하는 프롬프트라면 여러 가지 예제를 사용해서 에어컨이라는 단어의 영어 단어를 생성하게 하는 것입니다. 

> 
다음 단어를 한국어에서 영어로 번역해줘. 

사과: apple

핸드폰: mobile phone

에어컨:  

---

## 프롬프트 기능 개발을위한 예제 자동 생성 툴

이 글에 소개하는 `프롬프트는 기능 개발을 위한 예제 자동 생성 툴`입니다. 

프롬프트 엔지니어가 직업인 분의 프롬프트라 제가 이렇다 할 피드백을 하지 않아도, 이미 완성형인데요. 

프롬프트를 함께 보겠습니다.  ( 흔쾌히 공유를 허용해주셨습니다. 감사합니다 )

> **프롬프트 제목: Few-shot 프롬프트 생성기**

> **기능 설명: 대상 프롬프트와 정답 제약조건을 입력하면, 출력에 도움이 되는 예제를 생성합니다. **

---

## **프롬프트 생성기 설명 **

![Image](https://upload.cafenono.com/image/slashpagePost/20240827/135148_9jxO6qL7wg3soicKPH?q=80&s=1280x180&t=outside&f=webp)

**(중앙) 입력 필드: **

- 대상 프롬프트: 사용자가 생성하고자 하는 프롬프트를 입력하는 곳

- 생성할 예제 개수: 설정함

- 정답 제약조건: 생성될 예제에 대한 요구사항 입력하는 곳

- 오답 제약조건: 생성될 예제에 나오면 안되는 것들 입력하는 곳 

**(오른쪽) **

- 입력 프롬프트와 결과 확인 창 

## **사용한 프롬프트 **

```javascript
When generating a fewshot examples, assume that the prompt below will be used as the system_prompt.
This means that you should generate an 5 of fewshot-examples, assuming that the prompt below is a system prompt
<br>generate three possible faqs based on user inputs. <br>Should be within 2 words. these are used for app application. Answer in Korean. <br><br><br>

### requirements

This is a prerequisites for a "Fewshot Examples that satisfies the request."
A "Fewshot Examples that satisfies the request" must meet all of the following conditions
<br>- three questions should not be identical.<br>- three questions should attract user's interest. <br>

### constraints

This is a constraints for a "Fewshot Examples that satisfies the request."
A "Fewshot Examples that satisfies the request" must not meet any of the following conditions
<br>- too lengthy <br>- too redundant <br>

### Sample

This is a sample of a fewshot examples that the user wants to generate.
Each example is separated by '{}'.
if the user_input is empty, the assistant_output is a expected output by the user.

<br>None<br>

Considering the sample above, generate good & bad examples that meet the content of "requirements" and "constraints".

### output

generate 5 examples for both correct and wrong cases.
generate fewshot in Korean.

Please print in the format below :

```

Those are "Fewshot Examples that satisfies the request."

<fewshot examples 1>

<fewshot examples 2>

...

<fewshot examples 5>

Those are "Fewshot Examples that does not satisfies the request."

<fewshot examples 1>

<fewshot examples 2>

...

<fewshot examples 5>
```
```

### **사용 예시 **

- 사용자의 다양한 입력 값을 구분하기 위한 로직을 구현하는 기능을 위해, 예제 생성을 해봤습니다.

- 사용자의 질문을 두 종류로 구분 (실시간 정보 - 일반 정보) → 실시간 정보에 해당하는 입력 값에는 ! 기호를, 일반 입력 값에는 * 붙이도록 했습니다. 

- 사용 결과는 아래 스크린 샷에서 볼 수 있습니다. 

![Image](https://upload.cafenono.com/image/slashpagePost/20240827/144323_gyneIjWhDpwF53u4PY?q=80&s=1280x180&t=outside&f=webp)

- 이 툴의 최대 장점은 "예시 생성"에 있어서 오답 제약 조건입니다. 오답을 자동으로 분류하여 정확하게 처리할 수 있다면, 개발 속도가 빨라지니까요.  

---

→ 보완하면 좋을 점을 담은 피드백입니다. 

## 프롬프트 피드백

### **프롬프트 수정안**

```javascript
Generate 5 few-shot examples based on {{$the given prompt}} and {{$constraints}}.
Assume the prompt below will be used as the system prompt. 

# Requirements
Few-shot examples must meet all the following conditions:

[Specify conditions here]

#Constraints
Few-shot examples must not meet any of the following conditions:

[Specify constraints here]

#Sample
If the user input is empty, the assistant output should be the expected output.

# Output
Provide 5 examples for both correct and incorrect cases in Korean.

# Format: 
```
correct cases: <example 1 to 5>
incorrect cases: <example 1 to 5>
```

```

(1) `**표현 잡기**`:

정확한 표현으로 수정했습니다. 예를들면, 다음의 표현들요. 

- few-shot examples that satifies the request →Few-shot examples that satisfy the request

- few-shot examples that does not satisfies the request →  Few-shot examples that do not satisfy the request 

(2) `**불필요한 문장 제거**`: 

비용 효율화와 처리 과정 효율화를 위한 중복되는 프롬프트 문장을 제거했습니다.  

- 상단의 This means~~ a system prompt도 간결하게 표현을 쳤습니다.

-  a prerequisite 은 ##requirements 로 이미 지시를 했으니, 삭제 했습니다. 

- constraints 정의에 해당하는 표현도 간결하게 쳤습니다. 

- Considering~~으로 한 번 더 자세히 설명하는 구간도 삭제했습니다. 해당 지시가 이전 구성에있기 때문에 중복은 안해도 될 것 같습니다. 

**(3) **`**구조 수정**`**: **

프롬프트 첫 도입부의 #target prompt 내용을 지시문과 통합했습니다. 

요점은 두 가지 이니까요.  

- 프롬프트의 상세 내용이 'system_prompt'로 

- 5개의 예제를 생성하기 

---

수정을 하지 않아도, 훌륭한 프롬프트 툴이니 

사용해보시면 좋겠습니다. 

 - **Streamlit**:[https://twojay-fewshotmaker.streamlit.app/](https://twojay-fewshotmaker.streamlit.app/)  

[main](https://twojay-fewshotmaker.streamlit.app/)

**Thanks to **

공유와 공개를 허락해주신, 프롬프트 엔지니어 two-jay 님 감사드립니다.

#promptengineering #prompt #promptgenerator #프롬프트피드백 #프롬프트제작

For the site tree, see the [root Markdown](https://slashpage.com/sujin-prompt-engineer.md).
