Wonderful article!
Some modification for initiate the chat - due to OpenAI module upgrade:
Chat operation and data addition must be in the for cycle.
for index, row in dataset.iterrows():
messages = [
{
"role": "system",
"content": "For each company, I will give you the followwing information: Company, Price to Earnings, Price to Book, Return to Equity%, Debt to Equity, Current Ratio, Gross Margin%. Then, I will analyze the ratios and write a brief summary using the company name "
},
{
"role": "user",
"content": ''.join([str(col) for col in row])
}
]
chat = client.chat.completions.create(
model="your_model_name",
messages = messages,
temperature=0.7,
max_tokens=800,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
reply = chat.choices[0].message.content
# Write the response Back to the Report
dataset.at[index, "result"] = reply