Skip to content

Instantly share code, notes, and snippets.

@graylan0
Created August 3, 2023 10:25
Show Gist options
  • Select an option

  • Save graylan0/294b4f2f93a73d216c40c193f81a3245 to your computer and use it in GitHub Desktop.

Select an option

Save graylan0/294b4f2f93a73d216c40c193f81a3245 to your computer and use it in GitHub Desktop.
GPT appliaction for the prediction of future habits for thedevdad_
import openai
openai.api_key = 'your-api-key'
def get_habit_data(user_id):
# This function should connect to your habit-building app's database
# and return the user's habit data.
# For now, I'll just return some dummy data.
return {
"exercise": {
"frequency": "daily",
"duration": "30 minutes",
"progress": "improving"
},
"meditation": {
"frequency": "weekly",
"duration": "15 minutes",
"progress": "stagnant"
}
}
def generate_suggestions(habit_data):
# Convert the habit data into a string that the model can understand
habit_text = "\n".join(f"{habit}: {data['frequency']}, {data['duration']}, {data['progress']}" for habit, data in habit_data.items())
# Use the GPT-3.5 model to generate suggestions
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"The user has the following habits:\n{habit_text}\nWhat suggestions can we give them?",
temperature=0.5,
max_tokens=100
)
return response.choices[0].text.strip()
def main():
user_id = 123 # Replace with the actual user ID
habit_data = get_habit_data(user_id)
suggestions = generate_suggestions(habit_data)
print(suggestions)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment