AISmarteasy – 시맨틱 커널 포크로 개발하기 – Semantic Function – 3a1 – Semantic Kernel 샘플 프롬프트 – QASkill

시맨틱 커널의 샘플 프롬프트 템플릿들을 살펴보면, 템플릿 작성이나 시맨틱 커널 방식의 프롬프트 템플릿 작성 방식에 익숙해질 수 있다.

 

QAPlugin –

AssistantResults

These are the results from the API call “{{$api}}”
===RESULTS
{{$results}}
===END RESULTS{{$resultsContext}}Use the Results to answer the following query:Query: {{$input}}
Answer:

 

질의 응답할 때, 질의만 작성해서 프롬프트로 전달하지 않고 좀 더 구체적인 목표에 따라 분류된 프롬프트를 사용할 수도 있다.

시작 끝으로 영역을 구분할 때, “===”를 사용하고 영역의 시작과 끝은 모두 대문자로 작성한다. 끝에는 “END”를 영역 이름 앞에 더해준다.

위 예는 어떤 api를 통해 결과를 얻었는지 중요하다. 해당 내용에 대한 컨텍스트도  있을 수 있는 경우이다. llm이 쿼리에 답할 때 결과와 컨텍스트 내용을 중요하게 다루도록 지시한다.

 

ContextQuery
ONLY USE XML TAGS IN THIS LIST:
[XML TAG LIST]
lookup: lookup information from outside
unsure: low confidence
unknown: don’t know
fact: when you output you know for a fact
notfact: not true, but don’t use a double negative
fiction: stuff you hallucinated or made up
smalltalk: conversation
opinion: your opinion
python: python code you want to run
action: actions to take
essay: longer answers. You can have sub-elements such as fact and fiction
[END LIST][CONTEXT]
TODAY is {{time.Date}}
FIRST NAME: {{$firstname}}
LAST NAME: {{$lastname}}
CITY: {{$city}}
STATE: {{$state}}
COUNTRY: {{$country}}
{{recall $input}}
[END CONTEXT]EMIT WELL FORMED XML ALWAYS. Any code you write should be CDATA.
BE BRIEF AND TO THE POINT, BUT WHEN SUPPLYING OPINION, IF YOU SEE THE NEED, YOU CAN BE LONGER.
USE [CONTEXT] TO LEARN ABOUT ME.
WHEN ANSWERING QUESTIONS, GIVING YOUR OPINION OR YOUR RECOMMENDATIONS, BE CONTEXTUAL.
For updated information about an entity, thing, event or time dependent matter, put in tags.
If you don’t know, ask.
If you are not sure, ask.
If information is out of date, ask.
Don’t give me old information that is out of date.
Based on calculates from TODAY, if the answer in the past, emit a fact. Otherwise emit a lookup tag.Who is the current president of the United States? Who was president in 2012? Who was CEO of Microsoft 30 years ago?
<response><lookup>Who is United States President</lookup><fact>Barack Obama was president in 2012</fact><fact>Bill Gates was CEO 30 years ago</fact></response>
[done]Give me a short overview of Jupiter. What are NASA’s latest spacecraft around it? What was the first spacecraft to do so?
<response><fact>Jupiter is the largest planet in the solar system</fact> <lookup>NASA missions Jupiter now</lookup><fact>Galileo was the first spacecraft to orbit Jupiter</fact><fiction>invaders from Jupiter attacked Saturn</fiction></response>[done]

Why did the moon fly away in 2014? Was it a spaceship?
<response><notfact>The moon flew away in 2014</notfact><notfact>It was a spaceship</notfact></response>[done]

{{$input}}

llm은 상관하지 않으니, 결국 전체 문장을 대문자로 표시한 부분은 사람을 위한 강조이다. 강조하고 싶은 부분을 이렇게 작성하면 된다.

 

출력 형식을 지정해 주면 llm은 지시에 따른다. 출력 형식은 xml이나 json 형태가 되면 쉽게 다른 기능에서 사용할 수 있다.

이 내용을 잘 보고, xml 형식의 출력을 원할 때 이렇게 작성하면 된다.

 

간결하게 작성하라고 시작되는 부분은 다른 프롬프트를 작성할 때도 거의 그대로 재 사용 할 수 있을 것 같다.

내부 데이터로 llm이 사전 훈련할 때 접근할 수 없었던 데이터는 프롬프트 컨텍스트로 제공한다. 컨텍스트를 사용하라는 문구도 거의 바뀌지 않고 재 사용 될 수 있을 것 같다.

 

For updated information~로 시작되는 부분도 llm이 잘 모르는 내용을 억지로 짜내려 하지 않도록 할 때 필요한 문구로, 대부분의 프롬프트에서 공통적으로 사용될 수 있을 것 같다.  예지도 이렇게 작성해주면 llm의 답변이 구조화되기 때문에 다른 기능에서 사용하기 쉽다.

 

QNA

ONLY USE JSON PROPERTIES IN THIS LIST:
[JSON PROPERTY LIST]
question
answer
[END LIST][CONTENT]
{{$input}}
[END CONTENT]EMIT WELL FORMED JSON ALWAYS.
BE BRIEF AND TO THE POINT.Generate a Question and Answer list (results) based on the meeting chat and transcript in CONTENT.
Return well-formed json list. Example: { “results”: [{“question”: “What time is it?”, “answer”: “2:15pm”}]}
If you cannot find any, return an empty list.
Do not include questions with empty answers.
Questions should be focused on the context of the content, not metadata or statistics about the content.
Questions should be timeless.
Questions should use proper nouns when possible.
Questions should be about the content of the conversation and should be focused on key ideas or concepts discussed.
Questions should be concise and to the point.
Ignore small talk.
List at most 4 questions.{
“results”:

질의 응답이 여러 번에 걸쳐 진행되는 경우에 사용할 수 있을 것 같다.

Question

I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with “Unknown”.

Q: What is human life expectancy in the United States?
A: Human life expectancy in the United States is 78 years.

Q: Who was president of the United States in 1955?
A: Dwight D. Eisenhower was president of the United States in 1955.

Q: Which party did he belong to?
A: He belonged to the Republican Party.

Q: What is the square root of banana?
A: Unknown

Q: How does a telescope work?
A: Telescopes use lenses or mirrors to focus light and make objects appear closer.

Q: Where did the first humans land on the moon in 1969?
A: The first humans landed on the moon on the southwestern edge of the Sea of Tranquility.

Q: Name 3 movies about outer space.
A: Aliens, Star Wars, Apollo 13

Q: How many squigs are in a bonk?
A: Unknown

Q: {{$input}}

질문에 답하도록 하는 프롬프트의 전형으로 프롬프트 템플릿 그대도 사용할 수 있을 것 같다.

GitHubMemoryQuery

{{textmemoryskill.recall $input}}

Considering only the information above, which has been loaded from a GitHub repository, answer the following.
Question: {{$input}}Answer:

깃헙에서 로드되었다는 것은 뭐 사람을 위한 것으로 의미가 없다. input 변수 값을 인자로 textmemoryskill.recall 네이티브 함수를 호출해서 얻은 데이터에 기반해서 답하라는 것이다. 데이터 소스가 있는 경우 사람을 위한 부분을 어떻게 작성할지, 함수 호출이 있는 경우 어떻게 작성할지 알고 넘어가자.

 

Form

ACT LIKE A WEB SERVER, GIVING YOUR RESPONSES IN XML

ONLY USE XML TAGS IN THIS LIST.
[XML TAG LIST]
response: root node for your responses.
form: a container for questions you want me to answer
output: Output you are returning to me
question: questions I should ANSWER to clarify things. Can ask multiple.
submit: End form with submit IF YOU WANT answers sent back to you, LIKE in a CONVERSATION
[END LIST]

EMIT WELL FORMED XML ALWAYS. WHEN YOU NEED MORE INFORMATION, ASK.
WHEN YOU ALREADY KNOW, USE OUTPUT

Submit is always <submit promptName=”{{$promptName}}”/>
After </response> write [done]

Continue the conversation below, but always respond with a form.
{{$input}}

역할을 부여하는 부분만 잘 보면 될 것 같다. 이것도 일반적으로 사용할 수 있는 프롬프트 템플릿으로 보인다.

OrchestratorSkill – GetIntent

ai 애플리케이션이 사용자와 챗을 하다 보면, 사용자의 의도를 알면 좋은 때가 있다.

 

챗 이력을 요약하도록, history 변수를 인자로 ConversationSummarySkill.SummarizeConversation 함수를 호출한다.

{{ConversationSummarySkill.SummarizeConversation $history}}

User: {{$input}}

———————————————

Provide the intent of the user. The intent should be one of the following: {{$options}}

INTENT:

의도만 알아서 파악해 준다면, options 변수는 필요 없다. 어떤 의도인지 파악되면 그에 대한 대응이 필요한 경우, 개발되는 llm 연동 ai 애플리케이션이 제공하는 기능 중에 하나로 대응하고 싶은 경우에 options에 기능 목록을 작성해서 제공하도록 한다.

GetNumbers

Extract the numbers from the input and output them in JSON format.——————-
INPUT: Take the square root of 4
OUTPUT: {“number1”:4}INPUT: Subtract 3 dollars from 2 dollars
OUTPUT: {“number1″:2,”number2”:3}INPUT: I have a 2×4 that is 3 feet long. Can you cut it in half?
OUTPUT: {“number1”:3, “number2”:2}

INPUT: {{$input}}
OUTPUT:

 

About the Author
(주)뉴테크프라임 대표 김현남입니다. 저에 대해 좀 더 알기를 원하시는 분은 아래 링크를 참조하세요. http://www.umlcert.com/kimhn/

Leave a Reply

*