Skip to content

savantly-net/ax-test

Repository files navigation

AI Chat Agent with Ax

A simple question/answer chat agent built with Next.js and the Ax library.

Features

  • 🤖 AI-powered Q&A using Ax DSPy signatures
  • 🏗️ Nested objects and complex structured outputs
  • ⚡ Type-safe AI interactions with TypeScript
  • 🎨 Clean, modern UI with dark mode support
  • 🚀 Edge runtime for fast responses
  • 📊 Rich metadata including confidence, sentiment, and complexity

Setup

  1. Install dependencies:

    pnpm install
  2. Set up your OpenAI API key:

    Create a .env.local file in the root directory:

    OPENAI_APIKEY=your_openai_api_key_here
  3. Run the development server:

    pnpm dev
  4. Open your browser:

    Navigate to http://localhost:3000

How It Works

This app uses the Ax library to create a Q&A agent with complex structured outputs using DSPy signatures:

const qaAgent = ax(`
  question:string "User's question" ->
  answer:string "Comprehensive answer to the question",
  confidence:number "Confidence score from 0 to 1",
  sentiment:class "positive, neutral, negative" "Overall sentiment",
  relatedTopics:string[] "Related topics or concepts (2-4 items)",
  keyPoints:string[] "Key takeaways from the answer (2-3 items)",
  sources:string[] "Suggested sources or references (1-3 items)",
  followUpQuestions:string[] "Relevant follow-up questions (2-3 items)"
`);

The signature defines:

  • Input: question:string - The user's question
  • Outputs: Multiple structured fields including:
    • answer - The main response
    • confidence - How confident the AI is (0-1)
    • sentiment - Classified sentiment (positive/neutral/negative)
    • relatedTopics - Array of related concepts
    • keyPoints - Bullet points of key information
    • sources - Suggested references
    • followUpQuestions - Questions to explore further

Ax automatically generates optimal prompts and handles the LLM interaction, giving you type-safe, structured AI responses with rich metadata.

Project Structure

├── app/
│   ├── api/chat/route.ts      # API endpoint using Ax
│   ├── components/
│   │   └── ChatAgent.tsx      # Chat UI component
│   └── page.tsx               # Homepage
├── .env.local                 # Your API keys (create this)
└── package.json

Learn More

License

MIT

About

A test with Ax to show complex signature

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published