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.

19 lines
487 B

import g4f
global history
history = {}
def chat_predict(prompt, id, sys_inst = None):
global history
if id not in history:
history[id] = [{"role": "user", "content": prompt}]
else:
history[id].append({"role": "user", "content": prompt})
if sys_inst:
history[id] = [{"role": "system", "content": sys_inst}]
predicted = g4f.ChatCompletion.create(model="gpt-3.5-turbo", messages=history[id])
history[id].append({"role": "assistant", "content": predicted})
return predicted