import openai import gradio as gr from langchain import OpenAI from langchain.chains import PALChain import datetime gpt_only_prompt = "Calculate the following, giving only the final answer:\n" prompt = "" def openai_create(prompt): print("prompt: " + prompt) # We use temperature of 0.0 because it gives the most predictable, factual answer (i.e. avoids hallucination). response = openai.Completion.create( model="text-davinci-003", prompt=prompt, temperature=0.0, max_tokens=300, top_p=1, frequency_penalty=0, presence_penalty=0 ) return response.choices[0].text def calc_gpt_only(math_problem): answer = openai_create(gpt_only_prompt + math_problem + "\n") print("math problem: " + math_problem) print("calc_gpt_only answer: " + answer) html = "
" + answer + "" return html def calc_gpt_pal(math_problem): llm = OpenAI(model_name='code-davinci-002', temperature=0, max_tokens=512) pal_chain = PALChain.from_math_prompt(llm, verbose=True) answer = pal_chain.run(math_problem) print("math problem: " + math_problem) print("calc_gpt_pal answer: " + answer) html = "
" + answer + "" return html block = gr.Blocks(css=".gradio-container {background-color: lightgray}") with block: title = gr.Markdown("""