Facebook
From CorvisAI, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 410
  1. import openai
  2.  
  3. openai.api_key = "API_KEY_HERE"
  4.  
  5.  
  6. def chatGPTApi(user_input):
  7.     #cleans typed text and file typos
  8.     response = openai.chat.completions.create(
  9.         model = "gpt-4-turbo-preview",
  10.         messages=[
  11.             {
  12.                 "role": "system",
  13.                 "content": "AI Assistant. Teach the user about bananas, be concise, one paragraph max, bullet points"
  14.             },
  15.             {"role": "user", "content": user_input}
  16.         ],
  17.         temperature=0.4,
  18.         max_tokens=4096,
  19.         top_p=0.5,
  20.         frequency_penalty=0,
  21.         presence_penalty=0
  22.     )
  23.    
  24.     print (response.choices[0].message.content)
  25.     return response.choices[0].message.content
  26.  
  27.  
  28. print ("please enter your text")
  29. text_input = input ()
  30. chatGPTApi(text_input)