OpenAI Assistant - Function Calling

Hi everyone! I’m having an issue with function calling using the OpenAI Ask Assistant block. My use case is simple: the user says their name, and the assistant should send this name to my API, which returns the corresponding surname.
6 Replies
Daniel Prazeres
Daniel PrazeresOP7d ago
FastAPI backend:
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class NomeRequest(BaseModel):
nome: str

@app.post("/receber-nome")
def receber_nome(payload: NomeRequest):
nome = payload.nome.lower()
sobrenomes = {
"daniel": "Prazeres",
"joão": "Silva",
"maria": "Souza"
}
sobrenome = sobrenomes.get(nome, "Desconhecido")
print(f"Nome recebido: {payload.nome}. Sobrenome retornado: {sobrenome}")
return { "sobrenome": sobrenome }
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class NomeRequest(BaseModel):
nome: str

@app.post("/receber-nome")
def receber_nome(payload: NomeRequest):
nome = payload.nome.lower()
sobrenomes = {
"daniel": "Prazeres",
"joão": "Silva",
"maria": "Souza"
}
sobrenome = sobrenomes.get(nome, "Desconhecido")
print(f"Nome recebido: {payload.nome}. Sobrenome retornado: {sobrenome}")
return { "sobrenome": sobrenome }
Typebot function code:
try {
const response = await fetch("https://21f3-181-81-108-115.ngrok-free.app/receber-nome", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ nome: nome })
});

const json = await response.json();
const sobrenome = json.sobrenome;

setVariable("sobrenome_usuario", sobrenome);
return `Seu sobrenome é ${sobrenome}. Está correto?`;

} catch (error) {
return `Erro ao buscar sobrenome: ${error.message}`;
}
try {
const response = await fetch("https://21f3-181-81-108-115.ngrok-free.app/receber-nome", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ nome: nome })
});

const json = await response.json();
const sobrenome = json.sobrenome;

setVariable("sobrenome_usuario", sobrenome);
return `Seu sobrenome é ${sobrenome}. Está correto?`;

} catch (error) {
return `Erro ao buscar sobrenome: ${error.message}`;
}
OpenAI function JSON:
{
"name": "capturar_nome",
"description": "Captura o nome do usuário e envia para uma API externa.",
"strict": false,
"parameters": {
"type": "object",
"properties": {
"nome": {
"type": "string",
"description": "O nome do usuário"
}
},
"required": ["nome"]
}
}
{
"name": "capturar_nome",
"description": "Captura o nome do usuário e envia para uma API externa.",
"strict": false,
"parameters": {
"type": "object",
"properties": {
"nome": {
"type": "string",
"description": "O nome do usuário"
}
},
"required": ["nome"]
}
}
What’s happening: When I type: “Hi! My name is Daniel. What is my surname?” The assistant responds: ❌ “There was an error trying to retrieve your surname…” BUT: • The API is called (confirmed in FastAPI logs) • It returns 200 OK • The response is { "sobrenome": "Prazeres" } So everything seems fine on the backend. Has anyone encountered something like this? Am I missing something in the assistant config or function setup? Thanks in advance 🙏
Daniel Prazeres
Daniel PrazeresOP7d ago
No description
No description
Baptiste
Baptiste6d ago
Use the HTTP request block, it's made for that: https://docs.typebot.io/editor/blocks/integrations/http-request
Daniel Prazeres
Daniel PrazeresOP5d ago
Should I be using the HTTP Request block separately and connect it somehow to the Ask Assistant? Because I only have the information “name” (it’s a example) during the conversation between the agent and the customer. My goal is trigger an agent function, send an information and retrieve an information, give that response to the agent and then answer the customer.
Baptiste
Baptiste5d ago
So sorry about that, I read your post too fast

Did you find this page helpful?