Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fil tools error preventing interface from showing #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 37 additions & 42 deletions src/pages/ConsolePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ export function ConsolePage() {
* Set all of our instructions, tools, events and more
*/
useEffect(() => {
// Get refs
const wavStreamPlayer = wavStreamPlayerRef.current;
const client = clientRef.current;

Expand All @@ -408,7 +407,6 @@ export function ConsolePage() {
// Set transcription, otherwise we don't get user transcriptions back
client.updateSession({ input_audio_transcription: { model: 'whisper-1' } });

// execute fetch request to get the tools
const fetchTools = async () => {
const response = await fetch(`${FLOWISE_BASE_URL}/api/v1/openai-realtime/${FLOWISE_CHATFLOW_ID}`, {
method: 'GET',
Expand All @@ -417,47 +415,44 @@ export function ConsolePage() {
'Authorization': 'Bearer ' + FLOWISE_API_KEY
}
});
const tools = await response.json();
if (tools) {
setTools(tools);
for (const tool of tools) {
if (Object.hasOwnProperty.call(client.tools, tool.name)) continue
client.addTool(tool,
async (args: any) => {
const response = await fetch(`${FLOWISE_BASE_URL}/api/v1/openai-realtime/${FLOWISE_CHATFLOW_ID}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + FLOWISE_API_KEY
},
body: JSON.stringify({
chatId: sessionID,
toolName: tool.name,
inputArgs: args,
}),
});
const result = await response.json();
const toolOutput = result.output;
const sources = result.sourceDocuments;
const artifacts = result.artifacts;

setTools((tools) => {
const newTools = [...tools];
const toolIndex = newTools.findIndex((t) => t.name === tool.name);
if (toolIndex >= 0) {
const newTool = { ...newTools[toolIndex] };
newTool.messages = newTool.messages || [];
newTool.messages.push({ type: 'input', content: JSON.stringify(args) });
newTool.messages.push({ type: 'output', content: toolOutput, sources, artifacts });
newTools[toolIndex] = newTool;
}
return newTools;
});

return toolOutput;
const data = await response.json();
const tools = Array.isArray(data) ? data : [];
setTools(tools);
for (const tool of tools) {
if (Object.hasOwnProperty.call(client.tools, tool.name)) continue
client.addTool(tool, async (args: any) => {
const response = await fetch(`${FLOWISE_BASE_URL}/api/v1/openai-realtime/${FLOWISE_CHATFLOW_ID}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + FLOWISE_API_KEY
},
body: JSON.stringify({
chatId: sessionID,
toolName: tool.name,
inputArgs: args,
}),
});
const result = await response.json();
const toolOutput = result.output;
const sources = result.sourceDocuments;
const artifacts = result.artifacts;

setTools((tools) => {
const newTools = [...tools];
const toolIndex = newTools.findIndex((t) => t.name === tool.name);
if (toolIndex >= 0) {
const newTool = { ...newTools[toolIndex] };
newTool.messages = newTool.messages || [];
newTool.messages.push({ type: 'input', content: JSON.stringify(args) });
newTool.messages.push({ type: 'output', content: toolOutput, sources, artifacts });
newTools[toolIndex] = newTool;
}
);
};
return newTools;
});

return toolOutput;
});
}
};

Expand Down