๐ป AI Coding AssistantsJune 6, 2026โ
Tests passing
AI Code Completion CLI
A lightweight CLI tool that provides AI-driven code completions for partially written scripts. Developers can pass incomplete code files or snippets, and the tool generates plausible completions based on the context, leveraging pre-trained AI models.
What It Does
- Accepts input from a file containing incomplete code or a code snippet.
- Uses OpenAI's
text-davinci-003model to generate code completions. - Allows customization of the maximum number of tokens for the completion.
Installation
1. Clone the repository:
git clone <repository_url>
cd <repository_folder>2. Install the required dependencies:
pip install -r requirements.txtUsage
To use the tool, run the following command:
python ai_code_completion_cli.py --input <path_to_input_file> --api-key <your_openai_api_key> [--max-tokens <number_of_tokens>]Arguments
--input: Path to the input file containing incomplete code or a code snippet (required).--api-key: Your OpenAI API key (required).--max-tokens: Maximum number of tokens to generate for the completion (default: 150).
Example
python ai_code_completion_cli.py --input example.py --api-key sk-xxxxxxxx --max-tokens 100Source Code
import argparse
import openai
import os
def get_code_completion(api_key, prompt, max_tokens=150):
"""
Get code completion from OpenAI's API.
Args:
api_key (str): OpenAI API key.
prompt (str): The input code snippet or file content.
max_tokens (int): Maximum number of tokens for the completion.
Returns:
str: The completed code.
"""
try:
openai.api_key = api_key
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=max_tokens,
temperature=0.7
)
return response['choices'][0]['text'].strip()
except openai.error.OpenAIError as e:
raise RuntimeError(f"Error communicating with OpenAI API: {e}")
def read_input_file(file_path):
"""
Read the content of the input file.
Args:
file_path (str): Path to the input file.
Returns:
str: Content of the file.
"""
if not os.path.exists(file_path):
raise FileNotFoundError(f"The file '{file_path}' does not exist.")
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
def main():
parser = argparse.ArgumentParser(
description="AI Code Completion CLI: Generate code completions using OpenAI's API."
)
parser.add_argument(
'--input',
type=str,
required=True,
help="Path to the input file containing incomplete code or a code snippet."
)
parser.add_argument(
'--api-key',
type=str,
required=True,
help="Your OpenAI API key."
)
parser.add_argument(
'--max-tokens',
type=int,
default=150,
help="Maximum number of tokens to generate for the completion (default: 150)."
)
args = parser.parse_args()
try:
input_content = read_input_file(args.input)
completion = get_code_completion(args.api_key, input_content, args.max_tokens)
print("\n--- Code Completion ---\n")
print(completion)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- ai_code_completion_cli
- Category
- AI Coding Assistants
- Generated
- June 6, 2026
- Tests
- Passing โ
- Fix Loops
- 3
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-06-06/ai_code_completion_cli cd generated_tools/2026-06-06/ai_code_completion_cli pip install -r requirements.txt 2>/dev/null || true python ai_code_completion_cli.py