AumCoreAI commited on
Commit
5ac75d9
·
verified ·
1 Parent(s): a897680

Upload ai_core.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. ai_core.py +43 -0
ai_core.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ai_core.py - AI Logic & Code Generation
2
+ import os
3
+ from groq import Groq
4
+ from langdetect import detect
5
+ from reasoning_core import ReasoningEngine
6
+ from chain_of_thought_manager import ChainOfThought
7
+
8
+ class AICore:
9
+ def __init__(self):
10
+ self.client = Groq(api_key=os.getenv("GROQ_API_KEY"))
11
+ self.reasoning = ReasoningEngine()
12
+ self.chain = ChainOfThought()
13
+
14
+ def detect_language(self, text):
15
+ try:
16
+ lang = detect(text)
17
+ return "hi" if lang == "hi" else "en"
18
+ except:
19
+ return "en"
20
+
21
+ def generate_code_response(self, user_input):
22
+ # Language detection
23
+ lang = self.detect_language(user_input)
24
+
25
+ # Chain-of-Thought reasoning
26
+ thought_process = self.chain.generate_thoughts(user_input)
27
+
28
+ # Generate code using reasoning
29
+ code = self.reasoning.generate_complex_code(user_input, thought_process)
30
+
31
+ # Format response based on language
32
+ if lang == "hi":
33
+ return f"""कोड तैयार है:
34
+
35
+ {code}
36
+
37
+ यह कोड 350+ लाइन का है और Colab में रन करेगा।"""
38
+ else:
39
+ return f"""Code Generated:
40
+
41
+ {code}
42
+
43
+ This is 350+ lines of production-ready Python code."""