- Rewrite prompt builder with comprehensive rules for seamless text completion - Implement Markdown parsing for ghost text with proper mark handling - Update LLM parameters (temperature 0.7, repeat_penalty, think mode) - Add CSS styles for formatted ghost text elements - Add planning documentation for Copilot prompt system analysis
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import StreamingResponse, JSONResponse
|
|
from pydantic import BaseModel
|
|
import json
|
|
|
|
from prompt import build_prompt
|
|
from llm import call_ollama
|
|
|
|
app = FastAPI()
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
class CompletionRequest(BaseModel):
|
|
prefix: str
|
|
suffix: str
|
|
languageId: str = 'markdown'
|
|
|
|
@app.post("/v1/completions")
|
|
async def create_completion(request: CompletionRequest):
|
|
try:
|
|
prompt = build_prompt(request.prefix, request.suffix)
|
|
result = await call_ollama(prompt)
|
|
|
|
content = result["content"]
|
|
|
|
async def generate():
|
|
if content:
|
|
yield f"data: {json.dumps({'content': content})}\n\n"
|
|
yield f"data: {json.dumps({'done': True})}\n\n"
|
|
|
|
return StreamingResponse(generate(), media_type="text/event-stream")
|
|
|
|
except Exception as e:
|
|
import traceback
|
|
traceback.print_exc()
|
|
return JSONResponse(content={"error": str(e)}, status_code=500)
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|