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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here

# Model Configuration
# Options: gpt-3.5-turbo, gpt-4, gpt-4-turbo-preview, gpt-5.1-codex-max
OPENAI_MODEL=gpt-5.1-codex-max

# Application Configuration
PORT=3000
NODE_ENV=development
54 changes: 49 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Web3AI

Web3AI is an AI-powered blockchain and Web3 development toolkit that integrates OpenAI's capabilities with blockchain technologies.
Web3AI is an AI-powered blockchain and Web3 development toolkit that integrates OpenAI's capabilities with blockchain technologies. Now featuring **GPT-5.1-Codex-Max** for enhanced code generation, analysis, and blockchain insights.

## 🌟 Features

- **Node.js Backend**: Server-side JavaScript for Web3 applications
- **OpenAI Integration**: AI-powered smart contract analysis, code generation, and blockchain insights
- **GPT-5.1-Codex-Max Support**: Advanced AI model for superior code understanding and generation
- **Python AI Scripts**: Advanced AI capabilities for blockchain development
- **Modular Architecture**: Easy to extend with additional AI or blockchain features
- **Configurable Models**: Support for multiple OpenAI models (GPT-3.5, GPT-4, GPT-5.1-Codex-Max)

## 📋 Prerequisites

Expand Down Expand Up @@ -82,12 +84,27 @@ Your `.env` file should look like this:

```
OPENAI_API_KEY=sk-your-actual-api-key-here
OPENAI_MODEL=gpt-5.1-codex-max
PORT=3000
NODE_ENV=development
```

⚠️ **Important**: Never commit your `.env` file to version control. It's already included in `.gitignore`.

### 5. Choose Your AI Model (Optional)

The project defaults to **GPT-5.1-Codex-Max**, which provides:
- Superior code generation and analysis
- Enhanced smart contract security insights
- Better understanding of Web3 concepts
- Advanced reasoning capabilities

You can change the model by editing the `OPENAI_MODEL` variable in your `.env` file:
- `gpt-5.1-codex-max` (default, recommended)
- `gpt-4-turbo-preview` (alternative, also very capable)
- `gpt-4` (stable alternative)
- `gpt-3.5-turbo` (faster, more cost-effective)

## 🎯 Usage

### Running the Node.js Application
Expand All @@ -98,7 +115,7 @@ Start the main application:
npm start
```

This will run the OpenAI integration demo and show you how to interact with AI models.
This will run the OpenAI integration demo using GPT-5.1-Codex-Max and show you how to interact with AI models.

### Running Python AI Scripts

Expand All @@ -109,9 +126,10 @@ python ai_scripts/sample_ai.py
```

This demonstrates:
- Explaining Web3 concepts using AI
- Analyzing smart contract code
- Explaining Web3 concepts using GPT-5.1-Codex-Max
- Analyzing smart contract code with advanced AI
- Integration with OpenAI's Python library
- Enhanced code analysis and security insights

## 📁 Project Structure

Expand All @@ -134,6 +152,30 @@ Web3AI/
- `npm start` - Run the main application
- `npm test` - Run tests (to be implemented)

## 🚀 GPT-5.1-Codex-Max Features

GPT-5.1-Codex-Max is OpenAI's most advanced code-focused model, offering:

### Enhanced Capabilities
- **Superior Code Generation**: Create complex smart contracts and blockchain applications with minimal prompting
- **Advanced Security Analysis**: Identify subtle vulnerabilities and security issues in smart contracts
- **Deep Web3 Understanding**: Comprehensive knowledge of blockchain protocols, DeFi, NFTs, and Web3 patterns
- **Contextual Awareness**: Better understanding of complex codebases and multi-file projects
- **Detailed Explanations**: More thorough and educational responses about Web3 concepts

### Use Cases
1. **Smart Contract Development**: Generate production-ready Solidity code
2. **Security Auditing**: Comprehensive vulnerability analysis and remediation suggestions
3. **Code Review**: In-depth analysis of existing blockchain code
4. **Learning Tool**: Detailed explanations of complex Web3 concepts
5. **Architecture Design**: High-level system design for blockchain applications

### Performance Notes
- GPT-5.1-Codex-Max provides more detailed and accurate responses compared to earlier models
- Response times may be slightly longer due to enhanced processing
- Token limits are higher, allowing for more comprehensive analysis
- Recommended for production applications and critical security analysis

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Expand Down Expand Up @@ -163,10 +205,12 @@ Make sure you have activated your virtual environment (if using one) and install

- Integration with blockchain networks (Ethereum, Polygon, etc.)
- Smart contract deployment automation
- AI-powered security auditing
- AI-powered security auditing with GPT-5.1-Codex-Max
- Web3 wallet integration
- NFT generation and analysis
- DeFi protocol interaction
- Advanced code generation for smart contracts
- Automated vulnerability detection and patching

## 📚 Resources

Expand Down
28 changes: 18 additions & 10 deletions ai_scripts/sample_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
This script demonstrates how to use OpenAI's Python library to interact
with AI models for Web3 and blockchain-related tasks.

Now featuring GPT-5.1-Codex-Max for enhanced code generation and analysis.

Requirements:
pip install openai python-dotenv
"""
Expand All @@ -15,6 +17,9 @@
# Load environment variables from .env file
load_dotenv()

# Default model - can be overridden with OPENAI_MODEL env variable
DEFAULT_MODEL = os.getenv('OPENAI_MODEL', 'gpt-5.1-codex-max')


def setup_openai():
"""
Expand All @@ -31,7 +36,8 @@ def setup_openai():
return None

client = OpenAI(api_key=api_key)
print('✅ OpenAI client initialized successfully\n')
print('✅ OpenAI client initialized successfully')
print(f'📊 Using model: {DEFAULT_MODEL}\n')
return client

except ImportError:
Expand All @@ -40,13 +46,14 @@ def setup_openai():
return None


def analyze_smart_contract(client, contract_code):
def analyze_smart_contract(client, contract_code, model=DEFAULT_MODEL):
"""
Example function to analyze smart contract code using AI

Args:
client: OpenAI client instance
contract_code: Smart contract code to analyze
model: AI model to use (defaults to GPT-5.1-Codex-Max)

Returns:
AI analysis of the contract
Expand All @@ -56,18 +63,18 @@ def analyze_smart_contract(client, contract_code):

try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
model=model,
messages=[
{
"role": "system",
"content": "You are an expert in blockchain and smart contract security. Analyze smart contracts for potential vulnerabilities and best practices."
"content": "You are an expert in blockchain and smart contract security. Analyze smart contracts for potential vulnerabilities and best practices. Provide detailed, actionable feedback."
},
{
"role": "user",
"content": f"Analyze this smart contract code:\n\n{contract_code}"
}
],
max_tokens=300,
max_tokens=500,
temperature=0.5
)

Expand All @@ -77,13 +84,14 @@ def analyze_smart_contract(client, contract_code):
return f"Error analyzing contract: {str(e)}"


def explain_web3_concept(client, concept):
def explain_web3_concept(client, concept, model=DEFAULT_MODEL):
"""
Get AI explanation of Web3 concepts

Args:
client: OpenAI client instance
concept: Web3 concept to explain
model: AI model to use (defaults to GPT-5.1-Codex-Max)

Returns:
AI explanation
Expand All @@ -93,18 +101,18 @@ def explain_web3_concept(client, concept):

try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
model=model,
messages=[
{
"role": "system",
"content": "You are a Web3 educator. Explain blockchain and Web3 concepts in simple, clear terms."
"content": "You are a Web3 educator. Explain blockchain and Web3 concepts in simple, clear terms with practical examples."
},
{
"role": "user",
"content": f"Explain: {concept}"
}
],
max_tokens=200,
max_tokens=400,
temperature=0.7
)

Expand All @@ -118,7 +126,7 @@ def run_demo():
"""
Run demonstration of AI capabilities
"""
print('🚀 Web3AI Python Demo')
print('🚀 Web3AI Python Demo (GPT-5.1-Codex-Max)')
print('=' * 50)
print()

Expand Down
19 changes: 14 additions & 5 deletions backend/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* This module demonstrates how to interact with OpenAI's API using the official SDK.
* It includes examples of using GPT models for various AI tasks.
*
* Now featuring GPT-5.1-Codex-Max for enhanced code generation and analysis.
*/

const OpenAI = require('openai');
Expand All @@ -12,25 +14,31 @@ const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

// Default to GPT-5.1-Codex-Max if no model is specified
const DEFAULT_MODEL = process.env.OPENAI_MODEL || 'gpt-5.1-codex-max';

/**
* Simple chat completion example
* Demonstrates basic interaction with GPT models
*
* @param {string} prompt - The user prompt to send to the AI
* @param {string} model - Optional model override (defaults to GPT-5.1-Codex-Max)
*/
async function chatCompletion(prompt) {
async function chatCompletion(prompt, model = DEFAULT_MODEL) {
try {
const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
model: model,
messages: [
{
role: "system",
content: "You are a helpful AI assistant specialized in Web3 and blockchain technologies."
content: "You are a helpful AI assistant specialized in Web3 and blockchain technologies. You have advanced code generation and analysis capabilities."
},
{
role: "user",
content: prompt
}
],
max_tokens: 150,
max_tokens: 500,
temperature: 0.7,
});

Expand All @@ -45,8 +53,9 @@ async function chatCompletion(prompt) {
* Run a demo of the OpenAI integration
*/
async function runDemo() {
console.log('🤖 OpenAI Integration Demo');
console.log('🤖 OpenAI Integration Demo (GPT-5.1-Codex-Max)');
console.log('─────────────────────────────\n');
console.log(`📊 Using model: ${DEFAULT_MODEL}\n`);

try {
const prompt = "What is Web3 and how does AI enhance blockchain development?";
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
*
* This is the main entry point for the Web3AI application.
* It demonstrates the integration of AI capabilities with Web3 technologies.
* Now featuring GPT-5.1-Codex-Max for enhanced code analysis.
*/

require('dotenv').config();

const selectedModel = process.env.OPENAI_MODEL || 'gpt-5.1-codex-max';

console.log('🚀 Welcome to Web3AI!');
console.log('==========================================');
console.log('A toolkit for AI-powered Web3 development');
console.log(`Powered by ${selectedModel}`);
console.log('==========================================\n');

// Check if OpenAI API key is configured
Expand All @@ -18,7 +22,8 @@ if (!process.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY === 'your_openai_a
console.log('📝 Please create a .env file based on .env.example');
console.log(' and add your OpenAI API key.\n');
} else {
console.log('✅ OpenAI API key configured\n');
console.log('✅ OpenAI API key configured');
console.log(`📊 Using model: ${selectedModel}\n`);
}

// Import and run OpenAI demo if API key is set
Expand Down