mirror of
https://github.com/zhxycn/Telegram-ChatBot-Serverless.git
synced 2024-11-25 12:17:50 +00:00
22 lines
526 B
Python
22 lines
526 B
Python
import os
|
|
|
|
import openai
|
|
|
|
openai.api_key = os.environ["OPENAI_API_KEY"]
|
|
|
|
|
|
def create_conversation(messages: list):
|
|
response = openai.ChatCompletion.create(
|
|
model="gpt-3.5-turbo",
|
|
messages=messages,
|
|
temperature=1,
|
|
)
|
|
content = response["choices"][0]["message"]["content"]
|
|
model = response["model"]
|
|
tokens = [
|
|
response["usage"]["total_tokens"],
|
|
response["usage"]["prompt_tokens"],
|
|
response["usage"]["completion_tokens"],
|
|
]
|
|
return content, model, tokens
|