I’m really new to this, so if my questions are really basic please bear with me.
First question
I’ve got the following function in which the output is a DataFrame. The function performs some calculations, the calculations aren’t particularly relevant to my question, just that the output is a DataFrame:
def my_function():
conn = st.connection(‘mysql’, type=‘sql’)
df = conn.query(‘SELECT * FROM db.my_table’)
df = df.set_index(‘Date’)
list_bm = pd.date_range(df.index.min(), df.index.max(), freq=‘BME’).tolist()
df2 = df.loc[df.index.isin(list_bm)]
df3 = df2.diff(periods=-1)
df4 = (df3/df2.shift(-1))100
w = 6.25/100
df5 = df4.drop(‘A-Column’, axis=‘columns’)
df5 = df5w
df5[‘B_Column’] = df5.sum(axis=1)
df6 = df5.drop(df5.iloc[:, 0:16], axis=‘columns’)
df6[‘A_Column’] = df4[‘A_Column’]
df6[‘C_Column’] = df6[‘A_Column’] - df6[‘B_Column’]
df6[‘Result’] = np.where(df6[‘C_Column’] < 0, ‘Yes’, ‘No’)
df6.drop(df6.tail(1).index,inplace=True)
return df6
So, I’m not quite sure how the tool variable ought to work, since the output isn’t a string or a number, and as you can see, there aren’t any arguments to call. So, my tool variable is a follows:
tools = [
{
“type”: “function”,
“function”: {
“name”: “my_function”,
“description”: “Does what it’s supposed to do.”,
“parameters”: {
“type”: “object”,
“properties”: {
“df6”: {
“type”: “object”,
“description”: “The resulting DataFrame.”,
},
},
“required”: [“df6”],
},
},
}
]
I understand this is probably not correct, but I’ve got no idea how to work this out. So, my question is: How can I work the “tools” variable properly, so that it delivers a DataFrame.
Currently, I’m getting this:
Second question
The app I’m developing already has an agent for SQL, and thus it already had a response variable:
agent_executor = create_sql_agent(llm, toolkit=toolkit, agent_type=“openai-tools”, prompt=final_prompt, verbose=True)
response= ask_question_and_update_history(question, history_ai, agent_executor)
Thus, I’m not sure how to work with this out, since the Chat.Completions.Create (i.e. the function caller) has its own response:
def get_completion(messages,model=st.secrets[“OPENAI_CHAT_MODEL”],temperature=0,tools=None,tool_choice=None):
response = openai.chat.completions.create(
model=model,
messages=messages,
temperature=temperature,
tools=tools,
tool_choice=tool_choice
)
return response.choices[0].message
messages = [
{
“role”: “user”,
“content”: “My specific question that needs a function.”
}
]
response = get_completion(messages, tools=tools)
Thus, my second question is: How can I make it so that I keep my SQL Agent and the responses it ought to deliver, alongside the Chat.Completions.Create which is supposed to answer a specific question?
I appreciate any help. Thanks in advance.
