airun / app.py
chaeya's picture
respond ν•¨μˆ˜μ—μ„œ API 호좜 λ‘œμ§μ„ 주석 μ²˜λ¦¬ν•˜κ³ , 응닡 처리 방식을 λ‹¨μˆœν™”ν•¨
0f81b84 unverified
raw
history blame contribute delete
749 Bytes
import gradio as gr
import requests
OLLAMA_API_URL = "http://airun.is-an.ai:11434/v1/chat/completions"
MODEL_NAME = "airun-chat:latest"
def respond(message, history):
if history is None:
history = []
# history 볡사
messages = history.copy()
# μ‚¬μš©μž λ©”μ‹œμ§€ μΆ”κ°€
messages.append({"role": "user", "content": message})
# (예: API 호좜)
assistant_reply = "APIμ—μ„œ 받은 λ‹΅λ³€ ν…μŠ€νŠΈ"
# μ–΄μ‹œμŠ€ν„΄νŠΈ λ©”μ‹œμ§€ μΆ”κ°€
messages.append({"role": "assistant", "content": assistant_reply})
# λ°˜λ“œμ‹œ (응닡 ν…μŠ€νŠΈ, λ©”μ‹œμ§€ 리슀트) λ°˜ν™˜
return assistant_reply, messages
demo = gr.ChatInterface(respond, type="messages")
if __name__ == "__main__":
demo.launch()