OpenAI run and some fixes

This commit is contained in:
2024-02-08 18:16:43 +01:00
parent 56ad3a50a1
commit c1eab346e9
9985 changed files with 280881 additions and 12 deletions
@@ -19,10 +19,10 @@ else:
model = GPT4All("mistral-7b-instruct-v0.1.Q4_0.gguf", device="gpu", n_threads=4)
embedder = Embed4All()
def temp_sleep(seconds=0.1):
def temp_sleep(seconds=3.0):
time.sleep(seconds)
def GPT_single_request(prompt):
def ChatGPT_single_request(prompt):
temp_sleep()
if use_openai:
@@ -67,7 +67,7 @@ def GPT_single_request(prompt):
# return "ChatGPT ERROR"
def GPT_request(prompt):
def ChatGPT_request(prompt):
"""
Given a prompt and a dictionary of GPT parameters, fetch the response of the LLM
ARGS:
@@ -75,7 +75,7 @@ def GPT_request(prompt):
RETURNS:
a str of the LLM's response.
"""
# temp_sleep()
temp_sleep()
try:
if use_openai:
completion = openai.ChatCompletion.create(
@@ -152,9 +152,10 @@ def ChatGPT_safe_generate_response(prompt,
for i in range(repeat):
try:
curr_gpt_response = GPT_request(prompt).strip()
curr_gpt_response = ChatGPT_request(prompt).strip()
end_index = curr_gpt_response.rfind('}') + 1
curr_gpt_response = curr_gpt_response[:end_index]
curr_gpt_response = json.loads(curr_gpt_response)["output"]
# print ("---ashdfaf")
@@ -187,7 +188,7 @@ def ChatGPT_safe_generate_response_OLD(prompt,
for i in range(repeat):
try:
curr_gpt_response = GPT_request(prompt).strip()
curr_gpt_response = ChatGPT_request(prompt).strip()
if func_validate(curr_gpt_response, prompt=prompt):
return func_clean_up(curr_gpt_response, prompt=prompt)
if verbose: