mirror of
https://github.com/katanemo/plano.git
synced 2026-04-26 01:06:25 +02:00
Add function calling support using bolt-fc-1b (#35)
This commit is contained in:
parent
fdfad87347
commit
7b5203a2ce
39 changed files with 1763 additions and 416 deletions
40
function_resolver/app/main.py
Normal file
40
function_resolver/app/main.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from fastapi import FastAPI, Response
|
||||
from bolt_handler import BoltHandler
|
||||
from common import ChatMessage
|
||||
import logging
|
||||
from ollama import Client
|
||||
import os
|
||||
|
||||
ollama_endpoint = os.getenv("OLLAMA_ENDPOINT", "localhost")
|
||||
ollama_model = os.getenv("OLLAMA_MODEL", "Bolt-Function-Calling-1B:Q4_K_M")
|
||||
logger = logging.getLogger('uvicorn.error')
|
||||
|
||||
logger.info(f"using model: {ollama_model}")
|
||||
logger.info(f"using ollama endpoint: {ollama_endpoint}")
|
||||
|
||||
app = FastAPI()
|
||||
handler = BoltHandler()
|
||||
|
||||
ollama_client = Client(host=ollama_endpoint)
|
||||
|
||||
|
||||
@app.get("/healthz")
|
||||
async def healthz():
|
||||
return {
|
||||
"status": "ok"
|
||||
}
|
||||
|
||||
|
||||
@app.post("/v1/chat/completions")
|
||||
async def chat_completion(req: ChatMessage, res: Response):
|
||||
logger.info("starting request")
|
||||
tools_encoded = handler._format_system(req.tools)
|
||||
messages = []
|
||||
messages.append(
|
||||
{"role": "system", "content": tools_encoded}
|
||||
)
|
||||
messages.append({"role": "user", "content": req.messages[-1].content})
|
||||
|
||||
resp = ollama_client.chat(messages=messages, model=ollama_model, stream=False)
|
||||
logger.info(f"response: {resp}")
|
||||
return resp
|
||||
Loading…
Add table
Add a link
Reference in a new issue