Update README.md
Browse files
README.md
CHANGED
@@ -20,3 +20,77 @@ language:
|
|
20 |
This gemma2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
This gemma2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
23 |
+
|
24 |
+
-- teste esse codigo com o prompt modificado para realizar chamadas de funcao
|
25 |
+
|
26 |
+
from langchain.agents import AgentType, initialize_agent, load_tools
|
27 |
+
from langchain.agents import AgentExecutor
|
28 |
+
from langchain.agents import tool, load_tools, create_react_agent
|
29 |
+
from langchain import hub
|
30 |
+
import os
|
31 |
+
from langchain_ollama.llms import OllamaLLM
|
32 |
+
from langchain.prompts import PromptTemplate
|
33 |
+
|
34 |
+
# Criar tool personalizada
|
35 |
+
@tool
|
36 |
+
def get_word_length(word: str) -> int:
|
37 |
+
"""Returns the length of a word."""
|
38 |
+
return len(word)
|
39 |
+
|
40 |
+
MODEL = "hf.co/vinimuchulski/GEMMA-2-2B-it-GGUF-function_calling:latest"
|
41 |
+
|
42 |
+
custom_react_prompt = PromptTemplate(
|
43 |
+
input_variables=["input", "agent_scratchpad", "tools", "tool_names"],
|
44 |
+
template="""Answer the following questions as best you can. You have access to the following tools:
|
45 |
+
|
46 |
+
{tools}
|
47 |
+
|
48 |
+
Use the following format:
|
49 |
+
|
50 |
+
Question: the input question you must answer
|
51 |
+
Thought: you should always think about what to do
|
52 |
+
Action: the action to take, should be one of [{tool_names}]
|
53 |
+
Action Input: the input to the action, formatted as a string
|
54 |
+
Observation: the result of the action
|
55 |
+
Thought: I now know the final answer
|
56 |
+
Final Answer: the final answer to the original input question
|
57 |
+
|
58 |
+
Example:
|
59 |
+
Question: What is the length of the word "hello"?
|
60 |
+
Thought: I need to use the get_word_length tool to calculate the length of the word "hello".
|
61 |
+
Action: get_word_length
|
62 |
+
Action Input: "hello"
|
63 |
+
Observation: 5
|
64 |
+
Thought: I now know the length of the word "hello" is 5.
|
65 |
+
Final Answer: 5
|
66 |
+
|
67 |
+
Begin!
|
68 |
+
|
69 |
+
Question: {input}
|
70 |
+
Thought: {agent_scratchpad}"""
|
71 |
+
)
|
72 |
+
|
73 |
+
# Formatar as ferramentas para o prompt
|
74 |
+
tools = [get_word_length]
|
75 |
+
tools_str = "\n".join([f"{tool.name}: {tool.description}" for tool in tools])
|
76 |
+
tool_names = ", ".join([tool.name for tool in tools])
|
77 |
+
|
78 |
+
# Criar o agente com o prompt personalizado
|
79 |
+
agent = create_react_agent(
|
80 |
+
tools=tools,
|
81 |
+
llm=llm,
|
82 |
+
prompt=custom_react_prompt.partial(tools=tools_str, tool_names=tool_names),
|
83 |
+
)
|
84 |
+
|
85 |
+
# Criar o executor
|
86 |
+
agent_executor = AgentExecutor(
|
87 |
+
agent=agent,
|
88 |
+
tools=tools,
|
89 |
+
verbose=True,
|
90 |
+
handle_parsing_errors=True
|
91 |
+
)
|
92 |
+
|
93 |
+
# Testar
|
94 |
+
question = "What is the length of the word PythonDanelonAugustoTrajanoRomanovCzarVespasianoDiocleciano ?"
|
95 |
+
response = agent_executor.invoke({"input": question})
|
96 |
+
print(response)
|