shigeru saito commited on
Commit
7f8364e
·
1 Parent(s): d07f287

フォーマットを整形して出力

Browse files
Files changed (2) hide show
  1. app.py +14 -0
  2. flagged/log.csv +82 -0
app.py CHANGED
@@ -10,6 +10,7 @@ from langchain.chat_models import ChatOpenAI
10
  from langchain.agents import initialize_agent, Tool
11
  from langchain.schema import (
12
  AIMessage,
 
13
  HumanMessage,
14
  FunctionMessage
15
  )
@@ -33,6 +34,15 @@ def fetch_folklore(location):
33
  # 指定された地点の伝承を返す。存在しない場合は不明を返す。
34
  return folklore_lookup.get(location, "その地域の伝承は不明です。")
35
 
 
 
 
 
 
 
 
 
 
36
  # LangChainエージェントからレスポンスを取得する関数
37
  def get_response_from_lang_chain_agent(query_text):
38
  # ChatOpenAIを使用して言語モデルを初期化
@@ -49,6 +59,9 @@ def get_response_from_lang_chain_agent(query_text):
49
  agent = initialize_agent(tools, language_model, agent="zero-shot-react-description",
50
  verbose=True, return_intermediate_steps=True)
51
  response = agent({"input": query_text})
 
 
 
52
  return response
53
 
54
  # Function Callingからレスポンスを取得する関数
@@ -113,6 +126,7 @@ def get_response_from_function_calling_agent(query_text):
113
  agent = initialize_agent(tools, language_model, agent=AgentType.OPENAI_FUNCTIONS,
114
  verbose=True, return_intermediate_steps=True)
115
  response = agent({"input": query_text})
 
116
  return response
117
 
118
  # メインの実行部分
 
10
  from langchain.agents import initialize_agent, Tool
11
  from langchain.schema import (
12
  AIMessage,
13
+ AgentAction,
14
  HumanMessage,
15
  FunctionMessage
16
  )
 
34
  # 指定された地点の伝承を返す。存在しない場合は不明を返す。
35
  return folklore_lookup.get(location, "その地域の伝承は不明です。")
36
 
37
+ def serialize_agent_action(obj):
38
+ if isinstance(obj, AgentAction):
39
+ return { "tool": obj.tool, "tool_input": obj.tool_input, "log": obj.log}
40
+ if isinstance(obj, _FunctionsAgentAction):
41
+ return { "tool": obj.tool, "tool_input": obj.tool_input, "log": obj.log, "message_log": obj.message_log}
42
+ if isinstance(obj, AIMessage):
43
+ return { "content": obj.content, "additional_kwargs": obj.additional_kwargs, "example": obj.example}
44
+ raise TypeError(f"Type {type(obj)} not serializable")
45
+
46
  # LangChainエージェントからレスポンスを取得する関数
47
  def get_response_from_lang_chain_agent(query_text):
48
  # ChatOpenAIを使用して言語モデルを初期化
 
59
  agent = initialize_agent(tools, language_model, agent="zero-shot-react-description",
60
  verbose=True, return_intermediate_steps=True)
61
  response = agent({"input": query_text})
62
+ print(type(response))
63
+ response = json.dumps(response, default=serialize_agent_action, indent=2, ensure_ascii=False)
64
+
65
  return response
66
 
67
  # Function Callingからレスポンスを取得する関数
 
126
  agent = initialize_agent(tools, language_model, agent=AgentType.OPENAI_FUNCTIONS,
127
  verbose=True, return_intermediate_steps=True)
128
  response = agent({"input": query_text})
129
+ response = json.dumps(response, default=serialize_agent_action, indent=2, ensure_ascii=False)
130
  return response
131
 
132
  # メインの実行部分
flagged/log.csv ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ query_text,LangChain Agentのレスポンス,Function Callingのレスポンス,Function Calling Agentのレスポンス,flag,username,timestamp
2
+ 箱根の伝承を教えてください。,"'{
3
+ ""input"": ""箱根の伝承を教えてください。"",
4
+ ""output"": ""Hakone Yosegi-Zaiku is a traditional craft in Hakone that has been passed down since the Edo period."",
5
+ ""intermediate_steps"": [
6
+ [
7
+ {
8
+ ""tool"": ""Folklore"",
9
+ ""tool_input"": ""箱根"",
10
+ ""log"": ""I should use the Folklore tool to find information about the folklore of Hakone.\nAction: Folklore\nAction Input: 箱根""
11
+ },
12
+ ""箱根山の自然環境を生かした芸術として、箱根寄木細工は江戸時代から伝わる工芸品です。""
13
+ ]
14
+ ]
15
+ }",AIの回答: 箱根山の自然環境を生かした芸術として、箱根寄木細工は江戸時代から伝わる工芸品です。寄木細工は、異なる種類の木材を組み合わせて美しい模様や絵柄を作り出す技法です。箱根の寄木細工は、その技術を活かして箱根の自然風景や動植物を描いた作品が特徴です。また、箱根は古くから温泉地としても知られており、温泉の伝承や神話も多く存在します。例えば、「箱根駅伝」という箱根から東京までの長距離駅伝競走は、箱根の山々を走り抜ける伝統的なイベントとして知られています。,"'{
16
+ ""input"": ""箱根の伝承を教えてください。"",
17
+ ""output"": ""箱根には、箱根寄木細工という伝統的な工芸品があります。箱根寄木細工は、箱根山の自然環境を生かした芸術として江戸時代から伝わってきました。この工芸品では、様々な種類の木材を組み合わせて美しい模様を作り出します。箱根寄木細工は、木材の組み合わせや彫刻技術によって繊細な模様や景色を表現することが特徴です。箱根の伝統的な文化として、寄木細工は観光客にも人気があります。"",
18
+ ""intermediate_steps"": [
19
+ [
20
+ {
21
+ ""tool"": ""Folklore"",
22
+ ""tool_input"": ""箱根"",
23
+ ""log"": ""\nInvoking: `Folklore` with `箱根`\n\n\n""
24
+ },
25
+ ""箱根山の自然環境を生かした芸術として、箱根寄木細工は江戸時代から伝わる工芸品です。""
26
+ ]
27
+ ]
28
+ }",,,2023-07-14 17:37:42.832325
29
+ 佐渡にはどんな伝承がありますか?,"'{
30
+ ""input"": ""佐渡にはどんな伝承がありますか?"",
31
+ ""output"": ""One of the folklore in Sado is the Fukuhimatsuri festival, which is held once a year and is a traditional festival to ward off evil spirits."",
32
+ ""intermediate_steps"": [
33
+ [
34
+ {
35
+ ""tool"": ""Folklore"",
36
+ ""tool_input"": ""佐渡"",
37
+ ""log"": ""I should use the Folklore tool to find information about the folklore in Sado.\nAction: Folklore\nAction Input: 佐渡""
38
+ },
39
+ ""焚く火祭は年に一度、佐渡島で行われる伝統的なお祭りで、邪気を払う象徴とされています。""
40
+ ]
41
+ ]
42
+ }",AIの回答: 佐渡には焚く火祭という伝統的なお祭りがあります。このお祭りは年に一度、佐渡島で行われ、邪気を払うために焚かれる火を中心に行われます。焚く火祭は佐渡の伝統的な伝承の一つであり、地域の人々にとって重要な行事です。,"'{
43
+ ""input"": ""佐渡にはどんな伝承がありますか?"",
44
+ ""output"": ""佐渡には焚く火祭という伝承があります。焚く火祭は年に一度、佐渡島で行われる伝統的なお祭りです。このお祭りでは、大きな篝火が焚かれ、参加者がその周りを囲んで踊ります。焚く火祭は邪気を払う象徴とされており、地元の人々にとっては大切な行事です。"",
45
+ ""intermediate_steps"": [
46
+ [
47
+ {
48
+ ""tool"": ""Folklore"",
49
+ ""tool_input"": ""佐渡"",
50
+ ""log"": ""\nInvoking: `Folklore` with `佐渡`\n\n\n""
51
+ },
52
+ ""焚く火祭は年に一度、佐渡島で行われる伝統的なお祭りで、邪気を払う象徴とされています。""
53
+ ]
54
+ ]
55
+ }",,,2023-07-14 17:40:26.917775
56
+ 日下部民藝館にはどんな伝統がありますか?,"'{
57
+ ""input"": ""日下部民藝館にはどんな伝統がありますか?"",
58
+ ""output"": ""The 日下部民藝館 showcases traditional crafts from various regions in Japan, highlighting the traditional techniques passed down through generations by local people."",
59
+ ""intermediate_steps"": [
60
+ [
61
+ {
62
+ ""tool"": ""Folklore"",
63
+ ""tool_input"": ""日下部民藝館"",
64
+ ""log"": ""I should use the Folklore tool to find information about the 日下部民藝館.\nAction: Folklore\nAction Input: 日下部民藝館""
65
+ },
66
+ ""日本各地の美しい民芸品が集められ、展示されている美術館です。ここでは地元の人々が代々受け���いできた伝統的な技術が生かされた作品を見ることができます。""
67
+ ]
68
+ ]
69
+ }",AIの回答: 日下部民藝館では、日本各地の美しい民芸品が展示されています。この美術館では、地元の人々が代々受け継いできた伝統的な技術が生かされた作品を鑑賞することができます。具体的な伝統については、詳細な情報が必要です。もしご存知の特定の伝統があれば、お知らせください。,"'{
70
+ ""input"": ""日下部民藝館にはどんな伝統がありますか?"",
71
+ ""output"": ""日下部民藝館では、日本各地の美しい民芸品が集められ、展示されています。ここでは地元の人々が代々受け継いできた伝統的な技術が生かされた作品を見ることができます。詳細な展示内容や特色については、館内での展示やイベント情報をご確認ください。"",
72
+ ""intermediate_steps"": [
73
+ [
74
+ {
75
+ ""tool"": ""Folklore"",
76
+ ""tool_input"": ""日下部民藝館"",
77
+ ""log"": ""\nInvoking: `Folklore` with `日下部民藝館`\n\n\n""
78
+ },
79
+ ""日本各地の美しい民芸品が集められ、展示されている美術館です。ここでは地元の人々が代々受け継いできた伝統的な技術が生かされた作品を見ることができます。""
80
+ ]
81
+ ]
82
+ }",,,2023-07-14 17:58:53.065735