??? ???? ????? ?? ???? ?? ??, ??? ?? ? ?????? ??? ???? ???? ???? ?????. ? ??? ???? ?? Pydanticai ??? ??? Google? Gemini-1.5 ??? ???? SQL ?? ?? ? SQL ?? ??? ?? ???? ?? ??? ???? ??? AI ??? ?????? ?? ??? ????? ???? ??? ??? ?????.
???, ??? ??? ? ??? ???? ??? ??? ??? ?????? ??? ?? ???? ?? ??? ?? ?? ???? ??? ?? ??? ??? ?? ? ????.
?? ??
- Pydantic? Pydanticai? ?? ??? ??????.
- AI ?? SQL ?? ?? ???? ???? ??? ?? ??????.
- SQL ??? ?? ?? ??? Gemini-1.5-Flash? ??? ??????.
- ?????? ?? ????? ??? AI ????? ???? ?? ?? ???? ?????.
? ??? Data Science Blogathon ? ??? ??????? .
??
- Pydanticai? ??????
- ???? Pydanticai? ?
- AI ???? ? ??????
- ???? ?? ??? ??????
- AI ???? ? ???? ?? ??? ?? ??
- Pydanticai ??? ??? ??????
- ????? ?????
- ???? ??? ?? ??? ???
- ??
- ?? ?? ??
Pydanticai? ??????
Pydanticai? ??? ?? ? ?? ??? ??? ???? ??? ??? ????????. ??? ?? ??? ?? ??? ?? ??? ???? ??? ??? ??? ?? ??? ?? ? ? ????.
Pydantic? ??? ??? ??? ????.
??? ??
- ?? ?? ? ??? ?? ??? ???? ???? ??? ??? ?????.
- ?? ? ???? ?? ?? ?? Python ??? ?????
???
??? ?? ???? ?? ? ? ????.
- ?? ???? ???? ?????
- ??? ? ??? ?? ??? ??????
???
- Pydantic Object, Dictionary ? JSON ?? ??? ??? ?????.
- ?? ??? API ? JSON ???? ???? ??? ???? ??????.
??
- ?? ?? ??? ??? ??? ???? ?? Rust? ?????.
- ?? ??? REST API? ?? ? ??? ??????? ??????.
???
- Fastapi, Langchain, Llamaindex ?? ?? ???? Python ??????? ?? ?????.
- ?? ???? LLM? Pydantic ??? ??? ? ????.
???? Pydanticai? ?
Pydanticai? Python?? ??? ?? ? ?? ??? ????? ??? ??? ??? ??? ??? ?????. ? ??? ???? ? ?? ?? ?? ?? ?????.
?? ??? ??
Pydantic Import Basemodel?? ??? ??? (Basemodel) : ?? : str ?? : int # ??? ??? user = user (name = "alice", age = 30) ?? (???) print ( "==========================================") # ??? ??? (??? ??????) ????: user = user (name = "alice", age = "Thirty") E? ??? ???? : ?? (e)
?? ??? Pydantic? Basemodel? ???? ??? ??? ???? ??? ????, ???? ??? ?????. ??? ???? ????? ????? ??? ??? (??? ?? ???)? ???? ??? ?? ??? ?????.
??:
?? ?? ??
Pydantic Import Basemodel?? ??? ?? (Basemodel) : ?? : ??? ?? : int # ??? ??? ??? Product = Product (?? = "19.99", ?? = "5") ?? (??) print (type (product.price)) print (type (product.quantity))
???? ??? ????, ????? ??? ?? ?? ??. Pydantic? ??? ?? ( "19.99"? "5")? ??? ?? (float and int)?? ???? ???? ?? ?? ??? ?????.
??:
?? ? ??
Pydantic Import Basemodel?? ??? ?? (Basemodel) : ?? : Str ?? : Str ??? ??? (Basemodel) : ?? : str ?? : ?? # ??? ??? user = user (name = "bob", address = { "street": "123 Main St", "City": "Wonderland"}) ?? (???) # ?? ??? ?????? print (user.address.city)
???? ?? ??? ?? ? ?? ??? ??? ?????. Pydantic? ?? ??? ???? ??? ??? ?? ?????. ??? ???? ??? ??? ????? ' user.address.city' ? ?? ?? ??? ?? ??? ? ? ????.
??:
??? ?? ???? ??? ??
Pydantic Import Basemodel, Field, Field_validator?? ??? ??? (Basemodel) : ?? : str age : int = field (..., gt = 0, description = "??? 0?? ? ??") @field_validator ( "??") def name_must_be_non_empty (cls, value) : value.strip ()? ?? ?? : ValueError Raise ( "??? ???? ? ????") ?? ? # ??? ??? user = user (name = "charlie", age = 25) ?? (???) # ??? ??? ????: user = user (name = "", age = -5) E? ??? ???? : ?? (e)
??? ?? ????? ??? ??? ???? ??? 0?? ?? ??? ??? ???? ? ???? ( ??_must_be_non_empty ???? ?? ??). ??? ???? ??? ????? ????? ???? ?? ??? (? ?? ?? ???? ??)? ??? ??? ?? ??? ???? Pydantic? ??? ?? ??? ?????.
??:
???? Pydantic? ?? ? ? ?????. ??? ??? ?? ??? ???? ? ?????? ????.
AI ???? ? ??????
AI ????? ??? ????? ???? ??? ??? ??? ?? ???? ?? ??? ????? ??? ??? ??????. ? ????? ??? ?? ??? ??? ?? AI?? ?? ??? ????? ????? ???? ??? ??? ???? ????? ??? ????. ?? ????? ??? ???? ??? ???? ???? ??? ? ????. ??? ??? ??? ?? ?? ??? ???? ???? ?? ???? ??? ???? ?? ? ? ????.
???? ?? ??? ??????
???? ?? ???? ?? ?? ?? AI ????? ???? ???? ??, ?? ?? ?? ??? ?????. ??? ???? ?? ???, ???? ?? ???? ???, ??? ? ?? ??? ?????. ??? ?? ?? ?? AI ????? ????? ??? ??? ?? ??? ???? ???? ?? ???? ????? ??? ? ??? ??? ? ????.
AI ???? ? ???? ?? ??? ?? ??
AI ???? ? ???? ?? ??? ??? ??? ??? ????? ?? ??? ?? ??? ???? ?? ??? ??? ??????. ? ??? ???? ???? ???? ??? ????? ? ??? ???? ???????.
???? ???
AI ????? ??, ??? ?? ? ?? ??? ?? ???? ?? ?? ??? ?? ??? ? ??? ??????. ??? ? ???? ???? ?? ??? ???? ???? ??????.
????? ??
AI ?? ????? ??? ??, ??? ? ????? ????? ??? ???? ????? ?? ??? ?? ??? ????.
??
AI ????? ?? ??, ?? ???? ? ?? ???? ???? ?? ?? ? ?? ???? ??????.
??
?? ???? ??? ?? ??? ?? ??, ?? ?? ? ?? ??? ??????? ??? ??? ??? ?? ??? ???????.
?? ???
?? ???? ?? ??? ???? ???? ?? ?? ?? ? ?? ???? ??????.
AI ???? ? ???? ?? ??? ??? ??? ????? ?? ? ??? ?? ?? ?????? ??? ?????. ??? ???? ?? ??? ?? ??? ?? ????? ??, ?? ? ? ???? ???? ?????. AI? ?? ???? ?? AI ????? ?? ?? ??? ? ???? ?? ?? ? ?? ??? ???? ????.
Pydanticai ??? ??? ??????
Pydanticai? Pydantic, Fastapi? ???? ?? ? Python Agent ??? ??? ?? AI? ???? ?? ?? ?? ????? ??? ????? ?? ??, ?? ?? ?? ? ??? ?? ?? (LLMS)?? ??? ??? ?????.
?? ?? Pydanticai? ??? ?????.
- ?? ?? ?? : Pydanticai? OpenAi, Antropic, Gemini, Groq, Mistral ? Ollama? ??? ??? ??? ???? ?? ??? ?? ? ??? ??? ?????? ????.
- ?? ?? : Python? ?? ???? Pydantic? ??? ???? Pydanticai? ???? ?? ??? ???? ??? ?????.
- ??? ?? ??? : ??? TY-SAFE ??? ?? ????? ???? ??? ? ?? ?? ??? ??????.
- ??? ? ?? ?? : Pydantic? ?? ??? ???? ???? ??? ??? ?? ??? ?????.
- ?? ??? ?? : LLM ?? ??????? ??? ? ??????? Pydantic Logfire? ??? ?????.
Pydanticai? ?? ?? ??? ????.
OS ?? ?? pydantic_ai ?? ?????? pydantic_ai.models.gemini import geminimodel?? dotenv import load_dotenv?? load_dotenv () gemini_api_key = os.getenv ( "<google_api_key>") model = geminimodel ( "Gemini-1.5-Flash", api_key = gemini_api_key, )) ???? = ???? ( ?? = ??, system_prompt = "???? ? ???? ??????.", )) result = agent.run_sync ( 'Hello World "? ???? ?????') print (result.data)</google_api_key>
??:
?? ?? ?? ? ?????. Pydanticai Agent Framework? ???? Postgres SQL ?? ??? ?? ? ????.
????? ?????
?? ??? ??? ?????? ??? ???? ?? ????? ??? ??????.
?? ??
??? ??????? ?? ??? ?? ????.
#env? ?????? $ conda create -name sql_gen python = 3.12 # env ??? $ Conda? SQL_GEN? ??????
?? ???? ??? ????
# ??? ???? $ mkdir sql_code_gen # ??? ????? $ cd sql_code_gen
Postgres ??? ??????? ??????
Postgres, PSQL-Command-Tools ? PGADMIN-4? ????? ???? ?? ???? EDBDownload? ???? ?? ??? ? ?? ??????.
?? HEREAND?? DVDRENAL ??????? ?????? Postgres???????.
1 ?? : ???? ?? ?
psql -u postgres # ??? ?????
2 ?? : ??????? ????
# postgres =#?? ?????? DVDRENAL? ????.
3 ?? : ??? ??
?? PSQL ??? ?? ? ?? ???? ??????.
pg_restore -u postgres -d dvdrental d : /sampledb/postgres/dvdrental.tar
4 ?? : PSQL? ?????
?? PSQL? ???? ????????????? ??????.
psql -u postgres # dvdrental? ?????? \ c dvdrental # ???? ?? \ dt
??:
?? ???? ??? ?????. ??? ?? ?? ????? ??? ?????.
?? ??? ??? ?????? SQL_GEN CONDA ENV? ??????.
Conda? sql_gen? ?????? # ?????? ?????? Pip Pydantic Asyncpg asyncio pydantic -ai? ?????? PIP Python-Dotenv Fastapi Google-Generativeai? ?????? PIP ?? DevTools ?? ?? ?? ?? ??
???? ??
?? ?????? 4 ?? ??, ? ??, ??, ??? ? ???? ????.
sql_query_gen/ | |-?? .py |-?? .py | -schema.py | --- ??? .py |-. Env | -__ init__.py |-. Gitignore
???? ??? ?? ??? ???
? ??? ? ?? ???? ?? ????? ???? ??? ?? ?? ?? ??? ??? ???? ??? ??????.
Pydantic ??
Models.py ???? ??? ??? ???? ?????.
Dataclasses?? Dataclass? ????? ?? ?? ???? ??? ?? ???? asyncpg ?? ?? annotated_types import minlen?? Pydantic Import Basemodel, Field?? @dataclass ??? DEPS : Conn : Asyncpg.connection ??? ?? (Basemodel) : sql_query : ??? ?? [str, minlen (1)] ?? : str = field ( "", description = "sql ??? ??, Markdown") ??? invalidRequest (Basemodel) : ERROR_MESSAGE : str
? ????
- DEPS ???? ?????? ?? ???? ?????. @dataclass? __init__ ? __repr__? ?? ?? ???? ???? ?????. Conn? `asyncpg.connection` ?? ???? ?? PostgreSQL ??? ?????. ? ???? ??? ?? ??? ?? ????? ??? ???? ?? ?? ? ? ??????.
- ?? ???? ???? SQL-Query ??? ???? SQL_Query? ?? ?? ?? ??? ( Minlen (1))????? ??? ?? ??? ?? ?? ??? ???????. ?? ? ?? ? ?????? ?? ?????.
- InvalidRequest ???? ??? SQL-Query ?? ??? ???? ?? ?? ?????.
? ??? ?????? ?? ??, ?? ??? ??, ??? ? ?? ?? ? ?? ????? ??? ??????.
??? ??
?? ??? ???? SQL ????? Pydanticai ???? ??? ????.
?? ?? ????? ? ??
OS ?? ?? ?? ?? ???? dotenv import load_dotenv?? asyncpg ?? ?? typing_extensions import findealias?? pydantic_ai import Agent, ModelEtry, RunContext?? pydantic_ai.models.gemini import geminimodel?? ????? db_schema? ????? ???? DEP, ??, InvalIdRequest? ?????
????? ???? ???? .env ??? ???? Gemini API ?? ??? ?????.
# .env gemini_api_key = "asgfhkdhjy457gthjhajbsd"
?? ?? service.py ???? :
load_dotenv () gemini_api_key = os.getenv ( "google_api_key")
`?? Google API ???????. Env` ??.
??? ???? ??
?? : findealias = Union [??, InvalidRequest] model = geminimodel ( "Gemini-1.5-Flash", api_key = gemini_api_key, )) ???? = ???? ( ??, result_type = ??, # ?? : ?? deps_type = deps, ))
- ?? ?? ?? InvalidRequest? ? ??? ?? ??? ?????.
- API ?? Gemini 1.5 ??? ??? ??????
- ??? ?? ? ??? ???? Pydanticai ???? ??
??? ???? ??
?? SQL ?? ??? ?? ??? ????? ?????.
@agent.system_prompt Async def system_prompt () -> str : ?? f "" "\ ?? Postgresql ??? ???? ??? ? ??? ??? ??? ????. ???? ??? ?? SQL ??? ??????. ?????? ??? : {db_schema} ? ?? : ???? $ 4.00?? ? ???? 'PG'??? ?? ?? ??? ?????. ?? : ??, rental_rate? ?????? ???? ??? rental_rate> 4.00 ? ?? = 'pg'; ? ?? : ?? ? ??? ??? ????? ?? : ??, ??? ?????? ???? ??? ?? = (???? ?? (??)? ??); ? ?? : ? ?????? ??? ?? ?? ??? ?????. ?? : C.Name, avg (f.rental_duration)? ?? _rental_duration?? ?????? ?????? c c.category_id = fc.category_id?? film_category fc? ?????? fc.film_id = f.film_id?? ?? F? ?????? C.Name? ?? ?? ?? _rental_duration desc? ??; "" "
??? AI ??? ?? ????? ???? ??? ??? ?????? ?? ??? ?????. ?? ??? ?????? ??? ??? ???? ??? ???? ???? ? ?? ??? ?? ? ? ????.
?? ??
AI ????? ????? ???? ?? ???? ??? ???? ??? ?????.
@agent.result_validator Async def validate_result (ctx : runcontext [deps], ?? : ??) -> ?? : Isinstance (??, InvalidRequest) : ?? ?? # Gemini? ?? SQL? Extraneos ???? ????? result.sql_query = result.sql_query.replace ( "\\", "") ??? ?? ?? SQL_QUERY.UPPER (). StartSwith ( "Select") : ModelEtry Raven ( "?? ??? ??????") ????: ctx.deps.conn.execute? ????? (f "expler {result.sql_query}") asyncpg.exceptions.postgreserror? ???? E : e?? modelretry (f "???? ?? sql : {e}")? ????? ? ??: ?? ??
??? ?? ? SQL ??? ???? ?????.
?? ??? ?? ?? :
- ??? invalidrequeste ? ?? ?? ???? ?? ? ???? ??????.
- ??? ?? ????? ??????
- PostgreSQL? ???? SQL ??? ?????
- ??? ??? ?? ModelEtry? ?????
?????? ???
?????? ???? ???? Postgres ?? ?? ?? ? PGADMIN4? ?? ?. ' DVDRental' ??????? ???? ??? ??? ??? ?? ? ?? 'ERD? ????' ERD '? ??????.
??? ERD ?????? ?? ? ??? ?? ERD?? SQL? ????? (???? ?? ?? ? ?? ??).
???? schema.py ??? ??????.
# schema.py db_schema = "" " ????; ???? ?? ?? ???? ???? ( actor_id Serial NOT NULL, First_Name ?? Varying (45) PG_CATALOG? ?????. "???"NOT NULL, last_name ?? Varying (45) PG_CATALOG? ?????. "???"NOT NULL, ?????? last_update timestamp not null default now (), ?? ?? actor_pkey 1 ? ? (actor_id) ); . . . . . . "" "
?? ?? ??? ???? ?? ??? ???? ???? ????? ??????.
?? ??? ?? ??? ?????? ?? ??? ???? ??? ? ?????.
?? ??
?? ?? ?? ? ???? ??? ?????.
Asyncio ?? ?? OS ?? ?? SYS ?? ?? ?? ?? ???? dotenv import load_dotenv?? asyncpg ?? ?? DevTools ?? ?? ????? typing_extensions import findealias?? pydantic_ai ?? ?????? pydantic_ai.models.gemini import geminimodel?? ???? DEP, ??, InvalIdRequest? ????? load_dotenv () gemini_api_key = os.getenv ( "google_api_key") ?? : findealias = Union [??, InvalidRequest] model = geminimodel ( "Gemini-1.5-Flash", api_key = gemini_api_key, )) ???? = ???? ( ??, result_type = ??, # ?? : ?? deps_type = deps, )) Async def main () : LEN (sys.argv) == 1 : 1 : ???? = "?? ??? ??????" ? ??: ???? = sys.argv [1] # ?????? ?? conn = aisyncpg.connect ( user = "postgres", password = "avizyt", host = "localhost", ?? = 5432, ?????? = "dvdrental", )) ????: deps = deps (Conn) result = await agent.run (????, deps = deps) ?? = ??? (result.data) print ( "========== ?? ========") print (debug (result.sql_query)) print ( "========== ?? ========") print (debug (result.explanation)) ?????: conn.close ()? ?????. __name__ == "__main__"? ?? : asyncio.run (main ())
??? ?? ??? ?? ??? ???? ????? ??? ?? ? ??? ??????. ARG? ???? ??? ?? ????? ??????.
?? ?? Postgres Connection ?? ??? ???? DVDRental ?????? ???? ?????.
Try Block?? ?????? ??? ???? DEPS ????? ???? ????? AI ????? ???? ??? ?? ( PIP ?? DevTools )? ???? ??? ?????. ?? ?? ?? ? SQL ?? ? ?? ??? ???? ??? ? ??? ?????. ? ? ??? ?????? ??? ?????.
?? ??? ?? ?? ??? ??????.
# ????? Python Main.py "? ??? ?? ? ?? ? ??"
??:
PGADMIN4?? SQL ??? ??? ? ? :
??! ??? ??? ??? ?????. ?? ?? ? ?? ??? ????? ??? ?????.
??
? ????? ?????? ?? ????? ????? ??? ? ??? ??? ??? ?????. AI? ?? ??? ????? ????? ??? ?????? SQL ??? ?? ??? ??? ?? ??? ?? ???? ????? ???? ???? ???? ??? ??????.
? ??? ??? AI? ?? ?????? ??? ??????? ?? ? ???? ?? ?? ??? ??? ??? ??? ??? ?????.
???? Repo -? ????? ?? ? ?? ??? ???? ?????.
?? ??? ??
- Pydanticai? ????? ???? ?? ?? ??? ???????.
- Gemini-1.5-Flash? ?? ??? ?? ?? ??? ??? ?????.
- AI ????? ??????? ?? ???? ??? ???? ??? ?? ? ? ????.
- AI ?? ?? ????? ??? ??? ?????.
?? ?? ??
Q 1. SQL ??? ?? Pydanticai? ??? ??????A. Pydanticai? ?? ?? ?? ? ??? ?? ??? ?? ?? ??, ?? ? ?? ??? ?????.
Q 2. Gemini-1.5-Flash? ????? ??? ??????A. Gemini ??? ?? ?? ?? ??? ???? ??? ?? ??? ??? SQL ??? ?????.
Q 3.? ????? ?? AI ?? ?????? ?? ? ? ?????A. ?????! ? ????? ??? ????? ?? ??, ??? ?? ? ??? ???? ?? ? ? ????.
? ??? ??? ???? ?? Vidhya? ???? ??? ??? ??? ?? ?????.
? ??? Pydanticai? ???? ?? ?? LLM ?? ?? ????? ??????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











LLMSORGANATIONS? ?? ??? ??? LLM? ?? ??? ?? ????? ??? 72%? ?? ??? ?? ? ??? ???? ???, ?? ??? ?? ? ??? ???? ????. ?? ?? 40% a

??? ?????? ?????? ???? ????. AI ?? ?? ??? ??? ???? ???? ?? ???? ?? ??? ??????. ??, ?? ?? ???? ??? ?? ? ????? ? ??? PR? ???? ??? ??? ????

?? : ?? ?? ? Tirias Research?? ???? ?? ? IBM, NVIDIA ? ?? ??? ?? ??????. ?? ?? ?? AI ??? ??? ?? ??? ? ???? ??? ??? ??? ? ???????. ?? ?? a

???? ??? ??? ?? ??? ??? ??? ?? ? ?? ??? ???? ??? ???? ???? ?? ???? ?? ?????. ??? ????? ??? ?? ???? ?? ?? ??? ???? ????.

? ??? AI ??? ??? ?????. ?? ??? Kayak ? Edtech ?? ? Chegg? ?? ????? ?? ???? ????? Google? ?? ???? ??? 60%? ???? ??? ???? ?? ??? ???? ????.

??? ?? ??????. ???? AI ??? ??? ??? ??? ??? AI ???? ???? ???? ?? ???? AI? ?? Forbes ? ??? ????? (?? ?? ??). AGI? ??? ????

?? ?? ??? ?? ?? ?? ??? ???? Cisco? ??? ?? ????? ??? ??? ??? ?? ? ? ???? ??? ?? ?????. (?? : Cisco

LLM (Large Language Model) ?? ????? ????? ? ?? ????? ???? ??? ???? ??? ?? ??? LLM ?? ????? ???? ??? ?? ????? LLM ?? ????? ?? ???? ??? ??? ???????.
