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

Feature/add endpoints for realtime api #3318

Merged
merged 1 commit into from
Oct 7, 2024
Merged

Conversation

HenryHengZJ
Copy link
Contributor

@HenryHengZJ HenryHengZJ commented Oct 7, 2024

  • GET openai-realtime/:id will retrieve the tools connected on the chatflow
  • POST openai-realtime/:id will execute the tool specified in the request body

How to use it: https://github.com/FlowiseAI/openai-realtime-console

After realtime client is initialized, simply add the tools:

const fetchTools = async () => {
    const response = await fetch(`${FLOWISE_BASE_URL}/api/v1/openai-realtime/${FLOWISE_CHATFLOW_ID}`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + FLOWISE_API_KEY
      }
    });
    const tools = await response.json();
    if (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;

            // do something with the output

            return toolOutput;
          }
        );
      };
    }
  };

@HenryHengZJ HenryHengZJ merged commit 14b7148 into main Oct 7, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant