You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
419 B

import openai
class CTRLChat():
'''
OpenAI api调用控制类
'''
def chat(self, key:str, q:str, tokens_limit:int) -> str:
openai.api_key = key
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": q}
],
max_tokens=tokens_limit
)
return completion.choices[0].message.content