#Openai function usecase

1 messages · Page 1 of 1 (latest)

topaz lotus
#

Can you asses if my use case is fit for using function: I want the chatgpt-3 model, based on the conversation it has with a user, to asses if a meeting with a real human is necessary, ask the user if that's what it wants, ask for the required data to make the meeting and the call a function to make the meeting.
The prompt that I provided is a standard "you are a assistant designed to help the user with it's problems".
I made this workflow and the problem I'm encountering is that the model asks the user if it wants a meeting, the user responds yes and then the model calls the function and makes up a date without asking the user for one. I want to add other functionalities like this one so I would avoid explaining to much in the prompt about each specific function as I don't think this would be the correct approach (correct me if I'm wrong), but event with explicit system prompt that it should ask for date and time it still does not do that.

wicked salmonBOT
#

Hi @topaz lotus. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Your use case seems to be a good fit for OpenAI's function calling feature. You can define a function that schedules a meeting based on user preferences and calendar availability. The model can suggest the best times and dates to call this function based on the conversation it has with the user source (https://platform.openai.com/docs/guides/function-calling#faq-what-are-some-example-functions).

However, it seems like you're encountering an issue where the model is not asking the user for a date before calling the function. This could be due to the way you're instructing the model in your system prompt. The system prompt is used to guide the model's behavior, and providing clear instructions in your system message can significantly improve the model's function calling accuracy source (https://platform.openai.com/docs/guides/function-calling#tips-and-best-practices-consider-providing-additional-information-about-how-and-when-to-call-functions-in-your-system-message).

You could try to make your system prompt more explicit about the steps the model should take before calling the function. For example, you could instruct the model to always ask the user for a date and time before scheduling a meeting. However, you're correct that adding too many specific instructions for each function in the system prompt might not be the best approach, especially if you plan to add more functionalities in the future.

#

Another approach could be to modify your function to require a date and time as parameters. This way, the model would have to generate these parameters before it can call the function. You could also consider using a multi-step process where the model first calls a function to check the user's availability, and then calls the scheduling function based on the results source (https://platform.openai.com/docs/guides/function-calling#the-lifecycle-of-a-function-call).

Remember that the model never actually executes functions itself, it simply generates parameters that can be used to call your function. Your application is always in full control source (https://platform.openai.com/docs/guides/function-calling#the-lifecycle-of-a-function-call).

Here's an example of how you could structure your code to implement this multi-step process:

SYSTEM_MESSAGE = """
You are a helpful assistant.
Respond to the following prompt by using function_call and then summarize actions.
Ask for clarification if a user request is ambiguous.
"""

MAX_CALLS = 5

def get_openai_response(functions, messages):
    return client.chat.completions.create(
        model="gpt-3.5-turbo-16k",
        tools=functions,
        tool_choice="auto",
        temperature=0,
        messages=messages,
    )

def process_user_instruction(functions, instruction):
    num_calls = 0
    messages = [
        {"content": SYSTEM_MESSAGE, "role": "system"},
        {"content": instruction, "role": "user"},
    ]

    while num_calls < MAX_CALLS:
        response = get_openai_response(functions, messages)
        message = response.choices[0].message
        print(message)
        try:
            print(f"\n>> Function call #: {num_calls + 1}\n")
            pp(message.tool_calls)
            messages.append(message)
#

For the sake of this example, we'll simply add a message to simulate success.

        # Normally, you'd want to call the function here, and append the results to messages.
        messages.append(
            {
                "role": "tool",
                "content": "success",
                "tool_call_id": message.tool_calls[0].id,
            }
        )
[source](<https://cookbook.openai.com/examples/function_calling_with_an_openapi_spec#how-to-call-these-functions>
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
#

@topaz lotus kapa.ai is still learning and improving, please let us know how it did by reacting below

topaz lotus
#

@wicked salmon I see that using gpt-4o works better and asks for the required informations, is gpt-3 not setup to work with functions? I need gpt-3 for the speed and cost

wicked salmonBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Function calling was introduced with the release of gpt-4-turbo on June 13, 2023. The models that support function calling include various versions of gpt-4o, gpt-4-turbo, and gpt-3.5-turbo. Legacy models released before this date, which would include the original gpt-3, were not trained to support function calling source (https://platform.openai.com/docs/guides/function-calling#faq-which-models-support-function-calling).

If you're looking for a balance between cost, speed, and the ability to use function calling, you might want to consider using gpt-4o-mini or gpt-3.5-turbo. As of July 2024, gpt-4o-mini is recommended to be used in place of gpt-3.5-turbo, as it is cheaper, more capable, multimodal, and just as fast source (https://platform.openai.com/docs/models/gpt-3-5-turbo).

However, it's important to note that while gpt-3.5-turbo is faster than gpt-4 and gpt-4-turbo, it's recommended to use gpt-4 for improved reliability and creativity on higher complexity tasks source (https://help.openai.com/en/articles/8555514-gpt-3-5-turbo-updates).

You can experiment with these models in the playground (https://platform.openai.com/playground?mode=chat) to see which one provides the best price performance trade-off for your usage.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@topaz lotus kapa.ai is still learning and improving, please let us know how it did by reacting below

topaz lotus
#

can the gpt-4o-mini be finetunned using the openai platform?

#

@wicked salmon cant he gpt-4o-mini be finetunned using the openai platform?

wicked salmonBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Yes, the gpt-4o-mini model can be fine-tuned using the OpenAI platform. Fine-tuning is a process that allows you to customize the base model to better suit your specific use case by training it on your own dataset.

As of the information available, fine-tuning is available for the gpt-4o-mini-2024-07-18 model, among others. It's recommended for most users in terms of performance, cost, and ease of use source (https://platform.openai.com/docs/guides/fine-tuning).

To start a fine-tuning job, you can use the OpenAI SDK. Here's an example of how to do it:

from openai import OpenAI
client = OpenAI()

client.fine_tuning.jobs.create(
  training_file="file-abc123", 
  model="gpt-4o-mini"
)

In this example, model is the name of the model you want to fine-tune (gpt-4o-mini, gpt-3.5-turbo, babbage-002, davinci-002, or an existing fine-tuned model) and training_file is the file ID that was returned when the training file was uploaded to the OpenAI API source (https://platform.openai.com/docs/guides/fine-tuning).

Please note that GPT-4o mini fine-tuning is available to developers in OpenAI's Tier 4 and 5 usage tiers source (https://cookbook.openai.com/examples/how_to_finetune_chat_models).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@topaz lotus kapa.ai is still learning and improving, please let us know how it did by reacting below

topaz lotus
#

@wicked salmon what is the price difference between gpt-3-turbo and gpt-4o-mini?

wicked salmonBOT
#

Let me check the knowledge base for you. One moment! :books:

#

The pricing for gpt-4o-mini and gpt-3.5-turbo differs significantly.

For gpt-4o-mini, the cost is $0.15 per 1 million input tokens and $0.60 per 1 million output tokens source (https://platform.openai.com/docs/models).

On the other hand, the pricing for gpt-3.5-turbo has been reduced to $0.50 per 1 million tokens for input and $1.50 per 1 million tokens for output source (https://help.openai.com/en/articles/8555514-gpt-3-5-turbo-updates).

So, gpt-4o-mini is significantly cheaper than gpt-3.5-turbo for both input and output tokens.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: