Код: Выделить всё
class chatbot(APIView):
def post(self, request):
chatbot_response = None
if api_key is not None and request.method == 'POST':
openai.api_key = api_key
user_input = request.data.get('user_input')
prompt = user_input
response = openai.Completion.create(
model = 'text-davinci-003',
prompt = prompt,
max_tokens=250,
temperature=0.5
)
chatbot_response = response["choices"][0]["text"]
if chatbot_response is not None:
return Response({"response": chatbot_response}, status=status.HTTP_200_OK)
else:
return Response({'errors': {'error_de_campo': ['Promt vacio']}},
status=status.HTTP_404_NOT_FOUND)
Подробнее здесь: https://stackoverflow.com/questions/763 ... enai-model