PydanticAI? Generative AI? ???? ????? ?????? ??? ?????? ??? ??? Python ????????. ?? ???? ??? ?? ?????? Pydantic? ??? ?? ?? ?????? FastAPI? ????? ?????? ???? AI ?????? ?? ??? ???? ?? ??? ???. PydanticAI? ?? ???, ??? ? ?? Python ???? ??? ??? ??? ???.
?? ??
PydanticAI? ? ?? ?? ??? ???? ?????.
??? ??
????? LLM(?? ?? ??)? ?????? ?? ?? ????????. ????? ??? ??? ??? ????? ???? ??? ???.
- ??? ????: ?? ??? ?? ?? ??? ??? LLM ??
- ?? ??: LLM? ?? ??? ??? ??? ???? ?? ??? ? ?? ??
- ???? ?? ??: LLM? ?? ?? ? ???? ?? ??? ??
- ??? ??: ??? ???? ??, ?? ? ?? ??? ???? ??? ? ?? ??? ?? ???.
- LLM ??: ????? ??? LLM??, ???? ?? ? ?? ??? ? ??? ? ????.
????? ???? ????? ?????? ????? ? ? ??????? ?????? ???? ??????.
??? ????
??? ????? ???? LLM? ???? ?????. ??? ?? ? ????:
- ?? ??? ????: ???? ???? system_prompt ????? ???? ????? ??? ? ?????.
- ?? ??? ????: @agent.system_prompt? ??? ??? ?????. ?? RunContext ??? ?? ???? ?? ??? ??? ???? ? ????.
?? ????? ???? ??? ???? ???? ?? ? ?? ??? ????? ?? ??? ? ????.
from pydantic_ai import Agent, RunContext from datetime import date agent = Agent( 'openai:gpt-4o', deps_type=str, system_prompt="Use the customer's name while replying to them.", ) @agent.system_prompt def add_the_users_name(ctx: RunContext[str]) -> str: return f"The user's name is {ctx.deps}." @agent.system_prompt def add_the_date() -> str: return f'The date is {date.today()}.' result = agent.run_sync('What is the date?', deps='Frank') print(result.data) #> Hello Frank, the date today is 2032-01-02.
?? ??
?? ??? ???? LLM? ?? ??? ?????? ??? ???? ?? ??? ??? ? ?? ??? ??? ? ????. ??? ?? ?? ???? ??? ? ????:
- @agent.tool ?????: RunContext? ?? ????? ????? ????? ?? ??????.
- @agent.tool_plain ?????: ????? ????? ???? ??? ?? ??????.
- Agent ???? tools ??? ??: Tool ???? ?? ?? ?? ????? ???? ?? ??? ? ????? ??? ? ????.
from pydantic_ai import Agent, RunContext from datetime import date agent = Agent( 'openai:gpt-4o', deps_type=str, system_prompt="Use the customer's name while replying to them.", ) @agent.system_prompt def add_the_users_name(ctx: RunContext[str]) -> str: return f"The user's name is {ctx.deps}." @agent.system_prompt def add_the_date() -> str: return f'The date is {date.today()}.' result = agent.run_sync('What is the date?', deps='Frank') print(result.data) #> Hello Frank, the date today is 2032-01-02.
?? ????? ?? ???? ???? ??? JSON ???? ???? ? ?????. ??? ????? ?? ??? ??? ?? ???? ??? ???? ? ?????.
???
???? ??? ?? ???? ?? ????? ??? ????, ?? ? ?? ??? ???? ???? ???? ?????. ???? RunContext ??? ?? ??????. ?? Python ??? ? ? ??? ??? ???? ?? ???? ???? ??? ?????.
import random from pydantic_ai import Agent, RunContext agent = Agent( 'gemini-1.5-flash', deps_type=str, system_prompt=( "You're a dice game, you should roll the die and see if the number " "you get back matches the user's guess. If so, tell them they're a winner. " "Use the player's name in the response." ), ) @agent.tool_plain def roll_die() -> str: """Roll a six-sided die and return the result.""" return str(random.randint(1, 6)) @agent.tool def get_player_name(ctx: RunContext[str]) -> str: """Get the player's name.""" return ctx.deps dice_result = agent.run_sync('My guess is 4', deps='Anne') print(dice_result.data) #> Congratulations Anne, you guessed correctly! You're a winner!
??
??? ???? ???? ??? ?? ????. RunResult(?? ? ??? ??? ??) ?? StreamedRunResult(???? ??? ??)? ???? ?? ??? ? ??? ??? ?? ???? ?????. ??? ?? ?????? ???? ???? ? ??? Pydantic? ???? ?????.
from dataclasses import dataclass import httpx from pydantic_ai import Agent, RunContext @dataclass class MyDeps: api_key: str http_client: httpx.AsyncClient agent = Agent( 'openai:gpt-4o', deps_type=MyDeps, ) @agent.system_prompt async def get_system_prompt(ctx: RunContext[MyDeps]) -> str: response = await ctx.deps.http_client.get( 'https://example.com', headers={'Authorization': f'Bearer {ctx.deps.api_key}'}, ) response.raise_for_status() return f'Prompt: {response.text}' async def main(): async with httpx.AsyncClient() as client: deps = MyDeps('foobar', client) result = await agent.run('Tell me a joke.', deps=deps) print(result.data) #> Did you hear about the toothpaste scandal? They called it Colgate.
@agent.result_validator ?????? ?? ??? ?? ??? ???? ?? ??? ??? IO? ???? ????? ?? ??? ?? ??? ???? ??? ?????.
?? ??
PydanticAI? AI ?????? ??? ?? ??? ??? ?? ? ?? ?? ??? ?????.
- ?? ????: PydanticAI? OpenAI, Anthropic, Gemini, Ollama, Groq ? Mistral? ??? ??? LLM? ?????. ?? ?? ??? ?? ??? ???? ?? ??? ?????? ?????.
- ?? ???: mypy ? pyright? ?? ?? ?? ???? ???? ????? ???????. ??? ? ?? ??? ?? ??? ?????.
- Python ?? ???: ??? Python ?? ??? ???? ??? ???? AI ????? ????? ?? Python ??? ?? ??? ? ????.
- ???? ??: Pydantic? ???? ?? ??? ???? ????? ??? ??? ?????.
- ??? ?? ???: ???? ?? ??? ???? ???? ???? ??? ???? ?? ??? ????? ??? ?? ???? ?????.
- ???? ??: ???? ??? ?? LLM ?? ????? ???? ??? ??? ??? ?? ? ????.
???? ??
???? ??
????? ?? ?? ???? ??? ? ????.
- run_sync(): ?? ???.
- run(): ??? ???.
- run_stream(): ???? ??????.
from pydantic_ai import Agent, RunContext from datetime import date agent = Agent( 'openai:gpt-4o', deps_type=str, system_prompt="Use the customer's name while replying to them.", ) @agent.system_prompt def add_the_users_name(ctx: RunContext[str]) -> str: return f"The user's name is {ctx.deps}." @agent.system_prompt def add_the_date() -> str: return f'The date is {date.today()}.' result = agent.run_sync('What is the date?', deps='Frank') print(result.data) #> Hello Frank, the date today is 2032-01-02.
??
???? ??? ?? ??? ??? ? ??? ??? ?? ?? ?? ?? ??? ???? ?? ?? ???? ??? ?? ????. message_history ??? ???? ?? ??? ???? ???? ??? ??? ? ????.
import random from pydantic_ai import Agent, RunContext agent = Agent( 'gemini-1.5-flash', deps_type=str, system_prompt=( "You're a dice game, you should roll the die and see if the number " "you get back matches the user's guess. If so, tell them they're a winner. " "Use the player's name in the response." ), ) @agent.tool_plain def roll_die() -> str: """Roll a six-sided die and return the result.""" return str(random.randint(1, 6)) @agent.tool def get_player_name(ctx: RunContext[str]) -> str: """Get the player's name.""" return ctx.deps dice_result = agent.run_sync('My guess is 4', deps='Anne') print(dice_result.data) #> Congratulations Anne, you guessed correctly! You're a winner!
??? ??
PydanticAI? ?? ? ?? ?? ???? ?? settings.UsageLimits ??? ?????. Usage_limits ??? ?? ?? ??? ??? ??? ??? ? ????.
from dataclasses import dataclass import httpx from pydantic_ai import Agent, RunContext @dataclass class MyDeps: api_key: str http_client: httpx.AsyncClient agent = Agent( 'openai:gpt-4o', deps_type=MyDeps, ) @agent.system_prompt async def get_system_prompt(ctx: RunContext[MyDeps]) -> str: response = await ctx.deps.http_client.get( 'https://example.com', headers={'Authorization': f'Bearer {ctx.deps.api_key}'}, ) response.raise_for_status() return f'Prompt: {response.text}' async def main(): async with httpx.AsyncClient() as client: deps = MyDeps('foobar', client) result = await agent.run('Tell me a joke.', deps=deps) print(result.data) #> Did you hear about the toothpaste scandal? They called it Colgate.
?? ??
settings.ModelSettings ??? ???? ??, max_tokens ? ?? ??? ?? ????? ?? ?? ??? ?? ??? ? ????. ?? ??? model_settings ??? ?? ?? ??? ? ????.
from pydantic import BaseModel from pydantic_ai import Agent class CityLocation(BaseModel): city: str country: str agent = Agent('gemini-1.5-flash', result_type=CityLocation) result = agent.run_sync('Where were the olympics held in 2012?') print(result.data) #> city='London' country='United Kingdom'
?? ?? ??
?? ??
??? @agent.tool ?????(????? ??? ??? ??), @agent.tool_plain ?????(????? ?? ??? ??)? ????? ???? ???? ?? ??? ?? ??? ? ????.
from pydantic_ai import Agent agent = Agent('openai:gpt-4o') # Synchronous run result_sync = agent.run_sync('What is the capital of Italy?') print(result_sync.data) #> Rome # Asynchronous run async def main(): result = await agent.run('What is the capital of France?') print(result.data) #> Paris async with agent.run_stream('What is the capital of the UK?') as response: print(await response.get_data()) #> London
?? ???
???? ??? ?????? ???? ??? JSON ???? ?????. ??? JSON ????? ??? ??? ? ?? ?? ????? ?? ?? ???? ?? ??? ??????.
from pydantic_ai import Agent agent = Agent('openai:gpt-4o', system_prompt='Be a helpful assistant.') result1 = agent.run_sync('Tell me a joke.') print(result1.data) #> Did you hear about the toothpaste scandal? They called it Colgate. result2 = agent.run_sync('Explain?', message_history=result1.new_messages()) print(result2.data) #> This is an excellent joke invent by Samuel Colvin, it needs no explanation.
?? ??
?? ??? ????? ?? ???? ??? ???? ?? ? ???? ???? ?? ??? ???? ??? ??? ??? ? ????.
from pydantic_ai import Agent from pydantic_ai.settings import UsageLimits from pydantic_ai.exceptions import UsageLimitExceeded agent = Agent('claude-3-5-sonnet-latest') try: result_sync = agent.run_sync( 'What is the capital of Italy? Answer with a paragraph.', usage_limits=UsageLimits(response_tokens_limit=10), ) except UsageLimitExceeded as e: print(e) #> Exceeded the response_tokens_limit of 10 (response_tokens=32)
??? ? ?? ??
???? ????
???? ?? ?? ??? ???? RunResult ? StreamedRunResult ??? all_messages() ? new_messages() ???? ?? ???? ? ????.
from pydantic_ai import Agent agent = Agent('openai:gpt-4o') result_sync = agent.run_sync( 'What is the capital of Italy?', model_settings={'temperature': 0.0}, ) print(result_sync.data) #> Rome
??? ???
???? message_history ????? ???? ?? ???? ???? ??? ??? ? ????. message_history? ???? ?? ?? ??? ? ??? ????? ???? ????.
??? ??
??? ??? ?? ?????? ???? ?? ?????? ????? ?? ??? ???? ??? ?????? ??? ? ????.
??? ? ????
??? ???
PydanticAI? ?? ??????? ?????? ???? ? ?? ?? ???? Pydantic Logfire? ?????. Logfire? ?? ??? ??? ? ????.
- ??? ???: ???????? ?? ?? ???? ??? ????? ?????.
- ?????? ?? ????: SQL ?? ? ???? ??
Logfire? ?? PydanticAI? ????? logfire ?? ??? pip install 'pydantic-ai[logfire]'? ?? ?????. ?? ?? Logfire ????? ???? ??? ???? ???.
?? ? ??
??
PydanticAI? pip? ???? ??? ? ????:
from pydantic_ai import Agent, RunContext from datetime import date agent = Agent( 'openai:gpt-4o', deps_type=str, system_prompt="Use the customer's name while replying to them.", ) @agent.system_prompt def add_the_users_name(ctx: RunContext[str]) -> str: return f"The user's name is {ctx.deps}." @agent.system_prompt def add_the_date() -> str: return f'The date is {date.today()}.' result = agent.run_sync('What is the date?', deps='Frank') print(result.data) #> Hello Frank, the date today is 2032-01-02.
?? ??? ???? ?? ?? ??? ?????. ?? ?? ??? ????.
import random from pydantic_ai import Agent, RunContext agent = Agent( 'gemini-1.5-flash', deps_type=str, system_prompt=( "You're a dice game, you should roll the die and see if the number " "you get back matches the user's guess. If so, tell them they're a winner. " "Use the player's name in the response." ), ) @agent.tool_plain def roll_die() -> str: """Roll a six-sided die and return the result.""" return str(random.randint(1, 6)) @agent.tool def get_player_name(ctx: RunContext[str]) -> str: """Get the player's name.""" return ctx.deps dice_result = agent.run_sync('My guess is 4', deps='Anne') print(dice_result.data) #> Congratulations Anne, you guessed correctly! You're a winner!
????? ??
Logfire? ?? PydanticAI? ????? logfire ?? ??? ?? ?????.
from dataclasses import dataclass import httpx from pydantic_ai import Agent, RunContext @dataclass class MyDeps: api_key: str http_client: httpx.AsyncClient agent = Agent( 'openai:gpt-4o', deps_type=MyDeps, ) @agent.system_prompt async def get_system_prompt(ctx: RunContext[MyDeps]) -> str: response = await ctx.deps.http_client.get( 'https://example.com', headers={'Authorization': f'Bearer {ctx.deps.api_key}'}, ) response.raise_for_status() return f'Prompt: {response.text}' async def main(): async with httpx.AsyncClient() as client: deps = MyDeps('foobar', client) result = await agent.run('Tell me a joke.', deps=deps) print(result.data) #> Did you hear about the toothpaste scandal? They called it Colgate.
?
??? ??? ???? ?????.
from pydantic import BaseModel from pydantic_ai import Agent class CityLocation(BaseModel): city: str country: str agent = Agent('gemini-1.5-flash', result_type=CityLocation) result = agent.run_sync('Where were the olympics held in 2012?') print(result.data) #> city='London' country='United Kingdom'
??? ? ??
?? ???
?? ???? ?????? ??? ???? ????? ?????. PydanticAI? ?? ?? ??? ?????.
- pytest? ??? ???? ?????.
- ?? ?? ?? TestModel ?? FunctionModel? ?????.
- Agent.override? ???? ?????? ?? ??? ??? ?????.
- ????? ?? ??? ?? ???? ??? ????? ????? ALLOW_MODEL_REQUESTS=False? ?????.
from pydantic_ai import Agent agent = Agent('openai:gpt-4o') # Synchronous run result_sync = agent.run_sync('What is the capital of Italy?') print(result_sync.data) #> Rome # Asynchronous run async def main(): result = await agent.run('What is the capital of France?') print(result.data) #> Paris async with agent.run_stream('What is the capital of the UK?') as response: print(await response.get_data()) #> London
??
??? LLM? ??? ???? ? ???? ?? ???????? ????? ?????. ??? LLM? ?? ?? ????? ?? ??? ????? ???? ? ??? ???. ?? ????? ???, ???? ?? ?? ???, LLM? ???? LLM? ????? ?????? ???? ??? ???? ??? ? ????.
?? ?? ??
PydanticAI? ??? ?? ???? ??? ? ????.
- ?? ?: ?? ???? ?? ??? ?? ????? ???? ?? ?? ????????.
- ?? ??????: ?? ? ???? ?? ??????? ??? message_history? ???? ?? ???? ?????.
- ?? ?? ????: ??, ??? ?? ? ???? ??? ???? ??? ?? ?? ????? ?????.
- ????: ?? ??? ???? ???? ??? ??? ???? ????? ???? ??????? ????.
- SQL ??: ?? ??? ???? ??? ??? ??? ?? ??? ?????? SQL ??? ?????.
??
PydanticAI? ?? ???? ???? ??? ?? AI ?????? ??? ?? ???? ??? ?????? ?????. ??? ?? ? ???? ?? Pydantic? ??? ??? ?? ???? ???? ??? ? ?? ?? ??? ??? AI ??????? ???? ? ???? ??? ???. ???? LLM ??? Pydantic Logfire? ?? ???? ??? ??? ?? PydanticAI? ???? ???? ????? ?? ?? ??? AI ?? ????? ????? ??? ? ??? ?????.
? ??? PydanticAI: ????? AI ?????? ??? ?? ?? ???? ?? ?????. ??? ??? 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)

??? ??











Python? Unittest ? Pytest? ??? ? ???? ??, ?? ? ??? ????? ? ?? ?? ???? ??? ??? ?????. 1. ??? ??? ?? ??? ???? ??? ??? ??? ?????. UnitTest? ??? ??? ???? ???? Test \ _? ???? ???? ?????. Pytest? ? ?????. Test \ _?? ???? ?? ? ??????. 2. ??? ?? ?? ? ?? ? ??? ??? ????. UnitTest? Assertequal, AssertTrue ? ?? ??? ???? ?? Pytest? ??? Assert ?? ???? ?? ?? ??? ???? ?????. 3. ?? ??? ?? ? ?? ????? ????? ????.

Python? ?? ?? ??? ?? ? ???? ??????. ?? ??? ?? (? : ?? ?? ??)? ?? ?? ??? ???? ?? ??? ?? ??? ??? ? ????. ?? ??, ? ??? ?? ?? ??? ???? ??? ?? ?? ??? ?? ? ??? ???? ?? ??? ??? ??????. ? ???? ?? ??? ??? ????. 1. ?? ?? ?? ??? ?? ??? ??; 2. ?? ?? ??? ?? ??? ??? ?? ???? ???? ??????. 3. ??? ??? ???? ????? ???. 4. ???? ?? ? ???? ????? ????. ??? ??? ?? ?? ??? ???? ???? ???? my_list = [] ?? my_list = none? ???? ?? ?? ?? ??? ? ??? ??? ???? ??? ????.

Python? ??, ?? ? ?? ??? ??? ??? ?? ?? ??? ? ?? ???? ??????. ??? ?? ?? ??? ?? ?? ??? ??? ?? ?? ?? ???? ???? ? ?? ? ?? ??? ????? ? ?????. 1. [x2forxinRange (10)]? ?? ?? ??? ?? ???? ?? ?? ? ? ????. 2. {x : x2forxinrange (5)}? ?? ?? ???? ? ? ??? ???? ?????. 3. [xforxinnumbersifx%2 == 0]? ?? ??? ???? ??? ????? ????? ????. 4. ??? ??? ?? ?? ?? ??? ?? 3 ? ???? ???? ?? ?? ?? ? ???. ??? ?? ?? ???? ???? ??? ?? ?? ??? ??? ??????. ??? ???? ??? ?? ? ? ????

Python? ???? ??? ????? ?? ?? ? ???? ? ?????. ??? ? ???? ????? ???? ????? ???? ?????. 1. ?? API ? ?? ???? (? : HTTP, REST, GRPC)? ???? Python? Flask ? Fastapi? ?? ??? ??? ?? API? ???? ?? ?? HTTPX? ???? ?? ?? ???? ?????. 2. ??? ??? (Kafka, Rabbitmq, Redis)? ???? ??? ??? ???? Python Services? ?? ?? ???? ?? ? ???? ???? ??? ?? ?? ?, ?? ? ? ?? ??? ?? ? ? ????. 3. ??? ???? ?? C/C? ?? ?? ?? ??? (? : Jython)? ?? ?? ??

pythonisidealfordataanalysisduetonumpyandpandas.1) numpyexcelsatnumericalcomputationsfast, multi-dimensionalArraysandectorizedOferationsLikenp.sqrt ()

?? ????? (DP)? ??? ??? ? ??? ?? ??? ??? ??? ? ??? ??? ?? ??? ???? ??? ????? ??????. ? ?? ?? ??? ????. 1. ??? (??) : ??? ?? ??? ???? ??? ???? ?? ??? ??????. 2. ??? (?) : ?? ???? ???? ????? ?????. ???? ???, ?? ?? ?? ?? ??/?? ?, ??? ??? ?? ?? ?? ??? ??? ????? ?????. ?????? ????? ?? ???? ?? ??? ? ???, ?? ??? ???? ?? ?? ??? ???? ??? ???? ????? ???? ???????.

??? ?? ???? ????? ????? __iter_ ? __next__ ???? ???????. ① __iter__ ???? ??? ? ?? ??? ???? ??? ?? ?? ??? ?????. ② __next__ ???? ? ??? ?? ????, ?? ??? ??? ????, ? ?? ??? ??? stopiteration ??? ??????. status ??? ???? ??????? ?? ??? ??? ?? ?? ??? ???????. pile ?? ?? ???? ?? ??? ?? ? ??? ?? ? ??? ?????? ?????. simple ??? ??? ?? ?? ??? ?? ???? ???? ?? ??? ? ??? ?? ????? ???? ??? ??? ???????.

Python? ?? ???? ?? ???, ?? ?? ????, ?? ???? ?? ? AI/ML ??? ???? ??? ?????. ??, Cpython? ???? ????? ?? ??, ?? ?? ??? ? ?? ? ?? ??? ?? ??? ??????. ??, ??? ????? ?? ?? ? ?? ??? ????? ?? ?? ? ? ??? ?? ?????. ??, Pyscript ? Nuitka? ?? ?? ???? ??? ??? ?? ??? ?????. ?????, AI ? ??? ?? ??? ?? ???? ??? ?? ???????? ???? ?? ? ??? ?????. ??? ??? Python? ??? ??? ????? ???? ?? ??? ???? ??? ?????.
