import openai from transformers import GPT2Tokenizer openai.api_key = "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" def get_reply(message): reply = openai.ChatCompletion.create(model="gpt-4-0314", messages=[{ "role": "user", "content": message }]) return reply["choices"][0]["message"]["content"] def get_tokens_length(message): tokenizer = GPT2Tokenizer.from_pretrained("gpt2") tokens = tokenizer.encode(message) return len(tokens)