Spaces:
Runtime error
Runtime error
found a way to collect sources from tools
Browse files- mixtral_agent.py +116 -23
mixtral_agent.py
CHANGED
@@ -26,7 +26,7 @@ OLLMA_BASE_URL = os.getenv("OLLMA_BASE_URL")
|
|
26 |
# supports many more optional parameters. Hover on your `ChatOllama(...)`
|
27 |
# class to view the latest available supported parameters
|
28 |
llm = ChatOllama(
|
29 |
-
model="mistral",
|
30 |
base_url= OLLMA_BASE_URL
|
31 |
)
|
32 |
prompt = ChatPromptTemplate.from_template("Tell me a short joke about {topic}")
|
@@ -43,21 +43,86 @@ print(chain.invoke({"topic": "Space travel"}))
|
|
43 |
|
44 |
retriever = ArxivRetriever(load_max_docs=2)
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
|
63 |
|
@@ -106,12 +171,40 @@ agent_executor = AgentExecutor(
|
|
106 |
# }
|
107 |
# )
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
|
111 |
-
{
|
112 |
-
"input": "How to generate videos from images using state of the art macchine learning models; Using the axriv retriever " +
|
113 |
-
"add the urls of the papers used in the final answer using the metadata from the retriever"
|
114 |
-
# f"Please prioritize the newest papers this is the current data {get_current_date()}"
|
115 |
-
}
|
116 |
-
)
|
117 |
|
|
|
26 |
# supports many more optional parameters. Hover on your `ChatOllama(...)`
|
27 |
# class to view the latest available supported parameters
|
28 |
llm = ChatOllama(
|
29 |
+
model="mistral:instruct",
|
30 |
base_url= OLLMA_BASE_URL
|
31 |
)
|
32 |
prompt = ChatPromptTemplate.from_template("Tell me a short joke about {topic}")
|
|
|
43 |
|
44 |
retriever = ArxivRetriever(load_max_docs=2)
|
45 |
|
46 |
+
# Import things that are needed generically
|
47 |
+
from langchain.pydantic_v1 import BaseModel, Field
|
48 |
+
from langchain.tools import BaseTool, StructuredTool, tool
|
49 |
+
|
50 |
+
|
51 |
+
global all_sources
|
52 |
+
|
53 |
+
# @tool
|
54 |
+
# def search(query: str) -> str:
|
55 |
+
# """Look up things online."""
|
56 |
+
# # return "LangChain"
|
57 |
+
# data = retriever.invoke(query)
|
58 |
+
# meta_data = [i.metadata for i in data]
|
59 |
+
# # meta_data += all_sources
|
60 |
+
# # all_sources += meta_data
|
61 |
+
# all_sources += meta_data
|
62 |
+
# # all_sources = []
|
63 |
+
# return meta_data
|
64 |
+
|
65 |
+
from typing import List, Dict
|
66 |
+
from datetime import datetime
|
67 |
+
|
68 |
+
def format_info_list(info_list: List[Dict[str, str]]) -> str:
|
69 |
+
"""
|
70 |
+
Format a list of dictionaries containing information into a single string.
|
71 |
+
|
72 |
+
Args:
|
73 |
+
info_list (List[Dict[str, str]]): A list of dictionaries containing information.
|
74 |
+
|
75 |
+
Returns:
|
76 |
+
str: A formatted string containing the information from the list.
|
77 |
+
"""
|
78 |
+
formatted_strings = []
|
79 |
+
for info_dict in info_list:
|
80 |
+
formatted_string = "|"
|
81 |
+
for key, value in info_dict.items():
|
82 |
+
if isinstance(value, datetime.date):
|
83 |
+
value = value.strftime('%Y-%m-%d')
|
84 |
+
formatted_string += f"'{key}': '{value}', "
|
85 |
+
formatted_string = formatted_string.rstrip(', ') + "|"
|
86 |
+
formatted_strings.append(formatted_string)
|
87 |
+
return '\n'.join(formatted_strings)
|
88 |
+
|
89 |
+
@tool
|
90 |
+
def search(query: str) -> str:
|
91 |
+
"""Look up things online."""
|
92 |
+
# return "LangChain"
|
93 |
+
global all_sources
|
94 |
+
data = retriever.invoke(query)
|
95 |
+
meta_data = [i.metadata for i in data]
|
96 |
+
# meta_data += all_sources
|
97 |
+
# all_sources += meta_data
|
98 |
+
all_sources += meta_data
|
99 |
+
|
100 |
+
# formatted_info = format_info(entry_id, published, title, authors)
|
101 |
+
|
102 |
+
# formatted_info = format_info_list(all_sources)
|
103 |
+
|
104 |
+
return meta_data.__str__()
|
105 |
+
|
106 |
+
# all_sources = []
|
107 |
+
# return meta_data
|
108 |
+
|
109 |
+
tools = [search]
|
110 |
+
|
111 |
+
# tools = [
|
112 |
+
# create_retriever_tool(
|
113 |
+
# retriever,
|
114 |
+
# "search arxiv's database for",
|
115 |
+
# "Use this to recomend the user a paper to read Unless stated please choose the most recent models",
|
116 |
+
# # "Searches and returns excerpts from the 2022 State of the Union.",
|
117 |
+
# ),
|
118 |
+
|
119 |
+
# Tool(
|
120 |
+
# name="SerpAPI",
|
121 |
+
# description="A low-cost Google Search API. Useful for when you need to answer questions about current events. Input should be a search query.",
|
122 |
+
# func=SerpAPIWrapper().run,
|
123 |
+
# )
|
124 |
+
|
125 |
+
# ]
|
126 |
|
127 |
|
128 |
|
|
|
171 |
# }
|
172 |
# )
|
173 |
|
174 |
+
# class AgentSample:
|
175 |
+
|
176 |
+
|
177 |
+
# def __init__(self, agent_executor_object,*args, **kwargs):
|
178 |
+
# self.agent_executor_object = agent_executor_object
|
179 |
+
# self.meta_data = []
|
180 |
+
|
181 |
+
# def sample_invokex
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
+
|
186 |
+
if __name__ == "__main__":
|
187 |
+
|
188 |
+
# global variable for collecting sources
|
189 |
+
all_sources = []
|
190 |
+
|
191 |
+
input = agent_executor.invoke(
|
192 |
+
{
|
193 |
+
"input": "How to generate videos from images using state of the art macchine learning models; Using the axriv retriever " +
|
194 |
+
"add the urls of the papers used in the final answer using the metadata from the retriever"
|
195 |
+
# f"Please prioritize the newest papers this is the current data {get_current_date()}"
|
196 |
+
}
|
197 |
+
)
|
198 |
+
|
199 |
+
x = 0
|
200 |
+
|
201 |
+
input_1 = agent_executor.invoke(
|
202 |
+
{
|
203 |
+
"input": "I am looking for a text to 3d model; Using the axriv retriever " +
|
204 |
+
"add the urls of the papers used in the final answer using the metadata from the retriever"
|
205 |
+
# f"Please prioritize the newest papers this is the current data {get_current_date()}"
|
206 |
+
}
|
207 |
+
)
|
208 |
|
209 |
+
x = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
|