연습 - 사용자 고유의 프롬프트 작성
이 연습에서는 LLM(대규모 언어 모델)에 프랑스어로 유용한 문구 목록을 제공하도록 요청하는 프롬프트를 작성합니다. 선택한 다른 언어로 코드를 테스트할 수도 있습니다. 그럼 시작하겠습니다.
이전 연습에서 만든 Visual Studio Code 프로젝트를 엽니다.
Program.cs 파일을 다음 코드로 업데이트합니다.
using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Plugins.Core; var builder = Kernel.CreateBuilder(); builder..AddAzureOpenAIChatCompletion( "your-deployment-name", "your-endpoint", "your-api-key", "deployment-model"); var kernel = builder.Build(); string language = "French"; string prompt = @$"Create a list of helpful phrases and words in ${language} a traveler would find useful."; var result = await kernel.InvokePromptAsync(prompt); Console.WriteLine(result);
터미널에
dotnet run
을 입력하여 코드를 실행합니다.다음 출력과 유사한 응답이 표시됩니다.
1. Bonjour - Hello 2. Merci - Thank you 3. Oui - Yes 4. Non - No 5. S'il vous plaît - Please 6. Excusez-moi - Excuse me 7. Parlez-vous anglais? - Do you speak English? 8. Je ne comprends pas - I don't understand 9. Pouvez-vous m'aider? - Can you help me? 10. Combien ça coûte? - How much does it cost? 11. Où est la gare? - Where is the train station?
응답은 커널에 전달한 Azure OpenAI 모델에서 제공됩니다. 의미 체계 커널 SDK는 LLM(대규모 언어 모델)에 연결하고 프롬프트를 실행합니다. 보다 구체적인 지침을 추가하여 이 프롬프트를 개선할 수 있습니다.
다음 텍스트와 일치하도록 프롬프트를 업데이트합니다.
string prompt = @$"Create a list of helpful phrases and words in ${language} a traveler would find useful. Group phrases by category. Display the phrases in the following format: Hello - Ciao [chow]";
이 프롬프트에서는 응답 형식을 지정하기 위한 특정 지침을 LLM에 제공합니다. 새 프롬프트를 실행하면 다음 출력과 유사한 보다 자세한 응답이 표시됩니다.
Restaurant Phrases: - Water, please - De l'eau, s'il vous plaît [duh loh, seel voo pleh] - Check, please - L'addition, s'il vous plaît [lah-di-syo(n), seel voo pleh] - Bon appétit - Bon appétit [bohn ah-peh-teet] Transportation Phrases: - Where is the train station? - Où est la gare? [oo-eh lah gahr] - How do I get to...? - Comment aller à...? [ko-mahn tah-lay ah] - I need a taxi - J'ai besoin d'un taxi [zhay buh-zwan dunn tah-xee]
또한 LLM에 특정 범주의 구를 포함하고 여행자에 대한 몇 가지 배경 정보를 고려하라는 메시지를 표시할 수 있습니다. 시도해 보기:
다음 텍스트와 일치하도록 프롬프트를 업데이트합니다.
string language = "French"; string history = @"I'm traveling with my kids and one of them has a peanut allergy."; string prompt = @$"Consider the traveler's background: ${history} Create a list of helpful phrases and words in ${language} a traveler would find useful. Group phrases by category. Include common direction words. Display the phrases in the following format: Hello - Ciao [chow]";
이제 LLM은 구 목록을 생성할 때 여행자의 정보를 고려할 수 있습니다. 또한 일반적인 방향 단어를 포함하는 지침도 추가했습니다.
출력은 다음 응답과 유사하게 나타날 수 있습니다.
Phrases for dealing with peanut allergy: My child has a peanut allergy - Mon enfant a une allergie aux arachides [mon on-fon ah oon ah-lair-zhee oh a-rah-sheed] Is there a peanut-free option available? - Y a-t-il une option sans arachide? [ee ah-teel une oh-pee-syon sahn ah-rah-sheed] Phrases for directions: Turn left - Tournez à gauche [toor-nay ah gohsh] Turn right - Tournez à droite [toor-nay ah dwaht]
다음 연습에서는 LLM에 가상 사용자를 할당하여 응답의 품질을 개선하는 방법을 연습합니다.
Important
지금까지 작성한 코드를 삭제하지 마세요. 다음 연습에 필요합니다.