tab-cot / app.py
Jin Ziqi
Add application file
ee0fa6a
raw
history blame
3.7 kB
import gradio as gr
from statistics import mean
from torch.utils.data import Dataset
from collections import OrderedDict
import xml.etree.ElementTree as ET
import openai # For GPT-3 API ...
import os
import multiprocessing
import json
import numpy as np
import random
import torch
import torchtext
import re
import random
import time
import datetime
import pandas as pd
import sys
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
# Sentence Generator (Decoder) for GPT-3 ...
def decoder_for_gpt3(args, input, max_length, i, k, filename):
# GPT-3 API allows each users execute the API within 60 times in a minute ...
# time.sleep(1)
time.sleep(args.api_time_interval)
# https://beta.openai.com/account/api-keys
# api_list = []
# with open(filename,"r") as f:
# api_list = [line.rstrip('\n') for line in f]
# first_api = api_list[0]
# api_list = api_list[1:]
# api_list.append(first_api)
openai.api_key = "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"
#print(openai.api_key)
# Specify engine ...
# Instruct GPT3
if args.model == "gpt3":
engine = "text-ada-001"
elif args.model == "gpt3-medium":
engine = "text-babbage-001"
elif args.model == "gpt3-large":
engine = "code-cushman-001"
elif args.model == "gpt3-xl": # Please change this back
engine = "code-davinci-002"
elif args.model == "chatgpt":
engine = "gpt-3.5-turbo-0301"
else:
raise ValueError("model is not properly defined ...")
cnt = 0
while True:
try:
if args.model=="chatgpt":
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant that generate table to solve reasoning problem."},
{"role": "user", "content": input},
]
)
print(response)
return response["choices"][0]["message"]["content"]
# response = openai.Completion.create(
# engine=engine,
# prompt=input,
# max_tokens=max_length,
# temperature=0,
# stop='\n\n'
# )
# return response["choices"][0]["text"]
except KeyboardInterrupt:
print('Interrupted')
try:
sys.exit(0)
except SystemExit:
os._exit(0)
except openai.error.RateLimitError:
time.sleep(3)
cnt += 1
print(cnt)
if cnt >= 10:
print("!!!Error Occur " + input)
print("Unexpected error:", sys.exc_info()[0])
print(len(api_list))
api_list.remove(api_list[0])
with open(filename, 'w') as f:
for s in api_list:
f.write(s + '\n')
continue
except openai.error.ServiceUnavailableError:
time.sleep(2)
continue
except openai.error.APIConnectionError:
time.sleep(2)
continue
except openai.error.APIError:
time.sleep(2)
continue
except:
print("!!!Error Occur " + input)
print("Unexpected error:", sys.exc_info()[0])
print(len(api_list))
api_list.remove(api_list[0])
with open(filename, 'w') as f:
for s in api_list:
f.write(s + '\n')
continue