alaselababatunde commited on
Commit
170f71d
·
1 Parent(s): b96b289
Files changed (1) hide show
  1. main.py +31 -25
main.py CHANGED
@@ -1,4 +1,3 @@
1
- # main.py
2
  import os
3
  import tempfile
4
  from fastapi import FastAPI, UploadFile, File, Header, HTTPException, Body
@@ -63,14 +62,36 @@ autodoc_template = """You are DevAssist DocBot.
63
  Code: {code}
64
  Documentation:"""
65
 
66
- # Use RunnableSequence instead of LLMChain
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  chat_prompt = PromptTemplate(input_variables=["question"], template=chat_template)
68
  stt_prompt = PromptTemplate(input_variables=["speech"], template=stt_chat_template)
69
  autodoc_prompt = PromptTemplate(input_variables=["code"], template=autodoc_template)
 
 
 
 
70
 
71
  chat_chain = chat_prompt | llm
72
  stt_chain = stt_prompt | llm
73
  autodoc_chain = autodoc_prompt | llm
 
74
 
75
  # --------- REQUEST MODELS ----------
76
  class ChatRequest(BaseModel):
@@ -160,29 +181,14 @@ async def sme_generate(payload: dict = Body(...)):
160
  "language": "en"
161
  }
162
  """
163
- prompt = f"""
164
- You are an SME builder. Generate project code.
165
- Site name: {payload.get('site_name')}
166
- Stack: {payload.get('stack')}
167
- Pages: {payload.get('pages')}
168
- Language: {payload.get('language')}
169
-
170
- Return ONLY JSON:
171
- {{
172
- "files": {{
173
- "index.html": "<html>...</html>",
174
- "style.css": "body {{}}",
175
- "script.js": "..."
176
- }},
177
- "README.md": "# Instructions ..."
178
- }}
179
- """
180
-
181
- # Call your LLM (LangChain Runnable, HF endpoint, etc.)
182
- response = chain.invoke({"question": prompt})
183
-
184
- return { "success": True, "data": response }
185
-
186
 
187
  # ✅ Hugging Face requires port 7860, not 8000
188
  if __name__ == "__main__":
 
 
1
  import os
2
  import tempfile
3
  from fastapi import FastAPI, UploadFile, File, Header, HTTPException, Body
 
62
  Code: {code}
63
  Documentation:"""
64
 
65
+ sme_template = """You are an SME builder. Generate project code.
66
+ Site name: {site_name}
67
+ Stack: {stack}
68
+ Pages: {pages}
69
+ Language: {language}
70
+
71
+ Return ONLY JSON:
72
+ {
73
+ "files": {
74
+ "index.html": "<html>...</html>",
75
+ "style.css": "body {{}}",
76
+ "script.js": "..."
77
+ },
78
+ "README.md": "# Instructions ..."
79
+ }
80
+ """
81
+
82
+ # --------- CHAINS ----------
83
  chat_prompt = PromptTemplate(input_variables=["question"], template=chat_template)
84
  stt_prompt = PromptTemplate(input_variables=["speech"], template=stt_chat_template)
85
  autodoc_prompt = PromptTemplate(input_variables=["code"], template=autodoc_template)
86
+ sme_prompt = PromptTemplate(
87
+ input_variables=["site_name", "stack", "pages", "language"],
88
+ template=sme_template
89
+ )
90
 
91
  chat_chain = chat_prompt | llm
92
  stt_chain = stt_prompt | llm
93
  autodoc_chain = autodoc_prompt | llm
94
+ sme_chain = sme_prompt | llm
95
 
96
  # --------- REQUEST MODELS ----------
97
  class ChatRequest(BaseModel):
 
181
  "language": "en"
182
  }
183
  """
184
+ response = sme_chain.invoke({
185
+ "site_name": payload.get("site_name"),
186
+ "stack": payload.get("stack"),
187
+ "pages": payload.get("pages"),
188
+ "language": payload.get("language"),
189
+ })
190
+
191
+ return {"success": True, "data": response}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
  # ✅ Hugging Face requires port 7860, not 8000
194
  if __name__ == "__main__":