Build a Tool from Your Data Source
With watsonx.ai Flows Engine, you can turn any data source (REST APIs, GraphQL, Databases) into a tool you can use with an LLM. To build a tool, you need to have the watsonx.ai Flows Engine Node.js CLI installed and sign up for a free account.
Import Your Data Source
The data sources used as tools should be specified as a GraphQL schema. To generate a GraphQL schema for your data sources, you can either use the CLI or create GraphQL schemas from scratch.
Using the CLI
You can use the Node.js CLI to generate a GraphQL schema for the following data sources:
To use the CLI, you need to have Node.js and npm installed on your machine.
1. Install the CLI by following the instructions
2. Authenticate using your account information:
wxflows login
- Provide your account name
- Provide the admin key
3. Create a new directory for your project, and run the
mkdir my-project
wxflows init
You'll be asked to set the endpoint name for your project.
4. Run the
wxflows import curl
wxflows import openapi
wxflows import graphql
wxflows import mysql
wxflows import postgresql
wxflows import snowflake
You can append the
5. Modify the generated files:
After importing your data source as a GraphQL file, you can make changes to the generated
6. Proceed to registering your tool(s):
Finally, go to the next section to learn how to register your tool(s) and make them available for use in your application.
In some cases, you may need to write the GraphQL schema manually. This is necessary when using data sources not supported by the CLI (like MSSQL, Presto, Singlestore, Trino, or SOAP/XML) or when importing your supported data source fails due to authorization constraints like self-signed certificates.
Write a GraphQL Schema
If you choose not to use the CLI, you can write the GraphQL schemas for your data sources manually. This requires using a custom directive to connect to the data source. You can find detailed information about creating schemas with custom directives here.
Below is an example of a GraphQL schema:
type Customer {
email: String
id: ID
name: String
}
type Query {
customerById(id: ID!): Customer
@rest(endpoint: "https://introspection.apis.stepzen.com/customers/$id")
}
In this schema, the
Any
schema
@sdl(files: ["custom/index.graphql"]) { # Add your file here
query: Query
}
The following custom directives are currently supported:
- @rest
- @graphql
- @dbquery
After writing the GraphQL schema, proceed to the next section to learn how to register your tool(s) and make them available for use in your application.