Skip to content

Instantly share code, notes, and snippets.

@sunilkumardash9
Created April 28, 2023 18:39
Show Gist options
  • Save sunilkumardash9/94befafa232260e2262403c85bf491be to your computer and use it in GitHub Desktop.
Save sunilkumardash9/94befafa232260e2262403c85bf491be to your computer and use it in GitHub Desktop.
def generate_response(history, model ):
global messages, cost
response = openai.ChatCompletion.create(
model = model,
messages=messages,
temperature=0.2,
)
response_msg = response.choices[0].message.content
cost = cost + (response.usage['total_tokens'])*(0.002/1000)
messages = messages + [{"role":'assistant', 'content': response_msg}]
for char in response_msg:
history[-1][1] += char
#time.sleep(0.05)
yield history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment