Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured Outputs with Pydantic for CRITIC (QA, Math, Code) #183

Merged
merged 41 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6601ccf
Update code.py
emmalin-7 Jun 21, 2024
c832c60
Merge pull request #2 from emmalin-7/emmalin-7-patch-7
emmalin-7 Jun 21, 2024
d2a689f
Update critic.py
emmalin-7 Jun 21, 2024
e7dcb61
Update base.py
emmalin-7 Jun 21, 2024
52f0456
Update critic.py
emmalin-7 Jun 21, 2024
b279798
Update agential/cog/agent/critic.py
emmalin-7 Jun 21, 2024
a73a1a6
Update agential/cog/strategies/critic/code.py
emmalin-7 Jun 21, 2024
031e08d
Update critic.py
emmalin-7 Jun 23, 2024
ba0778d
Update critic.py
emmalin-7 Jun 23, 2024
df4074e
Update base.py
emmalin-7 Jun 24, 2024
a438d04
Update code.py
emmalin-7 Jun 24, 2024
60b3f07
Update math.py
emmalin-7 Jun 24, 2024
7dc1d03
Update code.py
emmalin-7 Jun 24, 2024
b2ff0f9
Update qa.py
emmalin-7 Jun 24, 2024
9f35788
Update math.py
emmalin-7 Jun 24, 2024
793846f
Update base.py
emmalin-7 Jun 27, 2024
8e5cb5a
Update qa.py
emmalin-7 Jun 27, 2024
6031a3b
Update code.py
emmalin-7 Jun 27, 2024
b1cdc78
Update math.py
emmalin-7 Jun 27, 2024
708b44e
Update qa.py
emmalin-7 Jun 27, 2024
17324d5
Merge branch 'main' into main
emmalin-7 Jun 27, 2024
750b46b
Update code.py
emmalin-7 Jun 30, 2024
9ef4051
Update math.py
emmalin-7 Jun 30, 2024
422ec09
Update qa.py
emmalin-7 Jun 30, 2024
964237a
Update critic.py
emmalin-7 Jun 30, 2024
75b9ec1
Merge branch 'main' into main
emmalin-7 Jun 30, 2024
9558357
Update base.py
emmalin-7 Jun 30, 2024
bb86e03
Update code.py
emmalin-7 Jun 30, 2024
6b4a933
Update qa.py
emmalin-7 Jun 30, 2024
b436a48
Update qa.py
emmalin-7 Jun 30, 2024
3789081
Update critic.py
emmalin-7 Jun 30, 2024
8ac7cce
ok
alckasoc Jul 1, 2024
85d2c55
reset
alckasoc Jul 1, 2024
cb83560
added pydantic output class; TODO: linting + unit testing
alckasoc Jul 1, 2024
0703de7
Merge branch 'main' into main
alckasoc Jul 2, 2024
72daf65
testing
emmalin-7 Jul 2, 2024
aacdd58
?
emmalin-7 Jul 2, 2024
c1e78c1
Merge branch 'main' of https://github.com/emmalin-7/llmagential into …
emmalin-7 Jul 2, 2024
7bf371c
Update critic.py
alckasoc Jul 2, 2024
d7ef41f
Delete notebooks/critic.ipynb
alckasoc Jul 2, 2024
1afdb53
Create critic.ipynb
alckasoc Jul 2, 2024
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
23 changes: 22 additions & 1 deletion agential/cog/agent/critic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@
from typing import Any, Dict, List

from langchain_core.language_models.chat_models import BaseChatModel
from pydantic import BaseModel, Field

from agential.cog.agent.base import BaseAgent
from agential.cog.strategies.strategy_factory import CriticStrategyFactory


class CriticOutput(BaseModel):
"""Critic Pydantic output class.

Attributes:
answer (str): The answer generated by the agent.
critique (str): The critique of the answer generated by the agent.
external_tool_info (Dict[str, Any]): The query requested by the agent.
"""

answer: str = Field(..., description="The answer generated by the agent.")
critique: str = Field(..., description="The answer's critique.")
external_tool_info: Dict[str, Any] = Field(
..., description="The external tool outputs."
)


class CriticAgent(BaseAgent):
"""CRITIC Agent.

Expand Down Expand Up @@ -98,7 +115,11 @@ def generate(
)

out.append(
self.strategy.create_output_dict(answer, critique, external_tool_info)
CriticOutput(
**self.strategy.create_output_dict(
answer, critique, external_tool_info
)
)
)

if self.strategy.halting_condition():
Expand Down
4 changes: 2 additions & 2 deletions agential/cog/strategies/critic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def update_answer_based_on_critique(
critique: str,
prompt: str,
additional_keys: Dict[str, str],
external_tool_info: Dict[str, str],
external_tool_info: Dict[str, Any],
**kwargs: Any,
) -> str:
"""Updates the answer based on the provided critique using the given language model and question.
Expand All @@ -85,7 +85,7 @@ def update_answer_based_on_critique(
critique (str): The critique of the original answer.
prompt (str): The instruction template used to prompt the language model for the update.
additional_keys (Dict[str, str]): Additional keys to format the update prompt.
external_tool_info (Dict[str, str]): Information from any external tools used during the critique.
external_tool_info (Dict[str, Any]): Information from any external tools used during the critique.
**kwargs (Any): Additional arguments that might be needed for specific implementations.

Returns:
Expand Down
Loading
Loading