fastapi / main.py
ka1kuk's picture
Update main.py
654794a
raw
history blame
952 Bytes
import Linlada
from fastapi import FastAPI
import asyncio
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware( # add the middleware
CORSMiddleware,
allow_credentials=True, # allow credentials
allow_origins=["*"], # allow all origins
allow_methods=["*"], # allow all methods
allow_headers=["*"], # allow all headers
)
@app.get("/")
def hello():
return "Hello, I'm Artist"
def generate(prompt):
response = Linlada._create_completion(model='gpt-4', messages=[
{"role": "user", "content": prompt}], stream=True)
chat = list(response)
sentence = ''.join(chat)
return sentence
@app.get('/linlada/{prompt}')
def generate_image_route(prompt: str):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
result = loop.run_until_complete(generate(prompt))
loop.close()
return result