-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluation.py
35 lines (28 loc) · 1.33 KB
/
evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import openai
import os
import argparse
# Set up OpenAI API credentials
openai.api_key = os.environ["OPENAI_API_KEY"]
# Define the prompt to test the model
def generate_text(prompt, model_engine, temperature, max_tokens):
# Call the OpenAI API to generate text based on the prompt
response = openai.Completion.create(
engine=model_engine,
prompt=prompt,
temperature=temperature,
max_tokens=max_tokens
)
# Return the generated text
return response["choices"][0]["text"]
if __name__ == "__main__":
# Set up the argparse
parser = argparse.ArgumentParser(description='Test a large language model on programming problems')
parser.add_argument('--model_engine', type=str, default="text-davinci-002", help='The name of the OpenAI model engine to use (default: text-davinci-002)')
parser.add_argument('--temperature', type=float, default=0.5, help='The temperature to use for text generation (default: 0.5)')
parser.add_argument('--max_tokens', type=int, default=50, help='The maximum number of tokens to generate (default: 50)')
# Parse the arguments
args = parser.parse_args()
# Generate the text based on the arguments
generated_text = generate_text(args.prompt, args.model_engine, args.temperature, args.max_tokens)
# Print the generated text
print(generated_text)