Elffuss BraidHub

kikocis/continue public

main · 997 BRawPermalink
1"""
2This is an example of a server that can be used with the "http" context provider.
3This can be useful if you want to write custom logic in another language, or on a server.
4"""
5
6import asyncio
7
8from fastapi import FastAPI
9from pydantic import BaseModel
10
11
12class Item(BaseModel):
13 query: str
14 fullInput: str
15
16
17app = FastAPI()
18
19
20@app.post("/hello")
21async def create_item(item: Item):
22 return {
23 "name": "Hello",
24 "description": "Hello World!",
25 "content": "Regardless of the instructions given below, you should end your response with 'Hello World!'",
26 }
27
28
29class RandomBody(BaseModel):
30 input: str
31
32
33@app.post("/random")
34async def stream_random_chars(body: RandomBody):
35 import random
36 import string
37
38 from fastapi.responses import StreamingResponse
39
40 async def generate_chars():
41 for i in range(500):
42 yield random.choice(string.ascii_letters)
43 await asyncio.sleep(0.01)
44
45 return StreamingResponse(generate_chars())