Skip to content

Instantly share code, notes, and snippets.

@Chenx221
Created March 6, 2025 06:22
Show Gist options
  • Save Chenx221/f00ea368f717bee664ecc1485c3c6e84 to your computer and use it in GitHub Desktop.
Save Chenx221/f00ea368f717bee664ecc1485c3c6e84 to your computer and use it in GitHub Desktop.
chatgpt, token, api, openai, kfc, free openai api key
import openai
openai.api_key = "sk-S0ZDIENyYXp5IFRodXJzZGF5LCBHaXZlIE1lIDUwICAgICAg"
openai.api_key_bak1 = "sk-ICAgICAgS0ZDIENyYXp5IFRodXJzZGF5LCBHaXZlIE1lIDUw"
openai.api_key_bak2 = "sk-a2ZjLCBjcmF6eSB0aHVyc2RheSwgZ2l2ZSBtZSA1MCBybWIu"
print("ChatGPT: Hi, I'm KFCGPT. I'm a helpful assistant")
messages = [
# system message to set the behavior of the assistant
{"role": "system", "content": "Hi ChatGPT, You are a helpful assistant!"},
]
try:
chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
reply = chat_completion["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": reply})
except:
print("Check if you have set the API key correctly")
exit()
while True:
message = input("👤: ")
# message = input("📄: ")
if message == "exit":
break
if message == "clear":
print("\033[H\033[J")
print("ChatGPT: Hi, I'm ChatGPT. I'm a helpful assistant")
messages = [
{"role": "system", "content": "Hi ChatGPT, You are a helpful assistant!"},
]
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat_completion["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": reply})
continue
if message:
messages.append(
{"role": "user", "content": message},
)
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat_completion["choices"][0]["message"]["content"]
print(f"🤖: {reply}")
messages.append({"role": "assistant", "content": reply})
# This is not my source code. In fact, it comes from https://github.com/abdur75648/ChatGPT-API-Python
# API key not working? Try base64 decoding the part after 'sk-'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment