Created
August 18, 2024 16:07
-
-
Save Terieyenike/06bdba420180e3424ae9cafa041f6bad to your computer and use it in GitHub Desktop.
Prompt Engineering for Python Developers
This file contains hidden or 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 | |
| client = OpenAI() | |
| import os | |
| from dotenv import load_dotenv | |
| api_key = os.getenv("OPENAI_API_KEY") | |
| def get_chat_completion(user_prompt, system_role='You are a helpful assistant', | |
| model='gpt-3.5-turbo', temperature=1): | |
| messages = [ | |
| {'role': 'system', 'content': system_role}, | |
| {'role': 'user', 'content': user_prompt} | |
| ] | |
| response = client.chat.completions.create( | |
| model=model, | |
| messages= messages, | |
| temperature=temperature | |
| ) | |
| return response.choices[0].message.content | |
| text = ''' | |
| Prompt engineering is a new discipline for developing and optimizing prompts \ | |
| to efficiently use language models for a wide variety of applications and research topics. | |
| ''' | |
| prompt = f''' | |
| Translate the text delimited by triple backticks from english to french. | |
| ```{text}``` | |
| ''' | |
| response = get_chat_completion(prompt) | |
| print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment