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:
Customizing the AI agent rules
To those that use Cursor or GitHub Copilot - You can customize the AI agent rules by updating the respected file listed below. For context, each chat response will read through the file and repspond with a more currated response based on your rules. It is important to
Cursor
Update the .cursorrules
file to customize the AI agent to your project needs. These rules can be updated at any time and will better help you over time.
Great examples of how to customize your Cursor Rules can be found at awesome-cursorrules.
Learn more about Cursor Rules.
GitHub Copilot
In order to begin using GitHub Copilot Instructions, you must first enable the Use Instruction Files
setting in VSCode.
Update the .github/copilot-instructions.md
file to customize the AI agent to your project needs. These instructions can be updated at any time and will better help you over time.