Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ from pathlib import Path
|
|
13 |
from typing import Annotated, Any, Callable, Literal, TypeVar
|
14 |
|
15 |
import fastapi
|
16 |
-
import logfire
|
17 |
from fastapi import Depends, Request
|
18 |
from fastapi.responses import FileResponse, Response, StreamingResponse
|
19 |
from typing_extensions import LiteralString, ParamSpec, TypedDict
|
@@ -30,7 +30,7 @@ from pydantic_ai.messages import (
|
|
30 |
)
|
31 |
|
32 |
# 'if-token-present' means nothing will be sent (and the example will work) if you don't have logfire configured
|
33 |
-
logfire.configure(send_to_logfire='if-token-present')
|
34 |
|
35 |
agent = Agent('openai:gpt-4o')
|
36 |
THIS_DIR = Path(__file__).parent
|
@@ -43,7 +43,7 @@ async def lifespan(_app: fastapi.FastAPI):
|
|
43 |
|
44 |
|
45 |
app = fastapi.FastAPI(lifespan=lifespan)
|
46 |
-
logfire.instrument_fastapi(app)
|
47 |
|
48 |
|
49 |
@app.get('/')
|
@@ -151,11 +151,11 @@ class Database:
|
|
151 |
async def connect(
|
152 |
cls, file: Path = THIS_DIR / '.chat_app_messages.sqlite'
|
153 |
) -> AsyncIterator[Database]:
|
154 |
-
with logfire.span('connect to DB'):
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
try:
|
160 |
yield slf
|
161 |
finally:
|
@@ -164,7 +164,7 @@ class Database:
|
|
164 |
@staticmethod
|
165 |
def _connect(file: Path) -> sqlite3.Connection:
|
166 |
con = sqlite3.connect(str(file))
|
167 |
-
con = logfire.instrument_sqlite3(con)
|
168 |
cur = con.cursor()
|
169 |
cur.execute(
|
170 |
'CREATE TABLE IF NOT EXISTS messages (id INT PRIMARY KEY, message_list TEXT);'
|
|
|
13 |
from typing import Annotated, Any, Callable, Literal, TypeVar
|
14 |
|
15 |
import fastapi
|
16 |
+
#import logfire
|
17 |
from fastapi import Depends, Request
|
18 |
from fastapi.responses import FileResponse, Response, StreamingResponse
|
19 |
from typing_extensions import LiteralString, ParamSpec, TypedDict
|
|
|
30 |
)
|
31 |
|
32 |
# 'if-token-present' means nothing will be sent (and the example will work) if you don't have logfire configured
|
33 |
+
#logfire.configure(send_to_logfire='if-token-present')
|
34 |
|
35 |
agent = Agent('openai:gpt-4o')
|
36 |
THIS_DIR = Path(__file__).parent
|
|
|
43 |
|
44 |
|
45 |
app = fastapi.FastAPI(lifespan=lifespan)
|
46 |
+
#logfire.instrument_fastapi(app)
|
47 |
|
48 |
|
49 |
@app.get('/')
|
|
|
151 |
async def connect(
|
152 |
cls, file: Path = THIS_DIR / '.chat_app_messages.sqlite'
|
153 |
) -> AsyncIterator[Database]:
|
154 |
+
#with logfire.span('connect to DB'):
|
155 |
+
loop = asyncio.get_event_loop()
|
156 |
+
executor = ThreadPoolExecutor(max_workers=1)
|
157 |
+
con = await loop.run_in_executor(executor, cls._connect, file)
|
158 |
+
slf = cls(con, loop, executor)
|
159 |
try:
|
160 |
yield slf
|
161 |
finally:
|
|
|
164 |
@staticmethod
|
165 |
def _connect(file: Path) -> sqlite3.Connection:
|
166 |
con = sqlite3.connect(str(file))
|
167 |
+
#con = logfire.instrument_sqlite3(con)
|
168 |
cur = con.cursor()
|
169 |
cur.execute(
|
170 |
'CREATE TABLE IF NOT EXISTS messages (id INT PRIMARY KEY, message_list TEXT);'
|