From a8c67a0469d13bf3fcf40318b47b1948bef05e92 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 8 Jan 2026 21:00:12 +0000 Subject: [PATCH 1/2] Initial plan From 3b98d72a08783f7ad87ef93b5b0ba1b9466fc054 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 8 Jan 2026 21:03:56 +0000 Subject: [PATCH 2/2] Add GPT-5.1-Codex-Max support to Web3AI Co-authored-by: lippytm <65956507+lippytm@users.noreply.github.com> --- .env.example | 4 +++ README.md | 54 +++++++++++++++++++++++++++++++++++++---- ai_scripts/sample_ai.py | 28 +++++++++++++-------- backend/openai.js | 19 +++++++++++---- index.js | 7 +++++- 5 files changed, 91 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index ce40fdd..eeae31a 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/README.md b/README.md index 8dc3497..db4cc83 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/ai_scripts/sample_ai.py b/ai_scripts/sample_ai.py index 45ca461..5f078a3 100644 --- a/ai_scripts/sample_ai.py +++ b/ai_scripts/sample_ai.py @@ -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 """ @@ -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(): """ @@ -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: @@ -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 @@ -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 ) @@ -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 @@ -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 ) @@ -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() diff --git a/backend/openai.js b/backend/openai.js index a763476..f989402 100644 --- a/backend/openai.js +++ b/backend/openai.js @@ -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'); @@ -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, }); @@ -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?"; diff --git a/index.js b/index.js index 2a9806c..ae600b4 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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