Does the model in this script keep the history of each sample or does is strat a new…
- User
Does the model in this script keep the history of each sample or does is strat a new session for each row?
""" """
- Code for prompting the openai models
- Given a csv file with a column of text,
- construct the prompt
- call openai's api for each sample
- save each output
- save the results to a csv file
from openai import OpenAI
add path to the prompts folder
import os import sys sys.path.append("/home/esther/PycharmProjects/edut710/holocaust_mentions/prompting") from prompts.explicit_mentions_prompt import * from prompts.translate import * from prompts.metadata_prompt import * from prompts.segmentation_prompt import * from read_data import * import os from argparse import ArgumentParser
os.environ[ "OPENAI_API_KEY"] = ( "sk-proj-XXX")
SYS_PROMPTS = {"FEW1": fewshot_p1, "FEW": fewshot_prompt, "DEF": prompt, "P_0": prompt0, "G_P0": g_prompt, "HEB_G_P": heb_g_prompt, "HEB_P": heb_prompt, "TRANSLATE": translate_prompt, "FEW_SEG": fewshot_by_segment, "FEW_FULL_TEXT": many_few_shot_full_text, "FEW_SEG_250": expanded_few_shot, "SHORT": fewshot_short_version, "SHORT_1": fewshot_short_version_1, "SHOAH_SHORT": holocaust_survivors_fewshot_short, "DIRECT_MENTIONS_0": expanded_few_shot_fixed, "WIDER_CONTEXT": fewshot_wider_context, "WITH_CONTEXT": fewshot_with_context, "SHOAH_SHORT_V2": holocaust_survivors_short_v2, "SEGMENT": segment_prompt_v0, "FS_KWORDS": FEWSHOT_NEW_KWORDS, "FS_V2_KWORDS": FEWSHOT_V2_NEW_KWORDS, "HS_LONG": HOLOCAUST_SURVIVORS_LONG, "HS_SHORT": HOLOCAUST_SURVIVORS_SHORT, "CM": COLLECTIVE_MEMMORY_PROMPT,}
MODELS = {"gpt40-11-24": "gpt-4o-2024-11-20", "gpt4_1": "gpt-4.1-2025-04-14", "gpt4_1-mini": "gpt-4.1-2025-04-14-mini", }
USER_PROMPTS = {"DEF": '"""{sample}\n"""', "FEW": '"{sample}"\nAssistant:', "FEW1": '"{sample}"\nAssistant:', "TRANSLATE": '{sample}', "META": '{sample}', "FEW_SEG": '{sample}', "FEW_FULL_TEXT": '{sample}', "FEW_SEG_250": '{sample}', "SHORT": '{sample}', "SHORT_1": '{sample}', "SHOAH_SHORT": '{sample}', "DIRECT_MENTIONS_0": '{sample}', "WIDER_CONTEXT": '{sample}', "WITH_CONTEXT": '{sample}', "SHOAH_SHORT_V2": '{sample}', "SEGMENT": '{sample}', "FS_KWORDS": "{sample}", "FS_V2_KWORDS": "{sample}", "HS_LONG": "{sample}", "HS_SHORT": "{sample}", "CM": "{sample}", } temperature = 0.0 orig_temp = 0.0, translate_temperature = 0.0 top_p = 1
ALL_SPLITS = True
def send_prompt(sample, model_k, temp, sys_prompt, prompt_key, json_schema=None): client = OpenAI() model = MODELS[model_k]
- Assistant
The model does not keep the history of each sample across rows. Here's why: 💡 Key Behavior: Each row is processed independently in the loop: pythonCopyEditfor index, row in out_df.iterrows(): if pd.isna(row[out_col]): ... response = send_prompt(row[input_col], ...)
📦 send_prompt() Function: This function sends a single request to OpenAI's API per sample: pythonCopyEditreturn client.chat.completions.create( model=model, messages=[ {"role": "system", "content": [...]}, {"role": "user", "content": [...]}, ], ... )
Each request includes only a system prompt and a user prompt.
There is no history or memory passed in from previous rows.
The API treats this like a fresh conversation every time.
✅ Conclusion: The script starts a new session for each row and does not retain history between samples. Each prompt is a self-contained unit without context from any other row in the CSV.