Created
June 24, 2024 06:57
-
-
Save albertocavalcante/a83346399ff4a4a936be069d520b3674 to your computer and use it in GitHub Desktop.
OpenAI GPT-4o vs GPT-4: Reverse "lollipop"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openai import OpenAI | |
from typing import Final | |
from pprint import pprint | |
class GPTHelper: | |
llm = OpenAI() | |
REVERSE_WORD_SYSTEM_PROMPT: Final = """ | |
Given a word by the user, you must reverse it and display back. | |
As an example: | |
User prompt: 'banana' | |
Expected response: 'The reverse of "banana" is "ananab".' (without the single quotes) | |
""" | |
def __init__(self, model: str, max_tokens: int = 500, temperature: float = 0.7): | |
self.model = model | |
self.max_tokens = max_tokens | |
self.temperature = temperature | |
def reverse_word(self, word: str) -> str: | |
response = self.llm.chat.completions.create( | |
model=self.model, | |
max_tokens=self.max_tokens, | |
temperature=self.temperature, | |
messages=[ | |
{"role": "system", "content": self.REVERSE_WORD_SYSTEM_PROMPT}, | |
{"role": "user", "content": word}, | |
], | |
) | |
return response.choices[0].message.content | |
def main(): | |
gpt4 = GPTHelper(model="gpt-4-turbo", temperature=0.0) | |
gpt4o = GPTHelper(model="gpt-4o", temperature=0.0) | |
word = "lollipop" | |
gpt4_response = gpt4.reverse_word(word) | |
gpt4o_response = gpt4o.reverse_word(word) | |
responses = {"gpt4": gpt4_response, "gpt4o": gpt4o_response} | |
print("\n" * 2) | |
pprint(responses) | |
print("\n" * 2) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment