Skip to content

Instantly share code, notes, and snippets.

@Terieyenike
Created August 18, 2024 16:07
Show Gist options
  • Select an option

  • Save Terieyenike/06bdba420180e3424ae9cafa041f6bad to your computer and use it in GitHub Desktop.

Select an option

Save Terieyenike/06bdba420180e3424ae9cafa041f6bad to your computer and use it in GitHub Desktop.
Prompt Engineering for Python Developers
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