|
import os |
|
import openai |
|
import gradio as gr |
|
|
|
|
|
|
|
openai.api_key ="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" |
|
start_sequence = "\nAI:" |
|
restart_sequence = "\nHuman: " |
|
|
|
def predict(input,initial_prompt, history=[]): |
|
|
|
s = list(sum(history, ())) |
|
s.append(input) |
|
|
|
|
|
response = openai.Completion.create( |
|
model="text-davinci-003", |
|
prompt= initial_prompt + "\n" + str(s), |
|
temperature=0.9, |
|
max_tokens=150, |
|
top_p=1, |
|
frequency_penalty=0, |
|
presence_penalty=0.6, |
|
stop=[" Human:", " AI:"]) |
|
|
|
response2 = response["choices"][0]["text"] |
|
history.append((input, response2)) |
|
|
|
return history, history |
|
|