Upload folder using huggingface_hub
Browse files
agent.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import ReactCodeAgent, HfApiEngine
|
2 |
+
from prompts import SQUAD_REACT_CODE_SYSTEM_PROMPT
|
3 |
+
from tools.squad_tools import SquadRetrieverTool, SquadQueryTool
|
4 |
+
from tools.text_to_image import TextToImageTool
|
5 |
+
|
6 |
+
def get_agent():
|
7 |
+
# model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
8 |
+
model_name = "http://localhost:1234/v1"
|
9 |
+
|
10 |
+
llm_engine = HfApiEngine(model_name)
|
11 |
+
|
12 |
+
TASK_SOLVING_TOOLBOX = [
|
13 |
+
SquadRetrieverTool(),
|
14 |
+
SquadQueryTool(),
|
15 |
+
TextToImageTool(),
|
16 |
+
]
|
17 |
+
|
18 |
+
# Initialize the agent with both tools
|
19 |
+
agent = ReactCodeAgent(
|
20 |
+
tools=TASK_SOLVING_TOOLBOX,
|
21 |
+
llm_engine=llm_engine,
|
22 |
+
system_prompt=SQUAD_REACT_CODE_SYSTEM_PROMPT,
|
23 |
+
)
|
24 |
+
|
25 |
+
return agent
|
26 |
+
|
app.py
CHANGED
@@ -1,40 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio import ChatMessage
|
3 |
-
from transformers import ReactCodeAgent, HfApiEngine
|
4 |
from utils import stream_from_transformers_agent
|
5 |
-
from prompts import SQUAD_REACT_CODE_SYSTEM_PROMPT
|
6 |
-
from tools.squad_tools import SquadRetrieverTool, SquadQueryTool
|
7 |
-
from tools.text_to_image import TextToImageTool
|
8 |
from gradio.context import Context
|
9 |
from gradio import Request
|
10 |
import pickle
|
11 |
import os
|
12 |
from dotenv import load_dotenv
|
|
|
13 |
|
14 |
load_dotenv()
|
15 |
|
16 |
-
TASK_SOLVING_TOOLBOX = [
|
17 |
-
SquadRetrieverTool(),
|
18 |
-
SquadQueryTool(),
|
19 |
-
TextToImageTool(),
|
20 |
-
]
|
21 |
-
|
22 |
sessions_path = "sessions.pkl"
|
23 |
sessions = pickle.load(open(sessions_path, "rb")) if os.path.exists(sessions_path) else {}
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
28 |
-
# model_name = "http://localhost:1234/v1"
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
# Initialize the agent with both tools
|
33 |
-
agent = ReactCodeAgent(
|
34 |
-
tools=TASK_SOLVING_TOOLBOX,
|
35 |
-
llm_engine=llm_engine,
|
36 |
-
system_prompt=SQUAD_REACT_CODE_SYSTEM_PROMPT,
|
37 |
-
)
|
38 |
|
39 |
def append_example_message(x: gr.SelectData, messages):
|
40 |
if x.value["text"] is not None:
|
|
|
1 |
import gradio as gr
|
2 |
from gradio import ChatMessage
|
|
|
3 |
from utils import stream_from_transformers_agent
|
|
|
|
|
|
|
4 |
from gradio.context import Context
|
5 |
from gradio import Request
|
6 |
import pickle
|
7 |
import os
|
8 |
from dotenv import load_dotenv
|
9 |
+
from agent import get_agent
|
10 |
|
11 |
load_dotenv()
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
sessions_path = "sessions.pkl"
|
14 |
sessions = pickle.load(open(sessions_path, "rb")) if os.path.exists(sessions_path) else {}
|
15 |
|
16 |
+
agent = get_agent()
|
|
|
|
|
|
|
17 |
|
18 |
+
app = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def append_example_message(x: gr.SelectData, messages):
|
21 |
if x.value["text"] is not None:
|