Project Jo

Python 서버 만들기 본문

Developer/LLM

Python 서버 만들기

Project Jo 2025. 4. 15. 15:58
# server.py
from fastapi import FastAPI, Request
from pydantic import BaseModel
import uvicorn

app = FastAPI()

class Message(BaseModel):
    role: str
    content: str

@app.post("/chat")
async def chat(message: Message):
    return {
        "message": {
            "role": "assistant",
            "content": f"Echo: {message.content}"
        }
    }

if __name__ == "__main__":
    uvicorn.run("server:app", host="0.0.0.0", port=8000, reload=True)

 

FastAPI는 Python에서 빠르고 간편하게 REST API 서버를 만들 수 있게 해주는 프레임워크로 해당 API 를 사용해 기본적인 서버를 구축 하고자 한다.

조건
1. LLM 과 같이 POST/JSON 타입으로 통신 한다.
2. 당연히 비동기로 동작해야 한다.

server.py
0.00MB

설명이 포함된 코드는 첨부파일로 올림.

'Developer > LLM' 카테고리의 다른 글

클로드(Claude) MCP  (0) 2025.04.21
챗봇(Chat Bot)  (0) 2025.04.18
페르소나(Persona)  (0) 2025.04.14
FineTuning  (0) 2025.04.14
Role과 Content의 개념  (0) 2025.04.08