gpt-3.5-turbo in Python
# coding=utf-8
import os
import openai
# Create the API instance
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.organization = os.getenv("OPENAI_ORG_ID")
def inputLoop():
# Type text
return str(input("Please type a text: "))
def gpt35(txt):
response = openai.ChatCompletion.create(
model = "gpt-3.5-turbo",
messages = [
{"role": "user", "content": txt}
],
temperature = 0.7
)
print('Bot: ' + response.choices[0].message.content) # type: ignore
print('total_tokens: '+ str(response.usage.total_tokens)) # type: ignore
if __name__ == '__main__':
txt = inputLoop()
while True:
if (txt != ''):
gpt35(txt)
txt = inputLoop()
else:
break
Records 2023-03-22 00:04:57 通过 网页 浏览(190)
共有0条评论!