I am using ChatGPT to help me code a chatbot and I want to give it fuctions.
I wanted to start by giving it the ability to know the date and time. I am very beginner with coding but with ChatGPTs help, I have a bot that connects to twitch and receives prompts from chat and responds.
The python code connects to an already created assistant in the playground and I want to past the code for the function into the Assistants UI on the OpenAI Dashboard.
The problem I am running into is that all the tutorials and documentation is showing how to, in the code, create the assistant, create the tool when for me, these components are already created and I don’t know enough to try to adapt it into a script where those things exist already.
I got as far as having the bot return “requires_action” in the terminal over and over again, I have the time module in the main script but i don’t know what to do form here and ChatGPT keeps giving me code that doesn’t work.
Some helpful people wrote CustomGPTs that will write the Assistant action code for you.
It just requires to paste in the API’s documentation, and it returns the action code to paste into the Ai Assistant.
I can’t access it atm, but try search in ExploreGPT menu on ChatGPT for “Create action” or “API to action”.
Thanks I’ll check it out.
The issue I keep having is that my code is wildly different from any of the examples I can find. Here is what I have and I can’t figure out how to integrate the function calling
class OpenAIIntegration:
def init(self, api_key):
# Initialize the OpenAI client with the provided API key
self.client = OpenAI(api_key=api_key)
# This is the function that we want the model to be able to call
def get_current_time_and_date(self):
from datetime import datetime
now = datetime.now()
return now.strftime("%Y-%m-%d %H:%M:%S")
# ...
def create_shared_thread(self):
# Create a new shared conversation thread
thread = self.client.beta.threads.create(
messages=[{"role": "user", "content": "This is the start of a shared conversation."}]
)
return thread.id
def add_message_to_thread(self, thread_id, role, content):
# Add a new message to an existing thread
self.client.beta.threads.messages.create(
thread_id=thread_id,
role=role,
content=content,
)
def run_thread(self, thread_id, assistant_id):
# Start a run for the thread and poll until it completes
run = self.client.beta.threads.runs.create_and_poll(thread_id=thread_id, assistant_id=assistant_id)
print(f"👉 Run Created: {run.id}")
# Polling the run status until it completes
while run.status != "completed":
run = self.client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
print(f"🏃 Run Status: {run.status}")
time.sleep(1)
print(f"🏁 Run Completed!")
return run