Spaces:
Sleeping
Sleeping
Asaad Almutareb
commited on
Commit
•
d6922d4
1
Parent(s):
6159920
- migrated HF usage to HuggingFaceEndpoint as HuggingFaceHub was deprecated
Browse files- hf_mixtral_agent.py +10 -23
- innovation_pathfinder_ai/utils.py +16 -3
hf_mixtral_agent.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# HF libraries
|
2 |
-
from langchain_community.llms import
|
3 |
from langchain_core.prompts import ChatPromptTemplate
|
4 |
from langchain import hub
|
5 |
import gradio as gr
|
@@ -21,7 +21,7 @@ from innovation_pathfinder_ai.structured_tools.structured_tools import (
|
|
21 |
from innovation_pathfinder_ai.source_container.container import (
|
22 |
all_sources
|
23 |
)
|
24 |
-
|
25 |
# from langchain_community.chat_message_histories import ChatMessageHistory
|
26 |
# from langchain_core.runnables.history import RunnableWithMessageHistory
|
27 |
|
@@ -36,12 +36,12 @@ LANGCHAIN_API_KEY = os.getenv('LANGCHAIN_API_KEY')
|
|
36 |
LANGCHAIN_PROJECT = os.getenv('LANGCHAIN_PROJECT')
|
37 |
|
38 |
# Load the model from the Hugging Face Hub
|
39 |
-
llm =
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
|
46 |
|
47 |
tools = [
|
@@ -76,7 +76,7 @@ agent_executor = AgentExecutor(
|
|
76 |
agent=agent,
|
77 |
tools=tools,
|
78 |
verbose=True,
|
79 |
-
max_iterations=
|
80 |
#max_execution_time=60, # timout at 60 sec
|
81 |
return_intermediate_steps=True,
|
82 |
handle_parsing_errors=True,
|
@@ -111,20 +111,7 @@ if __name__ == "__main__":
|
|
111 |
print("You upvoted this response: " + data.value)
|
112 |
else:
|
113 |
print("You downvoted this response: " + data.value)
|
114 |
-
|
115 |
-
def collect_urls(data_list):
|
116 |
-
urls = []
|
117 |
-
for item in data_list:
|
118 |
-
# Check if item is a string and contains 'link:'
|
119 |
-
if isinstance(item, str) and 'link:' in item:
|
120 |
-
start = item.find('link:') + len('link: ')
|
121 |
-
end = item.find(',', start)
|
122 |
-
url = item[start:end if end != -1 else None].strip()
|
123 |
-
urls.append(url)
|
124 |
-
# Check if item is a dictionary and has 'Entry ID'
|
125 |
-
elif isinstance(item, dict) and 'Entry ID' in item:
|
126 |
-
urls.append(item['Entry ID'])
|
127 |
-
return urls
|
128 |
|
129 |
css="""
|
130 |
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
|
|
|
1 |
# HF libraries
|
2 |
+
from langchain_community.llms import HuggingFaceEndpoint
|
3 |
from langchain_core.prompts import ChatPromptTemplate
|
4 |
from langchain import hub
|
5 |
import gradio as gr
|
|
|
21 |
from innovation_pathfinder_ai.source_container.container import (
|
22 |
all_sources
|
23 |
)
|
24 |
+
from innovation_pathfinder_ai.utils import collect_urls
|
25 |
# from langchain_community.chat_message_histories import ChatMessageHistory
|
26 |
# from langchain_core.runnables.history import RunnableWithMessageHistory
|
27 |
|
|
|
36 |
LANGCHAIN_PROJECT = os.getenv('LANGCHAIN_PROJECT')
|
37 |
|
38 |
# Load the model from the Hugging Face Hub
|
39 |
+
llm = HuggingFaceEndpoint(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
40 |
+
temperature=0.1,
|
41 |
+
max_new_tokens=1024,
|
42 |
+
repetition_penalty=1.2,
|
43 |
+
return_full_text=False
|
44 |
+
)
|
45 |
|
46 |
|
47 |
tools = [
|
|
|
76 |
agent=agent,
|
77 |
tools=tools,
|
78 |
verbose=True,
|
79 |
+
max_iterations=6, # cap number of iterations
|
80 |
#max_execution_time=60, # timout at 60 sec
|
81 |
return_intermediate_steps=True,
|
82 |
handle_parsing_errors=True,
|
|
|
111 |
print("You upvoted this response: " + data.value)
|
112 |
else:
|
113 |
print("You downvoted this response: " + data.value)
|
114 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
css="""
|
117 |
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
|
innovation_pathfinder_ai/utils.py
CHANGED
@@ -22,8 +22,21 @@ def create_wikipedia_urls_from_text(text):
|
|
22 |
url_title = title.replace(" ", "_")
|
23 |
# Construct the URL and add it to the list
|
24 |
url = f"https://en.wikipedia.org/wiki/{url_title}"
|
25 |
-
print(url)
|
26 |
urls.append(url)
|
27 |
-
print(urls)
|
28 |
|
29 |
-
return urls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
url_title = title.replace(" ", "_")
|
23 |
# Construct the URL and add it to the list
|
24 |
url = f"https://en.wikipedia.org/wiki/{url_title}"
|
|
|
25 |
urls.append(url)
|
|
|
26 |
|
27 |
+
return urls
|
28 |
+
|
29 |
+
def collect_urls(data_list):
|
30 |
+
urls = []
|
31 |
+
for item in data_list:
|
32 |
+
# Check if item is a string and contains 'link:'
|
33 |
+
if isinstance(item, str) and 'link:' in item:
|
34 |
+
start = item.find('link:') + len('link: ')
|
35 |
+
end = item.find(',', start)
|
36 |
+
url = item[start:end if end != -1 else None].strip()
|
37 |
+
urls.append(url)
|
38 |
+
# Check if item is a dictionary and has 'Entry ID'
|
39 |
+
elif isinstance(item, dict) and 'Entry ID' in item:
|
40 |
+
urls.append(item['Entry ID'])
|
41 |
+
last_sources = urls[-3:]
|
42 |
+
return last_sources
|