-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery_engine.py
More file actions
30 lines (26 loc) · 1016 Bytes
/
query_engine.py
File metadata and controls
30 lines (26 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
"""AI Code Assistant - Using Ollama for code analysis"""
import sys
import requests
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "qwen2.5-coder"
def query_code(question: str) -> dict:
prompt = f"""You are a code assistant. Answer this question about code:
{question}
Provide a helpful, clear answer."""
try:
response = requests.post(
OLLAMA_URL,
json={"model": MODEL, "prompt": prompt, "stream": False},
timeout=60
)
if response.status_code == 200:
answer = response.json().get("response", "")
return {"answer": answer[:500], "sources": []}
except Exception as e:
return {"answer": f"Ollama error: {e}", "sources": []}
return {"answer": "Ollama not running", "sources": []}
if __name__ == "__main__":
question = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else "How does Python work?"
result = query_code(question)
print(f"💬 {result['answer'][:300]}")