Update main.py
Browse files
main.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import Linlada
|
2 |
from fastapi import FastAPI
|
|
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
|
5 |
app = FastAPI()
|
@@ -16,7 +17,19 @@ app.add_middleware( # add the middleware
|
|
16 |
def hello():
|
17 |
return "Hello, I'm Artist"
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import Linlada
|
2 |
from fastapi import FastAPI
|
3 |
+
import asyncio
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
|
6 |
app = FastAPI()
|
|
|
17 |
def hello():
|
18 |
return "Hello, I'm Artist"
|
19 |
|
20 |
+
async def generate(prompt):
|
21 |
+
result = index._create_completion(model='gpt-4', messages=[
|
22 |
+
{"role": "user", "content": prompt}], stream=True)
|
23 |
+
chat = []
|
24 |
+
for message in result:
|
25 |
+
chat.append(message)
|
26 |
+
sentence = ''.join(chat)
|
27 |
+
return sentence
|
28 |
+
|
29 |
+
@app.get('/linlada/{prompt}')
|
30 |
+
def generate_image_route(prompt: str):
|
31 |
+
loop = asyncio.new_event_loop()
|
32 |
+
asyncio.set_event_loop(loop)
|
33 |
+
result = loop.run_until_complete(generate(prompt))
|
34 |
+
loop.close()
|
35 |
+
return result
|