Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

update logos, favicon and brand names#2193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes from1 commit
Commits
Show all changes
26 commits
Select commitHold shift + click to select a range
966c3f8
update logos, favicon and brand names
GSemikozovJul 13, 2025
befbca5
format code
GSemikozovJul 13, 2025
64045fd
format code
GSemikozovJul 13, 2025
fca3220
change logo color
GSemikozovJul 13, 2025
7af59cd
sm fix
GSemikozovJul 13, 2025
16ee22a
replace old brand name
GSemikozovJul 14, 2025
88118ce
fixes
GSemikozovJul 14, 2025
b5e1155
fixes
GSemikozovJul 14, 2025
4c5132c
fixes
GSemikozovJul 14, 2025
e44f395
fixes
GSemikozovJul 14, 2025
953a8c8
Merge branch 'main' into herman/PYD-2115/migrate-brand-for-all-websit…
GSemikozovJul 14, 2025
b3564e5
fix
GSemikozovJul 14, 2025
75ec47e
fix syntax issues
GSemikozovJul 14, 2025
7ce8dc4
fix syntax issues
GSemikozovJul 14, 2025
afb60f6
fix syntax issues
GSemikozovJul 14, 2025
738640f
restore admonitions
GSemikozovJul 15, 2025
02d101d
fix
GSemikozovJul 15, 2025
2a59de2
fix docs
GSemikozovJul 15, 2025
1508569
fix docs
GSemikozovJul 15, 2025
1f3df5e
Merge branch 'main' into herman/PYD-2115/migrate-brand-for-all-websit…
GSemikozovJul 15, 2025
c8b38b9
fix docs
GSemikozovJul 15, 2025
a4aba97
fix docs
GSemikozovJul 15, 2025
3409ce6
resolve conflicts
GSemikozovJul 17, 2025
7cde5ef
fix
GSemikozovJul 17, 2025
1ee9e6a
fix
GSemikozovJul 17, 2025
9ae91ce
Merge branch 'main' into herman/PYD-2115/migrate-brand-for-all-websit…
GSemikozovJul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
fix syntax issues
  • Loading branch information
@GSemikozov
GSemikozov committedJul 14, 2025
commit7ce8dc4c95ed092af48771263f0860ff61d9bd7c
218 changes: 136 additions & 82 deletionsdocs/graph.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -651,100 +651,98 @@ Instead of running the entire graph in a single process invocation, we run the g
```python {title="ai_q_and_a_graph.py" noqa="I001" py="3.10"}
from __future__ import annotations as _annotations

from dataclasses import dataclass, field

from pydantic import BaseModel
from pydantic_graph import (
BaseNode,
End,
Graph,
GraphRunContext,
)

from pydantic_ai import Agent, format_as_xml
from pydantic_ai.messages import ModelMessage
from dataclasses import dataclass, field
from pydantic import BaseModel
from pydantic_graph import (
BaseNode,
End,
Graph,
GraphRunContext,
)
from pydantic_ai import Agent, format_as_xml
from pydantic_ai.messages import ModelMessage

ask_agent = Agent('openai:gpt-4o', output_type=str, instrument=True)
ask_agent = Agent('openai:gpt-4o', output_type=str, instrument=True)


@dataclass
class QuestionState:
question: str | None = None
ask_agent_messages: list[ModelMessage] = field(default_factory=list)
evaluate_agent_messages: list[ModelMessage] = field(default_factory=list)
@dataclass
class QuestionState:
question: str | None = None
ask_agent_messages: list[ModelMessage] = field(default_factory=list)
evaluate_agent_messages: list[ModelMessage] = field(default_factory=list)


@dataclass
class Ask(BaseNode[QuestionState]):
async def run(self, ctx: GraphRunContext[QuestionState]) -> Answer:
result = await ask_agent.run(
'Ask a simple question with a single correct answer.',
message_history=ctx.state.ask_agent_messages,
)
ctx.state.ask_agent_messages += result.new_messages()
ctx.state.question = result.output
return Answer(result.output)
@dataclass
class Ask(BaseNode[QuestionState]):
async def run(self, ctx: GraphRunContext[QuestionState]) -> Answer:
result = await ask_agent.run(
'Ask a simple question with a single correct answer.',
message_history=ctx.state.ask_agent_messages,
)
ctx.state.ask_agent_messages += result.new_messages()
ctx.state.question = result.output
return Answer(result.output)


@dataclass
class Answer(BaseNode[QuestionState]):
question: str
@dataclass
class Answer(BaseNode[QuestionState]):
question: str

async def run(self, ctx: GraphRunContext[QuestionState]) -> Evaluate:
answer = input(f'{self.question}: ')
return Evaluate(answer)
async def run(self, ctx: GraphRunContext[QuestionState]) -> Evaluate:
answer = input(f'{self.question}: ')
return Evaluate(answer)


class EvaluationResult(BaseModel, use_attribute_docstrings=True):
correct: bool
"""Whether the answer is correct."""
comment: str
"""Comment on the answer, reprimand the user if the answer is wrong."""
class EvaluationResult(BaseModel, use_attribute_docstrings=True):
correct: bool
"""Whether the answer is correct."""
comment: str
"""Comment on the answer, reprimand the user if the answer is wrong."""


evaluate_agent = Agent(
'openai:gpt-4o',
output_type=EvaluationResult,
system_prompt='Given a question and answer, evaluate if the answer is correct.',
)
evaluate_agent = Agent(
'openai:gpt-4o',
output_type=EvaluationResult,
system_prompt='Given a question and answer, evaluate if the answer is correct.',
)


@dataclass
class Evaluate(BaseNode[QuestionState, None, str]):
answer: str
@dataclass
class Evaluate(BaseNode[QuestionState, None, str]):
answer: str

async def run(
self,
ctx: GraphRunContext[QuestionState],
) -> Annotated[End[str], Edge(label='success')] | Reprimand:
assert ctx.state.question is not None
result = await evaluate_agent.run(
format_as_xml({'question': ctx.state.question, 'answer': self.answer}),
message_history=ctx.state.evaluate_agent_messages,
)
ctx.state.evaluate_agent_messages += result.new_messages()
if result.output.correct:
return End(result.output.comment)
else:
return Reprimand(result.output.comment)
async def run(
self,
ctx: GraphRunContext[QuestionState],
) -> Annotated[End[str], Edge(label='success')] | Reprimand:
assert ctx.state.question is not None
result = await evaluate_agent.run(
format_as_xml({'question': ctx.state.question, 'answer': self.answer}),
message_history=ctx.state.evaluate_agent_messages,
)
ctx.state.evaluate_agent_messages += result.new_messages()
if result.output.correct:
return End(result.output.comment)
else:
return Reprimand(result.output.comment)


@dataclass
class Reprimand(BaseNode[QuestionState]):
comment: str
@dataclass
class Reprimand(BaseNode[QuestionState]):
comment: str

async def run(self, ctx: GraphRunContext[QuestionState]) -> Ask:
print(f'Comment: {self.comment}')
ctx.state.question = None
return Ask()
async def run(self, ctx: GraphRunContext[QuestionState]) -> Ask:
print(f'Comment: {self.comment}')
ctx.state.question = None
return Ask()


question_graph = Graph(
nodes=(Ask, Answer, Evaluate, Reprimand), state_type=QuestionState
)
```
question_graph = Graph(
nodes=(Ask, Answer, Evaluate, Reprimand), state_type=QuestionState
)
```

_(This example is complete, it can be run "as is" with Python 3.10+)_
_(This example is complete, it can be run "as is" with Python 3.10+)_

```python {title="ai_q_and_a_run.py" noqa="I001" py="3.10" requires="ai_q_and_a_graph.py"}
import sys
Expand DownExpand Up@@ -903,7 +901,15 @@ from typing import Annotated

from pydantic_graph import BaseNode, End, Graph, GraphRunContext, Edge

...
ask_agent = Agent('openai:gpt-4o', output_type=str, instrument=True)


@dataclass
class QuestionState:
question: str | None = None
ask_agent_messages: list[ModelMessage] = field(default_factory=list)
evaluate_agent_messages: list[ModelMessage] = field(default_factory=list)


@dataclass
class Ask(BaseNode[QuestionState]):
Expand All@@ -912,23 +918,71 @@ class Ask(BaseNode[QuestionState]):
async def run(
self, ctx: GraphRunContext[QuestionState]
) -> Annotated[Answer, Edge(label='Ask the question')]:
...
result = await ask_agent.run(
'Ask a simple question with a single correct answer.',
message_history=ctx.state.ask_agent_messages,
)
ctx.state.ask_agent_messages += result.new_messages()
ctx.state.question = result.output
return Answer(result.output)

...

@dataclass
class Evaluate(BaseNode[QuestionState]):
class Answer(BaseNode[QuestionState]):
question: str

async def run(self, ctx: GraphRunContext[QuestionState]) -> Evaluate:
answer = input(f'{self.question}: ')
return Evaluate(answer)


class EvaluationResult(BaseModel, use_attribute_docstrings=True):
correct: bool
"""Whether the answer is correct."""
comment: str
"""Comment on the answer, reprimand the user if the answer is wrong."""


evaluate_agent = Agent(
'openai:gpt-4o',
output_type=EvaluationResult,
system_prompt='Given a question and answer, evaluate if the answer is correct.',
)


@dataclass
class Evaluate(BaseNode[QuestionState, None, str]):
answer: str

async def run(
self,
ctx: GraphRunContext[QuestionState],
self,
ctx: GraphRunContext[QuestionState],
) -> Annotated[End[str], Edge(label='success')] | Reprimand:
...
assert ctx.state.question is not None
result = await evaluate_agent.run(
format_as_xml({'question': ctx.state.question, 'answer': self.answer}),
message_history=ctx.state.evaluate_agent_messages,
)
ctx.state.evaluate_agent_messages += result.new_messages()
if result.output.correct:
return End(result.output.comment)
else:
return Reprimand(result.output.comment)


@dataclass
class Reprimand(BaseNode[QuestionState]):
comment: str

async def run(self, ctx: GraphRunContext[QuestionState]) -> Ask:
print(f'Comment: {self.comment}')
ctx.state.question = None
return Ask()

...

question_graph.mermaid_save('image.png', highlighted_nodes=[Answer])
question_graph = Graph(
nodes=(Ask, Answer, Evaluate, Reprimand), state_type=QuestionState
)
```

_(This example is not complete and cannot be run directly)_
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp