[EXAMPLE][ToolAgent]

pull/378/head
Kye 11 months ago
parent 20e263cb40
commit 8b3b2fde1e

@ -83,32 +83,38 @@ ToolAgent is an agent that outputs JSON using any model from huggingface. It tak
```python
# Import necessary libraries
from transformers import AutoModelForCausalLM, AutoTokenizer
from swarms import ToolAgent
# Load the pre-trained model and tokenizer
model = AutoModelForCausalLM.from_pretrained("databricks/dolly-v2-12b")
tokenizer = AutoTokenizer.from_pretrained("databricks/dolly-v2-12b")
# Define a JSON schema for person's information
json_schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"},
"is_student": {"type": "boolean"},
"courses": {
"type": "array",
"items": {"type": "string"}
}
}
"courses": {"type": "array", "items": {"type": "string"}},
},
}
# Define the task to generate a person's information
task = "Generate a person's information based on the following schema:"
# Create an instance of the ToolAgent class
agent = ToolAgent(model=model, tokenizer=tokenizer, json_schema=json_schema)
# Run the agent to generate the person's information
generated_data = agent.run(task)
# Print the generated data
print(generated_data)
```

@ -0,0 +1,36 @@
# Import necessary libraries
from transformers import AutoModelForCausalLM, AutoTokenizer
from swarms import ToolAgent
# Load the pre-trained model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
"databricks/dolly-v2-12b"
)
tokenizer = AutoTokenizer.from_pretrained("databricks/dolly-v2-12b")
# Define a JSON schema for person's information
json_schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"},
"is_student": {"type": "boolean"},
"courses": {"type": "array", "items": {"type": "string"}},
},
}
# Define the task to generate a person's information
task = (
"Generate a person's information based on the following schema:"
)
# Create an instance of the ToolAgent class
agent = ToolAgent(
model=model, tokenizer=tokenizer, json_schema=json_schema
)
# Run the agent to generate the person's information
generated_data = agent.run(task)
# Print the generated data
print(generated_data)
Loading…
Cancel
Save