You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
response=get_completion("What is the capital of France?")
print(response)
Tokens
response=get_completion("Take the letters in lollipop \and reverse them")
print(response)
"lollipop" in reverse should be "popillol"
response=get_completion("""Take the letters in \l-o-l-l-i-p-o-p and reverse them""")
print(response)
Helper function (chat format)
Helper function
defget_completion_from_messages(messages,
model="gpt-3.5-turbo",
temperature=0,
max_tokens=500):
response=openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature, # this is the degree of randomness of the model's outputmax_tokens=max_tokens, # the maximum number of tokens the model can ouptut
)
returnresponse.choices[0].message["content"]
messages= [
{'role':'system',
'content':"""You are an assistant who\ responds in the style of Dr Seuss."""},
{'role':'user',
'content':"""write me a very short poem\ about a happy carrot"""},
]
response=get_completion_from_messages(messages, temperature=1)
print(response)
# lengthmessages= [
{'role':'system',
'content':'All your responses must be \one sentence long.'},
{'role':'user',
'content':'write me a story about a happy carrot'},
]
response=get_completion_from_messages(messages, temperature=1)
print(response)
# combinedmessages= [
{'role':'system',
'content':"""You are an assistant who \responds in the style of Dr Seuss. \All your responses must be one sentence long."""},
{'role':'user',
'content':"""write me a story about a happy carrot"""},
]
response=get_completion_from_messages(messages,
temperature=1)
print(response)
messages= [
{'role':'system',
'content':"""You are an assistant who responds\ in the style of Dr Seuss."""},
{'role':'user',
'content':"""write me a very short poem \ about a happy carrot"""},
]
response, token_dict=get_completion_and_token_count(messages)
print(response)
print(token_dict)