Prompt Wizard는 다양한 평가 방법을 사용하여 사용자 정의 프롬프트를 평가하기위한 패키지입니다. 이를 통해 자신의 프롬프트를 제공하거나 자동으로 생성 한 다음 JSON 파일에서 결과를 얻을 수 있습니다.
Prompt Wizard를 사용하려면 PIP를 사용하여 패키지 및 모든 종속성을 설치해야합니다.
pip install promptwizard또는 Git 클론 https://github.com/leniolabs/promptwiz.git을 사용하여 저장소를 복제하십시오
프롬프트 마법사를 실행하려면 OpenAI API 키를 설정하고 지정해야합니다. https://platform.openai.com/account/api-keys에서 하나를 생성 할 수 있습니다. API 키를 얻은 후에는 OpenAI_API_KEY 환경 변수를 사용하여 지정하십시오. EVAL을 실행할 때 API 사용과 관련된 비용을 알고 있습니다.
프롬프트 마법사를 사용하기 전에 환경 변수를 정의해야합니다. 두 가지 유효한 옵션이 있거나 올바른 폴더의 .env 에 OPENAI_API_KEY 정의하거나 azure 사용하기로 결정한 경우 OPENAI_API_TYPE azure 로 정의하고 OPENAI_API_BASE .env OPENAI_API_KEY OpenAI_API_BASE 및 OPENAI_API_VERSION 올바르게 정의해야합니다.
두 가지 사용 대안이 있습니다.
Yaml 파일을 사용하려면 :
평가하려는 프롬프트가 포함 된 YAML 파일이 있는지 확인하십시오. YAML 파일은 적절한 구조를 따라야합니다.
promptwizard YAML_FILE_PATHpromptwizard YAML_FILE_PATH --env_path .env_FILE_PATH계속하고 싶은지 물으면 'Y'에 응답하십시오.
output.json 파일에 저장됩니다. 프롬프트 평가를 위해 ELO 메소드를 선택하면 산점도 scatter_plot.png 도 YAML 파일과 동일한 폴더에 저장됩니다. YAML 파일에 반복을 수행하려는 경우 더 많은 수의 파일도 생성됩니다."프롬프트"변수가 YAML 파일에 정의되지 않으면 프로그램은 평가를위한 프롬프트를 자동으로 생성합니다.
Yaml 파일을 전달하는 패키지를 매개 변수로 실행하십시오.
promptwizard YAML_FILE_PATH계속하고 싶은지 물으면 'Y'에 응답하십시오.
output.json 파일에 저장됩니다. 프롬프트 평가를 위해 ELO 메소드를 선택하면 산점도 scatter_plot.png 도 YAML 파일과 동일한 폴더에 저장됩니다.파이썬 스크립트에서도 사용할 수 있습니다.
import promptwizardPromptwizard가 제공 할 수있는 다양한 기능을 사용하여 다음과 같이 사용합니다.
# Example of using PromptWizard
from promptwizard import prompt_generation
test_cases = [
{ ' input ' : ' How do you make a classic spaghetti carbonara? ' , ' output ' : ' REPLY ' },
{ ' input ' : " What is John Smith's phone number? " , ' output ' : ' NOT_REPLY ' },
]
description = " Decide whether the question should be answered or not. " # A short description of the type of task for the test cases.
system_gen_prompt = " " " Your job is to generate system prompts for GPT, given a description of the use-case and some test cases.
In your generated prompt, you should describe how the AI should behave in plain English. Include what it will see, and what it's allowed to output. Be creative with prompts to get the best possible results. The AI knows it's an AI -- you don't need to tell it this.
Remember that the prompt should only allow the AI to answer the answer and nothing else. No explanation is necessary.
You will be graded based on the performance of your prompt... but don't cheat! You cannot include specifics about the test cases in your prompt. Any prompts with examples will be disqualified. I repeat, do not include the test cases.
Most importantly, output NOTHING but the prompt. Do not include anything else in your message. " " " # Here you have to indicate to the LLM how your generated prompts should be. This example is useful if you later want to use the equals evaluation method.
# Create 4 prompts.
prompts = prompt_generation.generate_candidate_prompts(system_gen_prompt, test_cases, description)[0]
원하는 경우 제공된 프롬프트에서 수행하려는 반복 수 또는 언어 모델에 대한 최적의 동작을 달성하는 프롬프트를 얻기 위해 자동으로 생성 될 반복 수를 지정할 수도 있습니다. 반면에, 파이썬 스크립트의 프롬프트를 반복하기 위해 함수를 사용하는 것을 사용할 수 있습니다.
from promptwizard.prompt_generation import iteration
results = iteration.iterations(test_cases, method= ' Elo ' , prompts=old_prompts, number_of_prompts=3)YAML 파일의 유효한 구조에 대한 설명과 그 안에있는 일부 변수에 대한 특정 제한 사항을 제공합니다. 평가를 실행하기 전에 신중하게 읽는 것이 좋습니다.
다음은 YAML 파일이 가져야 할 구조입니다.
test:
cases: " " " Here, you have to put the test cases you are going to use to evaluate your prompts. If you are going to use the
Elo method to evaluate them, it should be just a list of strings. If you are going to use the methods classification,
equal or includes, it should be a list of tuples with two elements, where the first element is the test case and the
second element is the correct response to the test. Remember that if you decide to use classification, only a boolean
value is allowed as a response. the form of your test cases has to be, in case of selecting the Elo method:
-'Test1'
-'Test2'...
If you choose the methods Classification, Equals, Includes, Semantic Similarity or LogProbs they must be of the form:
-input: 'Test1'
output: 'Answer1'
-input: 'Test2'
output: 'Answer2'
In case the method is Function Calling:
-input: 'Test1'
output1: 'name_function'
output2: 'variable'
-input: 'Test2'
output1: 'name_function'
output2: 'variable'
If you choose Code Generation:
- input: 'Test1'
arguments: (arg1,) in case there is only one argument, (arg1, arg2,...) in case there are more than one argument.
output: res
and finally if you choose JSON Validation:
- input: 'Test1'
output: json_output " " "
description: " " " Here is the description of the type of task that summarizes the test cases. You only have to use this field if
you are going to use the 'Elo' method " " "
method: " " " Here, you select the evaluation method for your prompts. You must choose between 'Elo',
'Classification', 'Equals', 'Includes', 'Function Calling', 'Code Generation' 'JSON Validation', 'Semantic Similarity' and 'LogProbs'. " " "
model:
name: " " " The name of the GPT model you will use to evaluate the prompts. " " "
temperature: " " " The temperature of the GPT model you will use to evaluate the prompts. " " "
max_tokens: " " " The maximum number of tokens you will allow the GPT model to use to generate the response to the test. " " "
functions: " " " This field must only be filled out in case the 'Function Calling' method is intended to be used.
If another method is used, it must not be filled out. The structure is a JSON object. Let's break down the different components:
- Function Name (name): This is the identifier used to refer to this function within the context of your code.
- Function Description (description): A brief description of what the function does.
- Function Parameters (parameters): This section defines the input parameters that the function accepts.
- Type (type): The type of the parameter being defined.
- Properties (properties): This is an object containing properties that the input parameter object should have.
- File Type (file_type): This is a property of the parameter object.
- Enum (enum): An enumeration of allowed values for the 'file_type' property. (optional)
- Description (description): A description of what the 'file_type' property represents.
- Required (required): An array listing the properties that are required within the parameter object. (optional) " " "
function_call: " " " This field must only be filled out in case the 'Function Calling' method is intended to be
used. If another method is used, it must not be filled out. " " "
prompts: " " " You have two options, either provide your list of prompts or generate them following the instructions below. " " "
list: " " " A list of prompts you want to evaluate. If you want to generate them with the prompt generator, don't use this field.
Please provide a minimum number of 4 prompts. Your prompts must be listed as follows:
- 'Prompt1'
- 'Prompt2'... " " "
generation:
number: " " " The number of prompts you are going to evaluate. You need to provide this key value only if you are going to generate the prompts. Indicate the quantity of prompts you want to generate. Please provide a minimum number of 4 prompts. If you do not define this key by default, 4 prompts will be created. " " "
constraints: " " " If you are going to generate prompts, this optional feature allows you to add special characteristics to the prompts that will be generated. For example, if you want prompts with a maximum length of 50 characters, simply complete with 'Generate prompts with a maximum length of 50 characters'. If you don't want to use it, you don't need to have this key defined. " " "
description: " " " Here is the description of the type of task that summarizes the test cases. If you use the 'Elo' method you mustn't use this field. " " "
best_prompts: " " " The number of prompts you want to iterate over and on which you want to highlight the final results. the value must be between 2 and the number of prompts you provide (or generate) minus one. If you do not define this value the default value will be 2. " " "
model:
name: " " " The name of the GPT model you will use to generate the prompts. " " "
temperature: " " " The temperature of the GPT model you will use to generate the prompts. " " "
max_tokens: " " " The maximum number of tokens you will allow the GPT model to use to generate your prompts. " " "
iterations:
number: " " " The number of iterations you want to perform on the best prompts obtained in your initial testing to arrive at
prompts with better final results. If you don't want to try alternatives combining your best prompts just put 0. " " "
best_percentage: " " " Number between 0 and 100 indicating that iterations should be stopped if all 'best_prompts' equaled or exceeded the indicated accuracy. If this value is not defined, it will default to 100. " " "
model:
name: " " " The name of the GPT model you will use to generate the prompts. " " "
temperature: " " " The temperature of the GPT model you will use to generate the prompts. " " "
max_tokens: " " " The maximum number of tokens you will allow the GPT model to use to generate your prompts. " " "
You can not define these variables for ' model ' in case you want to keep the same variables that were used in ' generation ' , in case the ' generation ' field has not been used it will take the following default values:
name: ' gpt-4
temperature: 0.6
max_tokens: 300"""
timeout: """Timeout set for an API request. This time limit indicates how long the client should wait to receive a response before the request expires."""
n_retries: """Number of attempts that will be automatically made to resend an API request in case the initial request fails."""평가하려는 YAML 파일이 구조에 오류가있는 경우 걱정하지 마십시오. 프롬프트 엔지니어가 평가하기 전에 파일이 검증되며 파일을 성공적으로 평가하기 위해 수정해야 할 위치를 나타내는 알림을 받게됩니다.
프롬프트를 생성 할 때 constraints 조건 키를 사용하여 생성하려는 프롬프트가 특별한 특성을 가지도록 명시 적으로 요청할 수 있습니다. 예를 들어 '20 단어를 초과하지 않는 길이의 프롬프트를 생성하십시오'.
평가를 실행하는 데 드는 비용을 알고 싶다면 간단히 입력하십시오.
promptwizard YAML_FILE_PATH그리고 계속하고 싶은지 물었을 때 단순히 'n'에 대답하십시오.
그렇지 않으면 'Y'에 응답하고 평가를 실행하면 실제 최종 비용과 함께 대략적인 비용을 받게됩니다. 최종 JSON 파일에서 최상의 결과로 상위 프롬프트를 보는 것 외에도 GPT-3.5-Turbo 및 GPT-4 모두에 대해 효과적으로 소비되는 비용과 토큰 수에 대한 동일한 정보를 얻게됩니다.
또는 파이썬 스크립트에서 다음을 수행 할 수 있습니다.
from promptwizard.approximate_cost import cost
print(cost.approximate_cost(test_cases, method, prompts_value))그리고 가능한 평가에 대한 대략적인 비용을 보게 될 것입니다.
사용 예제를 보려면 PromptWizard를 사용할 수있는 다양한 방법을 탐색 할 수있는 다음 Colab 노트북을 제공합니다. (https://colab.research.google.com/drive/1iw2y439233vecohkpuhogenwy1y81rw8i?usp=sharing)
Promptwizard는 Leniolabs와 점점 더 많은 기고자 커뮤니티의 사랑으로 제작되었습니다. 우리는 당신의 아이디어로 디지털 경험을 쌓습니다. 연락하십시오! 또한 PrfustWizard에 대한 질문이나 피드백이 있으시면 [email protected]으로 문의하십시오. 우리는 당신의 의견을 듣고 싶습니다!