|
import Linlada |
|
from fastapi import FastAPI |
|
import asyncio |
|
from fastapi.middleware.cors import CORSMiddleware |
|
|
|
app = FastAPI() |
|
|
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_credentials=True, |
|
allow_origins=["*"], |
|
allow_methods=["*"], |
|
allow_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 |
|
|