I’m trying to implement in-context learning using an assistant. I came across this thread (Few-shot and function calling - #15 by lucas.godfrey1000), but the code in the thread uses openai.ChatCompletion.create rather than client.beta.threads.messages.create. However, the client.beta.threads.messages.create function expects only 2 arguments, and I can’t figure out how to pass the “function_call” key and value to the assistant.
Here is a trimmed example of my code:
# Define schema for assistant function
schema = {
"type": "object",
"properties": {
"property1": {
"type": "array",
"items": {
"type": "string",
},
"description": f"description of property"},
},
"required": ["property1"]
}
# Create an assistant to run the function
assistant = client.beta.assistants.create(
name="assistant name",
instructions="You are an information retrieval agent that will extract specific properties from text I provide you...",
tools=[{
"type": "function",
"function": {
"name": "extract_information",
"parameters": schema
}
}],
model="gpt-4-turbo-preview",
)
# Create an example user message calling the function extract_information
client.beta.threads.messages.create(thread.id, {
"role": "user",
"content": f"Extract information from the following text: \n\n {text goes here}"
})
# Create an example response to the user's input for in-context learning
client.beta.threads.messages.create(thread.id, {
"role": "function",
"content": "",
"function_call": {
"name": "extract_information",
"arguments": {"property1": ["example1", "example"2]}
}
})