-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathutils.py
More file actions
56 lines (41 loc) · 1.28 KB
/
utils.py
File metadata and controls
56 lines (41 loc) · 1.28 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# ruff: noqa: S101
from collections.abc import AsyncGenerator, Generator
from contextlib import asynccontextmanager, contextmanager
from functools import lru_cache
from typing import cast
from langchain.chat_models import BaseChatModel, init_chat_model
def load_llm() -> BaseChatModel:
model = cast(
"BaseChatModel",
init_chat_model(
model="gpt-oss:20b",
model_provider="ollama",
base_url="http://127.0.0.1:11434",
temperature=0.2,
configurable_fields="any",
),
)
assert hasattr(model, "bind_tools")
assert hasattr(model, "invoke")
assert hasattr(model, "with_config")
return model
class Connection:
def use(self) -> None:
print("Ok, estou usando a connection...")
def open_connection(self) -> None:
print("Connection Opened")
def close_connection(self) -> None:
print("Connection Closed")
@lru_cache
def get_connection() -> Connection:
return Connection()
@contextmanager
def sync_lifespan() -> Generator[Connection]:
print("Sync Abri")
yield get_connection()
print("Sync Fechei")
@asynccontextmanager
async def async_lifespan() -> AsyncGenerator[Connection]:
print("Async Abri")
yield get_connection()
print("Async Fechei")