Skip to content

Latest commit

History

24 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

CodeAce

CodeAce is a Python package that helps you analyze and understand your codebase using Large Language Models (LLMs). It provides an intuitive interface to map your codebase and query it using natural language.

Features

  • 🤖 Multiple LLM providers support (Azure OpenAI, OpenAI, Google Gemini, Anthropic Claude)
  • 🔍 Smart code search and analysis
  • 💡 Natural language queries about your code
  • 📝 Automatic code documentation

Installation

pip install codeace

Quick Start

fromdotenvimportload_dotenvfromcodeaceimportCoreAgent, MappingAgent# Load environment variablesload_dotenv()
# Initialize agentssrc_path="path/to/your/code"model_name="azure"# or "openai", "gemini", "anthropic"# Map your codebase (do this once)# Note: Mapping process automatically uses GPT-4o-mini for efficient processingmapping_agent=MappingAgent(model_name=model_name, src_path=src_path)
mapping_agent.run_mapping_process()
# Query your code (uses full model capabilities)core_agent=CoreAgent(model_name=model_name, src_path=src_path)
result=core_agent.run_core_process("Explain how the error handling works in this codebase")
print(result)

Advanced Usage

Mapping Process

The mapping process uses Azure OpenAI's GPT-4o-mini model for optimal performance and cost efficiency. This process:

  • Scans your codebase
  • Analyzes each file
  • Generates descriptions and function lists
  • Creates a searchable index
  • Builds a project summary
# Initialize mapping agentmapping_agent=MappingAgent(model_name="azure", src_path=src_path)
# Run mapping with progress updatesforstatusinmapping_agent.run_mapping_process():
print(status) # Shows progress of file processing# Optional: Force remapping of all filesmapping_agent.run_mapping_process(override=True)
# Optional: Map without generating summarymapping_agent.run_mapping_process(generate_summary=False)

Context Management

CodeAce supports rich context management to improve code analysis:

# Initialize agentcore_agent=CoreAgent(model_name="azure", src_path=src_path)
# Add documentation context from filecore_agent.add_extra_context_by_path("path/to/documentation.md")
# Add custom context directlycore_agent.add_extra_context("Additional context information")
# Context is automatically used to improve promptsimproved_prompt=core_agent.improve_user_prompt(user_query)
# Context is considered during code analysisresult=core_agent.process_code_query(user_query, relevant_files)

Multi-Codebase Analysis

You can analyze dependencies across multiple codebases:

# Initialize agents for different codebasesmain_agent=CoreAgent(model_name="azure", src_path=main_src)
modules_agent=CoreAgent(model_name="azure", src_path=modules_src)
# Analyze dependenciesdependencies_result=modules_agent.process_dependencies_query(query, files)
# Use dependencies context in main analysismain_agent.add_extra_context(dependencies_result)
result=main_agent.process_code_query(query, files)

Environment Setup

  1. Create a .env file in your project root directory
  2. Add the required environment variables based on your chosen LLM provider:

OpenAI

OPENAI_API_KEY=your_api_key_here

Azure OpenAI

AZ_OPENAI_API_KEY=your_azure_api_key_hereAZ_OPENAI_API_BASE=your_azure_endpoint_hereAZ_OPENAI_API_VERSION=your_api_version_hereAZ_OPENAI_LLM_4_O=your_deployment_name_here

Google (Gemini)

GOOGLE_API_KEY=your_google_api_key_here

Anthropic

ANTHROPIC_API_KEY=your_anthropic_api_key_here

Supported LLM Providers

Choose the appropriate model_name when initializing agents:

  • "azure": Azure OpenAI (GPT-4o)
  • "openai": OpenAI API (GPT-4)
  • "gemini": Google Gemini Pro
  • "anthropic": Anthropic Claude
  • "ollama": Local Ollama models

Requirements

  • Python 3.8+

  • Required dependencies (installed automatically):

    • langchain
    • pydantic
    • python-dotenv
    • tiktoken
    • (Provider-specific packages based on your choice)
  • Built with LangChain

  • Supports multiple LLM providers

About

Ai agent

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages