Skip to content

Commit

Permalink
Merge pull request #15 from crcresearch/jonathan-dev-rebase
Browse files Browse the repository at this point in the history
Jonathan dev rebase
  • Loading branch information
chowington authored Nov 22, 2024
2 parents 36df909 + ebb3fc2 commit 89adcdd
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 298 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ logs/*
!logs/skip-morning_2024-05-15_13-54-44.txt

### Add simulations to keep here ###
!environment/frontend_server/storage/base_the_ville_isabella_maria_klaus/*
!environment/frontend_server/storage/base_the_ville_isabella_maria_klaus/
!environment/frontend_server/storage/base_the_ville_n25/*
!environment/frontend_server/storage/July1_the_ville_isabella_maria_klaus-step-3-*/*
!environment/frontend_server/storage/skip-morning-s-14/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"age": 20,
"innate": "kind, inquisitive, passionate",
"learned": "Klaus Mueller is a student at Oak Hill College studying sociology. He is passionate about social justice and loves to explore different perspectives.",
"currently": "Klaus Mueller is writing a research paper on the effects of gentrification in low-income communities. Klauss is thinking about whom to vote for in the upcoming town election. He knows that Adam Smith and Isabella Rodriguez are running for the office of town mayor. The election takes place next week.",
"currently": "Klaus Mueller is writing a research paper on the effects of gentrification in low-income communities. Klaus is thinking about whom to vote for in the upcoming town election. He knows that Adam Smith and Isabella Rodriguez are running for the office of town mayor. The election takes place next week.",
"lifestyle": "Klaus Mueller goes to bed around 11pm, awakes up around 7am, eats dinner around 5pm.",
"living_area": "the Ville:Dorm for Oak Hill College:Klaus Mueller's room",
"concept_forget": 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"age": 20,
"innate": "kind, inquisitive, passionate",
"learned": "Klaus Mueller is a student at Oak Hill College studying sociology. He is passionate about social justice and loves to explore different perspectives.",
"currently": "Klaus Mueller is writing a research paper on the effects of gentrification in low-income communities. Klauss is thinking about whom to vote for in the upcoming town election. He knows that Adam Smith and Isabella Rodriguez are running for the office of town mayor. The election takes place next week.",
"currently": "Klaus Mueller is writing a research paper on the effects of gentrification in low-income communities. Klaus is thinking about whom to vote for in the upcoming town election. He knows that Adam Smith and Isabella Rodriguez are running for the office of town mayor. The election takes place next week.",
"lifestyle": "Klaus Mueller goes to bed around 11pm, awakes up around 7am, eats dinner around 5pm.",
"living_area": "the Ville:Dorm for Oak Hill College:Klaus Mueller's room",
"concept_forget": 100,
Expand Down
2 changes: 1 addition & 1 deletion nlp/openai_convo_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():
print(file_chunks[0])

response = client.chat.completions.create(
model="gpt-4",
model="gpt-4o-mini",
messages=[
{
"role": "system",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def generate_insights_and_evidence(persona, nodes, n=5):

print(ret)
try:
if type(ret) == dict:
if isinstance(ret, dict):
for thought, evi_raw in ret.items():
evidence_node_id = [nodes[i].node_id for i in evi_raw]
ret[thought] = evidence_node_id
Expand Down
73 changes: 24 additions & 49 deletions reverie/backend_server/persona/prompt_template/gpt_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def ChatGPT_structured_request(prompt, response_format):

def ChatGPT_safe_generate_response(
prompt,
example_output,
special_instruction,
example_output="",
special_instruction="",
repeat=3,
fail_safe_response="error",
func_validate=None,
Expand All @@ -294,11 +294,13 @@ def ChatGPT_safe_generate_response(
if func_validate and func_clean_up:
# prompt = 'GPT-3 Prompt:\n"""\n' + prompt + '\n"""\n'
prompt = '"""\n' + prompt + '\n"""\n'
prompt += (
f"Output the response to the prompt above in json. {special_instruction}\n"
)
prompt += "Example output json:\n"
prompt += '{"output": "' + str(example_output) + '"}'
if example_output or special_instruction:
prompt += (
f"Output the response to the prompt above in json. {special_instruction}\n"
)
if example_output:
prompt += "Example output json:\n"
prompt += '{"output": "' + str(example_output) + '"}'

if verbose:
print("LLM PROMPT")
Expand All @@ -310,9 +312,10 @@ def ChatGPT_safe_generate_response(
if not chatgpt_response:
raise Exception("No valid response from LLM.")
curr_gpt_response = chatgpt_response.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"]
if example_output or special_instruction:
end_index = curr_gpt_response.rfind("}") + 1
curr_gpt_response = curr_gpt_response[:end_index]
curr_gpt_response = json.loads(curr_gpt_response)["output"]

if verbose:
print("---- repeat count:", i)
Expand All @@ -327,13 +330,15 @@ def ChatGPT_safe_generate_response(
print("ERROR:", e)
traceback.print_exc()

print("FAIL SAFE TRIGGERED")
return fail_safe_response


def ChatGPT_safe_generate_structured_response(
prompt,
response_format,
example_output,
special_instruction,
example_output="",
special_instruction="",
repeat=3,
fail_safe_response="error",
func_validate=None,
Expand All @@ -343,11 +348,13 @@ def ChatGPT_safe_generate_structured_response(
if func_validate and func_clean_up:
# prompt = 'GPT-3 Prompt:\n"""\n' + prompt + '\n"""\n'
prompt = '"""\n' + prompt + '\n"""\n'
prompt += (
f"Output the response to the prompt above in json. {special_instruction}\n"
)
prompt += "Example output json:\n"
prompt += '{"output": "' + str(example_output) + '"}'
if example_output or special_instruction:
prompt += (
f"Output the response to the prompt above in json. {special_instruction}\n"
)
if example_output:
prompt += "Example output json:\n"
prompt += str(example_output)

if verbose:
print("LLM PROMPT")
Expand Down Expand Up @@ -377,38 +384,6 @@ def ChatGPT_safe_generate_structured_response(

return fail_safe_response

def ChatGPT_safe_generate_response_OLD(prompt,
repeat=3,
fail_safe_response="error",
func_validate=None,
func_clean_up=None,
verbose=False):
if verbose:
print ("LLM PROMPT")
print (prompt)

if func_validate and func_clean_up:
for i in range(repeat):
try:
chatgpt_response = ChatGPT_request(prompt)
if not chatgpt_response:
raise Exception("No valid response from LLM.")
curr_gpt_response = chatgpt_response.strip()
if func_validate(curr_gpt_response, prompt=prompt):
return func_clean_up(curr_gpt_response, prompt=prompt)
if verbose:
print(f"---- repeat count: {i}")
print(curr_gpt_response)
print("~~~~")

except Exception as e:
print("ERROR:", e)
traceback.print_exc()

print("FAIL SAFE TRIGGERED")
return fail_safe_response



# ============================================================================
# ###################[SECTION 2: ORIGINAL GPT-3 STRUCTURE] ###################
Expand Down
Loading

0 comments on commit 89adcdd

Please sign in to comment.