Skip to content

Commit

Permalink
[EXAMPLES][Jamba ++ Command R Tool Agent]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Apr 4, 2024
1 parent fefc884 commit a86f597
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 4 deletions.
59 changes: 59 additions & 0 deletions playground/agents/command_r_tool_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from pydantic import BaseModel, Field
from transformers import AutoModelForCausalLM, AutoTokenizer

from swarms import ToolAgent
from swarms.utils.json_utils import base_model_to_json

# Model name
model_name = "CohereForAI/c4ai-command-r-v01-4bit"

# Load the pre-trained model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
)

# Load the pre-trained model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Initialize the schema for the person's information
class APIExampleRequestSchema(BaseModel):
endpoint: str = Field(
..., description="The API endpoint for the example request"
)
method: str = Field(
..., description="The HTTP method for the example request"
)
headers: dict = Field(
..., description="The headers for the example request"
)
body: dict = Field(
..., description="The body of the example request"
)
response: dict = Field(
..., description="The expected response of the example request"
)

# Convert the schema to a JSON string
api_example_schema = base_model_to_json(APIExampleRequestSchema)
# Convert the schema to a JSON string

# Define the task to generate a person's information
task = (
"Generate an example API request using this code:\n"
)

# Create an instance of the ToolAgent class
agent = ToolAgent(
name="Command R Tool Agent",
description="An agent that generates an API request using the Command R model.",
model=model,
tokenizer=tokenizer,
json_schema=api_example_schema,
)

# Run the agent to generate the person's information
generated_data = agent.run(task)

# Print the generated data
print(f"Generated data: {generated_data}")
59 changes: 59 additions & 0 deletions playground/agents/jamba_tool_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from pydantic import BaseModel, Field
from transformers import AutoModelForCausalLM, AutoTokenizer

from swarms import ToolAgent
from swarms.utils.json_utils import base_model_to_json

# Model name
model_name = "ai21labs/Jamba-v0.1"

# Load the pre-trained model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
)

# Load the pre-trained model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Initialize the schema for the person's information
class APIExampleRequestSchema(BaseModel):
endpoint: str = Field(
..., description="The API endpoint for the example request"
)
method: str = Field(
..., description="The HTTP method for the example request"
)
headers: dict = Field(
..., description="The headers for the example request"
)
body: dict = Field(
..., description="The body of the example request"
)
response: dict = Field(
..., description="The expected response of the example request"
)

# Convert the schema to a JSON string
api_example_schema = base_model_to_json(APIExampleRequestSchema)
# Convert the schema to a JSON string

# Define the task to generate a person's information
task = (
"Generate an example API request using this code:\n"
)

# Create an instance of the ToolAgent class
agent = ToolAgent(
name="Command R Tool Agent",
description="An agent that generates an API request using the Command R model.",
model=model,
tokenizer=tokenizer,
json_schema=api_example_schema,
)

# Run the agent to generate the person's information
generated_data = agent(task)

# Print the generated data
print(f"Generated data: {generated_data}")
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "swarms"
version = "4.7.4"
version = "4.7.8"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <[email protected]>"]
Expand Down Expand Up @@ -44,6 +44,8 @@ Pillow = "10.2.0"
rich = "13.5.2"
psutil = "*"
sentry-sdk = "*"
python-dotenv = "*"
accelerate = "0.28.0"

[tool.poetry.dev-dependencies]
black = "23.3.0"
Expand Down
4 changes: 1 addition & 3 deletions swarms/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
remove_whitespace_from_yaml,
)
from swarms.utils.save_logs import parse_log_file
from swarms.utils.supervision_visualizer import MarkVisualizer
# from swarms.utils.supervision_visualizer import MarkVisualizer
from swarms.utils.try_except_wrapper import try_except_wrapper
from swarms.utils.yaml_output_parser import YamlOutputParser
from swarms.utils.concurrent_utils import execute_concurrently
Expand Down Expand Up @@ -77,8 +77,6 @@
"remove_whitespace_from_json",
"remove_whitespace_from_yaml",
"parse_log_file",
"MarkVisualizer",
# "limit_tokens_from_string",
"try_except_wrapper",
"YamlOutputParser",
"execute_concurrently",
Expand Down

0 comments on commit a86f597

Please sign in to comment.