AI
How to use AI in next-forge.
next-forge has a pre-configured ai
package that uses ai-sdk to provide a simple interface for interacting with AI models.
Usage
To use AI functionality, you can import it from the @repo/ai
package.
Generating text
You can use the generateText
function to generate text from an AI model. For example:
Components
The AI package comes with a few components that you can use to build your own AI chatbot, such as Thread
and Message
.
Adding payment agentic capabilities
You can use the paymentsAgentToolkit
to add payments capabilities to your AI agent for financial services. As next-forge uses Stripe by default, here’s an example of how to use it:
Adding analytics
There are quite a few ways to add analytics to your AI agent depending on your use case, environment and whether you’re generating or streaming.
Here’s a simple example of how to add analytics to a generateText
request using our analytics
package:
Using a different provider
If you want to use a different provider, you can modify the provider
in @repo/ai/lib/provider.ts
to use the one you want. For example, to use Anthropic, you can change it to: