use openai standard response in arch-fc and in gradio client (#62)

* use openai standard response in arch-fc and in gradio client

also fix code bug in usage

* fix int test
This commit is contained in:
Adil Hafeez 2024-09-19 12:19:14 -07:00 committed by GitHub
parent ed6a9139e6
commit 2cd5ec5adf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 89 additions and 133 deletions

View file

@ -2,7 +2,7 @@ from fastapi import FastAPI, Response
from bolt_handler import BoltHandler
from common import ChatMessage
import logging
from ollama import Client
from openai import OpenAI
import os
ollama_endpoint = os.getenv("OLLAMA_ENDPOINT", "localhost")
@ -15,8 +15,12 @@ logger.info(f"using ollama endpoint: {ollama_endpoint}")
app = FastAPI()
handler = BoltHandler()
ollama_client = Client(host=ollama_endpoint)
client = OpenAI(
base_url='http://{}:11434/v1/'.format(ollama_endpoint),
# required but ignored
api_key='ollama',
)
@app.get("/healthz")
async def healthz():
@ -35,6 +39,6 @@ async def chat_completion(req: ChatMessage, res: Response):
)
messages.append({"role": "user", "content": req.messages[-1].content})
resp = ollama_client.chat(messages=messages, model=ollama_model, stream=False)
resp = client.chat.completions.create(messages=messages, model=ollama_model, stream=False)
logger.info(f"response: {resp}")
return resp