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

Fix/response #174

Merged
merged 31 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bdb14f9
requirementsの更新
haruki26 Jan 26, 2025
c61cde1
invokeメソッドの役割を同期レスポンスのみに限定
haruki26 Jan 26, 2025
33a21c4
非同期ジェネレータでストリーミング実装
haruki26 Jan 26, 2025
650a3ba
Agentクラスにstreamメソッドを作成
haruki26 Jan 26, 2025
05b4e26
Agentクラスをインスタンス化時にストリーミングを判断しないように修正
haruki26 Jan 26, 2025
a74b05a
ToolManagerも同様に変更
haruki26 Jan 26, 2025
85a0812
toolのstreamingセットアップの挙動を変更
haruki26 Jan 26, 2025
302f9f3
agentセットアップと同時にツールも行うように修正
haruki26 Jan 26, 2025
0408704
calling_agentでAgentクラスの修正に対応
haruki26 Jan 26, 2025
90cbb2e
agent群を改修
haruki26 Jan 26, 2025
9f57b59
mainを修正
haruki26 Jan 27, 2025
213673a
検索エージェントで変更に対応
haruki26 Jan 27, 2025
f8a496d
同期とストリーミング毎にレスポンスの型を統一
haruki26 Jan 27, 2025
e0f0e54
レスポンスの型をBaseModelで再定義
haruki26 Jan 27, 2025
ba2ce2b
レスポンスの型を適用
haruki26 Jan 27, 2025
108c1ad
calling_agentがstrを返却するように修正
haruki26 Jan 27, 2025
02bf6b1
呼び出しツールでレスポンスを保持
haruki26 Jan 27, 2025
4ce0555
検索エージェントでレスポンスの型を適用
haruki26 Jan 27, 2025
fca62ad
document_idを保持する変数を追加
haruki26 Jan 27, 2025
398d583
ツールから直接idを取得
haruki26 Jan 27, 2025
c59c63a
デバッグ用のコードを修正
haruki26 Jan 27, 2025
2700161
雑談エージェントの作成
haruki26 Jan 27, 2025
dec2281
プロンプトの修正
haruki26 Jan 27, 2025
1d5a30e
雑談エージェントの呼び出しツールを作成
haruki26 Jan 27, 2025
37c3b72
分類エージェントの呼び出しツールに追加
haruki26 Jan 27, 2025
55648f6
エントリーポイントに追加
haruki26 Jan 27, 2025
e776140
chatクラスでAgentクラスのレスポンス変更に対応
haruki26 Jan 27, 2025
2d2d9ce
ツール上でストリーミングを行うメソッドを作成
haruki26 Jan 28, 2025
fba162a
呼び出しツールでストリーミングを可能
haruki26 Jan 28, 2025
13e52db
分類エージェントでツールストリーミングの設定
haruki26 Jan 28, 2025
02043b1
ストリーミングのテストコード
haruki26 Jan 28, 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
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ click==8.1.7 ; python_version >= "3.10" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"
dataclasses-json==0.6.7 ; python_version >= "3.10" and python_version < "4.0"
distro==1.9.0 ; python_version >= "3.10" and python_version < "4.0"
duckduckgo-search==6.3.7 ; python_version >= "3.10" and python_version < "4.0"
duckduckgo-search==7.2.1 ; python_version >= "3.10" and python_version < "4.0"
exceptiongroup==1.2.2 ; python_version >= "3.10" and python_version < "3.11"
frozenlist==1.4.1 ; python_version >= "3.10" and python_version < "4.0"
greenlet==3.1.1 ; python_version < "3.13" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") and python_version >= "3.10"
Expand All @@ -28,17 +28,18 @@ jsonpointer==3.0.0 ; python_version >= "3.10" and python_version < "4.0"
langchain-community==0.3.13 ; python_version >= "3.10" and python_version < "4.0"
langchain-core==0.3.28 ; python_version >= "3.10" and python_version < "4.0"
langchain-openai==0.2.14 ; python_version >= "3.10" and python_version < "4.0"
langchain-text-splitters==0.3.5 ; python_version >= "3.10" and python_version < "4.0"
langchain-text-splitters==0.3.4 ; python_version >= "3.10" and python_version < "4.0"
langchain==0.3.13 ; python_version >= "3.10" and python_version < "4.0"
langsmith==0.1.147 ; python_version >= "3.10" and python_version < "4.0"
lxml==5.3.0 ; python_version >= "3.10" and python_version < "4.0"
marshmallow==3.22.0 ; python_version >= "3.10" and python_version < "4.0"
multidict==6.1.0 ; python_version >= "3.10" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
numpy==1.26.4 ; python_version >= "3.10" and python_version < "4.0"
openai==1.58.1 ; python_version >= "3.10" and python_version < "4.0"
orjson==3.10.7 ; python_version >= "3.10" and python_version < "4.0" and platform_python_implementation != "PyPy"
packaging==24.1 ; python_version >= "3.10" and python_version < "4.0"
primp==0.8.1 ; python_version >= "3.10" and python_version < "4.0"
primp==0.10.0 ; python_version >= "3.10" and python_version < "4.0"
propcache==0.2.0 ; python_version >= "3.10" and python_version < "4.0"
pydantic-core==2.23.4 ; python_version >= "3.10" and python_version < "4.0"
pydantic-settings==2.5.2 ; python_version >= "3.10" and python_version < "4.0"
Expand Down
26 changes: 11 additions & 15 deletions src/sc_system_ai/agents/classify_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import Iterator
from typing import Any, cast
from typing import cast

from langchain_openai import AzureChatOpenAI

Expand Down Expand Up @@ -35,14 +34,10 @@ def __init__(
self,
llm: AzureChatOpenAI = llm,
user_info: User | None = None,
is_streaming: bool = True,
return_length: int = 5
):
super().__init__(
llm=llm,
user_info=user_info if user_info is not None else User(),
is_streaming=is_streaming,
return_length=return_length
)
self.assistant_info = classify_agent_info
super().set_assistant_info(self.assistant_info)
Expand All @@ -53,16 +48,17 @@ def set_tools(self, tools: list) -> None:
for tool in tools:
if isinstance(tool, CallingAgent):
tool.set_user_info(self.user_info)

super().set_tools(tools)

def invoke(self, message: str) -> Iterator[str | AgentResponse | SearchSchoolDataAgentResponse]:
if self.is_streaming:
yield from super().invoke(message)
def invoke(self, message: str) -> AgentResponse | SearchSchoolDataAgentResponse:
# toolの出力を整形
resp = super().invoke(message)
if type(resp["output"]) is str:
return resp
else:
# ツールの出力をそのまま返却
resp = cast(dict[str, Any], next(super().invoke(message)))
yield resp["output"]
return cast(
AgentResponse | SearchSchoolDataAgentResponse, resp["output"]
)


if __name__ == "__main__":
Expand All @@ -79,7 +75,7 @@ def invoke(self, message: str) -> Iterator[str | AgentResponse | SearchSchoolDat
user_info.conversations.add_conversations_list(history)

while True:
classify_agent = ClassifyAgent(user_info=user_info, is_streaming=False)
classify_agent = ClassifyAgent(user_info=user_info)
# classify_agent.display_agent_info()
# print(main_agent.get_agent_prompt())
# classify_agent.display_agent_prompt()
Expand All @@ -89,7 +85,7 @@ def invoke(self, message: str) -> Iterator[str | AgentResponse | SearchSchoolDat
break

# 通常の呼び出し
resp = next(classify_agent.invoke(user))
resp = classify_agent.invoke(user)
print(resp)

# ストリーミング呼び出し
Expand Down
4 changes: 0 additions & 4 deletions src/sc_system_ai/agents/dummy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ def __init__(
self,
llm: AzureChatOpenAI = llm,
user_info: User | None = None,
is_streaming: bool = True,
return_length: int = 5
):
super().__init__(
llm=llm,
user_info=user_info if user_info is not None else User(),
is_streaming=is_streaming,
return_length=return_length
)
self.assistant_info = dummy_agent_info
super().set_assistant_info(self.assistant_info)
Expand Down
8 changes: 2 additions & 6 deletions src/sc_system_ai/agents/main_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ def __init__(
self,
llm: AzureChatOpenAI = llm,
user_info: User | None = None,
is_streaming: bool = True,
return_length: int = 5
):
super().__init__(
llm=llm,
user_info=user_info if user_info is not None else User(),
is_streaming=is_streaming,
return_length=return_length
)
self.assistant_info = main_agent_info
super().set_assistant_info(self.assistant_info)
Expand All @@ -43,9 +39,9 @@ def __init__(
user_info = User(name=user_name, major=user_major)
user_info.conversations.add_conversations_list(history)

main_agent = MainAgent(user_info=user_info, is_streaming=False)
main_agent = MainAgent(user_info=user_info)
main_agent.display_agent_info()
# print(main_agent.get_agent_prompt())
main_agent.display_agent_prompt()
print(next(main_agent.invoke("magic function に3をいれて")))
print(main_agent.invoke("magic function に3をいれて"))

23 changes: 8 additions & 15 deletions src/sc_system_ai/agents/search_school_data_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from collections.abc import Iterator
from typing import cast

from langchain_openai import AzureChatOpenAI

# from sc_system_ai.agents.tools import magic_function
Expand Down Expand Up @@ -29,18 +26,14 @@ def __init__(
self,
llm: AzureChatOpenAI = llm,
user_info: User | None = None,
is_streaming: bool = True,
return_length: int = 5
):
super().__init__(
llm=llm,
user_info=user_info if user_info is not None else User(),
is_streaming=is_streaming,
return_length=return_length
)
self.assistant_info = search_school_data_agent_info

def invoke(self, message: str) -> Iterator[SearchSchoolDataAgentResponse]:
def invoke(self, message: str) -> SearchSchoolDataAgentResponse:
# Agentクラスのストリーミングを改修後にストリーミング実装
self.cancel_streaming()
search = search_school_database_cosmos(message)
Expand All @@ -50,11 +43,11 @@ def invoke(self, message: str) -> Iterator[SearchSchoolDataAgentResponse]:
ids.append(doc.metadata["id"])
super().set_assistant_info(self.assistant_info)

resp = cast(AgentResponse, next(super().invoke(message)))
yield {
**resp,
"document_id": ids
}
resp = super().invoke(message)
return SearchSchoolDataAgentResponse(
document_id=ids,
**resp
)

if __name__ == "__main__":
from sc_system_ai.logging_config import setup_logging
Expand All @@ -68,5 +61,5 @@ def invoke(self, message: str) -> Iterator[SearchSchoolDataAgentResponse]:
]
user_info = User(name=user_name, major=user_major)
user_info.conversations.add_conversations_list(history)
agent = SearchSchoolDataAgent(user_info=user_info, is_streaming=False)
print(next(agent.invoke("京都テックについて教えて")))
agent = SearchSchoolDataAgent(user_info=user_info)
print(agent.invoke("京都テックについて教えて"))
Loading
Loading