Ashar086 commited on
Commit
07b34e1
·
verified ·
1 Parent(s): d566377

Create openai_agent.py

Browse files
Files changed (1) hide show
  1. openai_agent.py +23 -0
openai_agent.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+
3
+ class OpenAIAgent:
4
+ def __init__(self):
5
+ # Make sure to set your OpenAI API key in your environment variables
6
+ openai.api_key = "c496d9094ba54ddb9d66eeeb35a6196f"
7
+
8
+ def get_insights(self, df, prompt):
9
+ # Prepare the data for the API call
10
+ data_sample = df.head(5).to_string()
11
+
12
+ messages = [
13
+ {"role": "system", "content": "You are a data analyst assistant."},
14
+ {"role": "user", "content": f"Here's a sample of my data:\n{data_sample}\n\nBased on this data, {prompt}"}
15
+ ]
16
+
17
+ response = openai.ChatCompletion.create(
18
+ model="gpt 4o",
19
+ messages=messages,
20
+ max_tokens=150
21
+ )
22
+
23
+ return response.choices[0].message['content']