Skip to content

Commit 5170cab

Browse files
feat(add new algos)
0 parents  commit 5170cab

189 files changed

Lines changed: 23468 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
OPENROUTER_API_KEY=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
2+
DEEPSEEK_API_KEY=sk-6edd755aff9d4e238832a9db6fb7241b

.github/workflows/static.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [main] # Cambia se usi un altro branch principale
6+
7+
permissions:
8+
contents: write # Serve per pushare su gh-pages
9+
10+
jobs:
11+
build-and-deploy:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: 📥 Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: ⚙️ Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.10' # Cambia se usi un'altra versione
22+
23+
- name: 📦 Install dependencies
24+
run: |
25+
pip install -r requirements.txt
26+
27+
- name: 🛠️ Build static site
28+
run: |
29+
python web/generate_website.py
30+
31+
- name: 🚀 Deploy to GitHub Pages
32+
uses: peaceiris/actions-gh-pages@v4
33+
with:
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
publish_dir: web/output

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# AlgoWiki

__pycache__/config.cpython-310.pyc

733 Bytes
Binary file not shown.

agents/__init__.py

Whitespace-only changes.
142 Bytes
Binary file not shown.
4.17 KB
Binary file not shown.

agents/content_agent.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from core.api_handler import DeepSeekAPI
2+
from db.db import save_algorithm
3+
import time
4+
5+
6+
class ContentAgent:
7+
def __init__(self):
8+
self.api = DeepSeekAPI()
9+
10+
def get_new_topics(self, existing_topics):
11+
print("Finding new topics")
12+
13+
prompt = f"""
14+
### IMPORTANT INSTRUCTION ###
15+
Generate ONLY comma-separated strings in lowercase.
16+
Do NOT include any comments or explanations—just the comma-separated list.
17+
18+
I have already created web pages for the following algorithms:
19+
{existing_topics}
20+
21+
Now I need to create a new web page for different algorithms. Suggest algorithms that do NOT appear in the list above.
22+
Only include algorithm names that are suitable for a dedicated web page.
23+
"""
24+
25+
try:
26+
print("Sending topic request to OpenRouter...")
27+
response = self.api.generate_content(prompt)
28+
29+
if not response:
30+
print("Retry with simpler prompt.")
31+
simple_prompt = f"Generate comma separated names of algorithms, possibly not in this list: {existing_topics}"
32+
response = self.api.generate_content(simple_prompt)
33+
time.sleep(1)
34+
35+
print(f"Answer received ({len(response)} chars):\n{response[:200]}...")
36+
37+
algorithm_list = [name.strip() for name in response.split(',') if name.strip()]
38+
39+
return algorithm_list
40+
41+
except Exception as e:
42+
print(f"Error while generating: {str(e)}.")
43+
return None
44+
45+
46+
def generate_new_algorithm(self, topic):
47+
print("Generating new algorithm")
48+
prompt = f"""
49+
### IMPORTANT INSTRUCTION ###
50+
Generate a valid JSON ONLY, with no additional text.
51+
Do not include comments or explanations outside the JSON.
52+
The JSON should describe the following algorithm: {topic}.
53+
54+
### JSON STRUCTURE ###
55+
{{
56+
"name": "Formalized Name",
57+
"slug": "name in lowercase and with spaces replaced by _",
58+
"description": "1-2 concise sentences",
59+
"categories": ["list", "of categories", "in lowercase"],
60+
"best_time": "O(...)",
61+
"avg_time": "O(...)",
62+
"worst_time": "O(...)",
63+
"space": "O(...)",
64+
"stability": 0|1,
65+
"inplace": 0|1,
66+
"difficulty": 0-4,
67+
"long_description": "3-5 paragraphs in HTML",
68+
"year": "year of invention",
69+
"author": "name of inventor",
70+
"curiosities": "2-3 interesting facts",
71+
"python": "well-commented python implementation code",
72+
"cpp": "well-commented c++ implementation code",
73+
"c": "well-commented c implementation code"
74+
}}
75+
"""
76+
77+
try:
78+
print("Sending request to OpenRouter...")
79+
response = self.api.generate_content(prompt)
80+
81+
if not response:
82+
print("Retry with simpler prompt.")
83+
simple_prompt = f"Genera un JSON per un algoritmo di {topic} con la struttura richiesta"
84+
response = self.api.generate_content(simple_prompt)
85+
time.sleep(1)
86+
87+
print(f"Answer received ({len(response)} chars):\n{response[:200]}...")
88+
89+
algorithm_data = self.api.parse_algorithm(response)
90+
print(f"Algorithm parsed: {bool(algorithm_data)}.")
91+
92+
if algorithm_data:
93+
# Check required fields
94+
required = ["name", "c", "categories"]
95+
if all(key in algorithm_data for key in required):
96+
save_algorithm(algorithm_data)
97+
return algorithm_data['name']
98+
else:
99+
print(f"Missed data: {[k for k in required if k not in algorithm_data]}.")
100+
return None
101+
102+
except Exception as e:
103+
print(f"Error while generating: {str(e)}.")
104+
return None

agents/design_agent.py

Whitespace-only changes.

0 commit comments

Comments
 (0)