Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions NODEJS_VERSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Node.js Version - Quick Start Guide

## What is This?

This is the **Node.js version** of the Tool Calling API project. It provides the same functionality as the Python version but uses Node.js, Express, and modern JavaScript practices.

## Location

The Node.js version is located in the `nodejs_version/` directory.

## Quick Start

```bash
# Navigate to the Node.js version
cd nodejs_version

# Install dependencies
npm install

# Configure environment
cp .env.example .env
# Edit .env with your Africa's Talking credentials

# Start the server
npm start
```

The API will be available at http://localhost:3000

## Key Differences from Python Version

| Feature | Python | Node.js |
|---------|--------|---------|
| Interface | Gradio Web UI | REST API |
| Port | 7860 | 3000 |
| Usage | Web browser | HTTP requests |
| Framework | Gradio + Flask | Express |
| Validation | Pydantic | Zod |

## API Usage

### Python (Gradio)
1. Open http://localhost:7860
2. Type message in chat
3. Get response in UI

### Node.js (REST API)
```bash
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d '{"message": "Send airtime to +254712345678 with 10 KES"}'
```

## Documentation

For complete documentation, see:
- `nodejs_version/README.md` - Full documentation
- `nodejs_version/IMPLEMENTATION_SUMMARY.md` - Implementation details
- `nodejs_version/PYTHON_VS_NODEJS.md` - Comparison guide

## Features

- ✅ Send airtime
- ✅ Send SMS
- ✅ Search news
- ✅ Translate text
- ✅ Send USSD
- ✅ Send mobile data
- ✅ Get balance

## Requirements

- Node.js 18+
- Ollama running locally
- Africa's Talking credentials

## Testing

```bash
cd nodejs_version
npm test
```

## Questions?

Check the comprehensive documentation in `nodejs_version/README.md`
15 changes: 15 additions & 0 deletions nodejs_version/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Africa's Talking API Credentials
AT_USERNAME=sandbox
AT_API_KEY=your_api_key_here

# Test Configuration
TEST_PHONE_NUMBER=+254712345678

# Server Configuration
PORT=3000

# Logging Configuration
LOG_LEVEL=info

# Ollama Configuration (optional - defaults to localhost:11434)
# OLLAMA_HOST=http://localhost:11434
133 changes: 133 additions & 0 deletions nodejs_version/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Audio files
*.mp3
10 changes: 10 additions & 0 deletions nodejs_version/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
semi: true,
trailingComma: 'es5',
singleQuote: true,
printWidth: 100,
tabWidth: 2,
useTabs: false,
arrowParens: 'always',
endOfLine: 'lf',
};
25 changes: 25 additions & 0 deletions nodejs_version/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Node.js Tool Calling API Dockerfile

FROM node:18-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy application files
COPY . .

# Expose port
EXPOSE 3000

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1); });"

# Run the application
CMD ["node", "app.js"]
Loading