Spaces:
Building
Building
Commit
·
55cfbd7
1
Parent(s):
16c76cc
Refactored Quantum-API: removed codelama & ollama, added phi endpoint using Ollama
Browse files- api/endpoints/codelama.py +0 -10
- api/endpoints/ollama.py +0 -9
- api/endpoints/phi.py +22 -0
- api/main.py +8 -5
- app/app.py +8 -20
api/endpoints/codelama.py
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
# api/endpoints/codelama.py
|
2 |
-
|
3 |
-
from fastapi import APIRouter, HTTPException
|
4 |
-
|
5 |
-
router = APIRouter()
|
6 |
-
|
7 |
-
@router.post("/")
|
8 |
-
async def run_codelama(payload: dict):
|
9 |
-
# Placeholder logic
|
10 |
-
return {"status": "success", "received_input": payload}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/endpoints/ollama.py
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
from fastapi import APIRouter, Request
|
2 |
-
|
3 |
-
router = APIRouter()
|
4 |
-
|
5 |
-
@router.post("/")
|
6 |
-
async def ollama_response(request: Request):
|
7 |
-
data = await request.json()
|
8 |
-
question = data.get("question", "No question provided.")
|
9 |
-
return {"response": f"Olama received: {question}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/endpoints/phi.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, HTTPException
|
2 |
+
from pydantic import BaseModel
|
3 |
+
import requests
|
4 |
+
|
5 |
+
router = APIRouter()
|
6 |
+
|
7 |
+
class QueryRequest(BaseModel):
|
8 |
+
query: str
|
9 |
+
|
10 |
+
@router.post("/")
|
11 |
+
async def phi_response(data: QueryRequest):
|
12 |
+
try:
|
13 |
+
# Call the Ollama local API to generate a response using the phi model
|
14 |
+
response = requests.post(
|
15 |
+
"http://localhost:11434/api/generate",
|
16 |
+
json={"model": "phi:latest", "prompt": data.query, "stream": False}
|
17 |
+
)
|
18 |
+
response.raise_for_status()
|
19 |
+
result = response.json()
|
20 |
+
return {"response": result.get("response", "")}
|
21 |
+
except Exception as e:
|
22 |
+
raise HTTPException(status_code=500, detail=f"Phi error: {str(e)}")
|
api/main.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
-
from api.endpoints import
|
3 |
|
4 |
-
app = FastAPI(
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
app.include_router(
|
8 |
-
app.include_router(ollama.router, prefix="/ollama-response")
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from api.endpoints import phi
|
3 |
|
4 |
+
app = FastAPI(
|
5 |
+
title="Quantum-API",
|
6 |
+
description="Quantum API powered by the Ollama φ (phi) model",
|
7 |
+
version="1.0.0"
|
8 |
+
)
|
9 |
|
10 |
+
# Mount the phi endpoint at /phi-response/
|
11 |
+
app.include_router(phi.router, prefix="/phi-response", tags=["Phi"])
|
|
app/app.py
CHANGED
@@ -1,33 +1,21 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
-
# URL
|
5 |
-
|
6 |
-
API_URL_CODELAMA = "http://localhost:7860/codelama/run"
|
7 |
|
8 |
def main():
|
9 |
-
st.title("Quantum-API Chat Interface with
|
10 |
-
|
11 |
user_input = st.text_input("Ask a question:")
|
12 |
|
13 |
if user_input:
|
14 |
-
if st.button("Chat with
|
15 |
-
#
|
16 |
-
response = requests.post(
|
17 |
if response.status_code == 200:
|
18 |
-
|
19 |
-
st.write(f"Olama says: {response.json()['response']}")
|
20 |
else:
|
21 |
-
st.error(f"Error contacting
|
22 |
|
23 |
-
if st.button("Run Code with CodeLlama"):
|
24 |
-
# Make a GET request to the FastAPI server for CodeLlama
|
25 |
-
response = requests.get(API_URL_CODELAMA)
|
26 |
-
if response.status_code == 200:
|
27 |
-
# Display the response from CodeLlama
|
28 |
-
st.write(f"CodeLlama result: {response.json()['result']}")
|
29 |
-
else:
|
30 |
-
st.error(f"Error contacting CodeLlama API: {response.status_code}")
|
31 |
-
|
32 |
if __name__ == "__main__":
|
33 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
+
# Set the correct URL for the φ endpoint; note that the full path is /phi-response/
|
5 |
+
API_URL_PHI = "http://localhost:7860/phi-response/"
|
|
|
6 |
|
7 |
def main():
|
8 |
+
st.title("Quantum-API Chat Interface with φ")
|
|
|
9 |
user_input = st.text_input("Ask a question:")
|
10 |
|
11 |
if user_input:
|
12 |
+
if st.button("Chat with φ"):
|
13 |
+
# Send a POST request with the prompt
|
14 |
+
response = requests.post(API_URL_PHI, json={"query": user_input})
|
15 |
if response.status_code == 200:
|
16 |
+
st.write(f"φ says: {response.json()['response']}")
|
|
|
17 |
else:
|
18 |
+
st.error(f"Error contacting φ API: {response.status_code} - {response.text}")
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
if __name__ == "__main__":
|
21 |
main()
|