def openAI_call(model,message,max_token):
response = openai.ChatCompletion.create(
model=model,
messages=message,
max_tokens=int(max_token),
temperature=0.7,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
n=1,
stream=True
)
for chunk in response:
choices = chunk.get("choices",[])
if choices and len(choices)>0 and "delta" in choices[0]:
delta = choices[0].get("delta",{})
#print(delta)
if "content" in delta:
text = delta.get("content",{})
yield str(text + '\n').encode('utf-8')