File size: 842 Bytes
b8a907e
e5bc3c5
67780da
 
b8a907e
 
 
d2978b4
 
 
 
 
 
 
 
67780da
 
 
 
 
b8a907e
 
e0b6fc3
61d0503
ff2c49e
61d0503
6e99035
454db78
67780da
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import asyncio
from Linlada import Chatbot, ConversationStyle

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
    allow_credentials=True,
)

async def generate(prompt):
    bot = await Chatbot.create()
    result = await bot.ask(prompt=prompt, conversation_style=ConversationStyle.precise)
    return result

@app.get("/")
def read_root():
    return "Hello, I'm Linlada"

@app.get("/test/{hello}")
def hi(hello: str):
    return {"text": hello}
    
@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