ReadmeandLicenseGithub / azure_ai.py
PraneshJs's picture
Update azure_ai.py
18977b5 verified
Raw
History Blame Contribute Delete
3.92 kB
import os
from dotenv import load_dotenv
from openai import AzureOpenAI
load_dotenv()
client = AzureOpenAI(
api_version="2025-01-01-preview",
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT").strip(),
api_key=os.getenv("AZURE_OPENAI_KEY").strip()
)
def enhance_with_ai(repo_info):
file_summaries = "\n".join([
f"### {name}\n```{content[:500]}```"
for name, content in list(repo_info['files'].items())[:10]
])
system_prompt = """You are a senior open-source developer and technical writer who has authored
documentation for projects with 50,000+ GitHub stars (e.g., FastAPI, LangChain, Streamlit).
Your README output must:
- Feel like a polished, production-grade open-source project
- Use Mermaid diagrams: sequenceDiagram for API/data flow, flowchart LR for architecture.
- In Mermaid Diagrams, Dont use any Use only text dont use any symbol like .,*£_-+()/ and HTML tags in Mermaid and Follow correct Mermaid Syntax
- Mermaid diagrams should change according to project working refer the sample one present in user input
- Include shields.io badges, tables, and collapsible sections where appropriate
- Be scannable: a developer should understand the project in under 60 seconds
- Never truncate — every section must be fully written
- Use emojis only in section headers, not inline text"""
user_prompt = f"""
Generate a world-class GitHub README.md for this project.
PROJECT CONTEXT
---------------
Name : {repo_info['name']}
Description : {repo_info['description']}
Topics : {', '.join(repo_info['topics'])}
User : {repo_info['owner']['login']}
FILES (sampled for context):
{file_summaries}
---------------
Follow this EXACT structure and do not skip any section:
1. Hero Section
- H1 title with a one-line tagline below it
- A short 2-line summary of what the project does
2. Table of Contents
- Linked TOC to every section
3. Introduction
- The problem this project solves (2-3 sentences)
- Who benefits from it
- A "Why {repo_info['name']}?" comparison table vs alternatives:
| Feature | {repo_info['name']} | Alternative A | Alternative B |
4. Features
- 6-8 bullet points, each starting with a relevant emoji
- Group under: Core Features, Developer Experience, Deployment
5. Architecture
- A Mermaid flowchart LR showing system components:
```mermaid
flowchart LR
A[Input Layer] --> B[Processing Layer]
B --> C[Output Layer]
```
- A component breakdown table after the diagram:
| Component | Role | Technology |
6. Workflow
- A Mermaid sequenceDiagram showing the request/response or data flow:
```mermaid
sequenceDiagram
actor User
participant App
participant Backend
User->>App: action
App->>Backend: request
Backend-->>App: response
App-->>User: result
```
- Numbered step-by-step explanation below the diagram
7. Tech Stack
| Layer | Technology | Purpose |
8. Installation
- Prerequisites block
- Quick Start in 3 steps max:
```bash
git clone https://github.com/user/{repo_info['name']}.git
cd {repo_info['name']}
pip install -r requirements.txt
```
- Environment setup:
```bash
cp .env.example .env
# Fill in your values
```
9. Project Structure
```
{repo_info['name']}/
```
10. Usage
- Basic example with code block
- Advanced example with code block
Write the complete README now. Do not summarize, skip, or truncate any section.
"""
response = client.chat.completions.create(
model=os.getenv("AZURE_DEPLOYMENT_NAME").strip(),
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
],
temperature=0.7,
max_tokens=4000
)
return response.choices[0].message.content