Former-commit-id: 3213f8736b
pull/47/head
Kye 1 year ago
parent 2ce4847df1
commit 59762dfb22

@ -0,0 +1,8 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1

@ -42,6 +42,6 @@ async def run(swarm_input: SwarmInput):
except ValueError as ve:
logging.error("A ValueError occurred", exc_info=True)
raise HTTPException(status_code=400, detail=str(ve))
except Exception as e:
except Exception:
logging.error("An error occurred", exc_info=True)
raise HTTPException(status_code=500, detail="An unexpected error occurred")

@ -1,5 +1,4 @@
import os
import re
from pathlib import Path
from typing import Dict, List

@ -1,5 +1,4 @@
from swarms import HierarchicalSwarm
import os
# Retrieve your API key from the environment or replace with your actual key
api_key = ""

@ -1,5 +1,2 @@
# from swarms import Swarms, swarm
from swarms.swarms import HierarchicalSwarm, swarm
# from swarms.workers.worker_ultra_node import WorkerUltraNode, WorkerUltra
from swarms.workers.worker_node import WorkerNode, worker_node
from swarms.boss.boss_node import BossNode

@ -2,11 +2,8 @@
#models
from swarms.agents.models.llm import LLM
from swarms.agents.models.hf import HuggingFaceLLM
#tools
from swarms.agents.tools.main import process_csv, MaskFormer, ImageEditing, InstructPix2Pix, Text2Image, VisualQuestionAnswering, ImageCaptioning, browse_web_page, WebpageQATool, web_search

@ -4,15 +4,10 @@ from swarms.utils.logger import logger
from langchain.tools import BaseTool
from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from typing import List, Any, Dict, Optional, Type
from typing import List, Any, Optional
from langchain.memory.chat_message_histories import FileChatMessageHistory
import logging
from pydantic import BaseModel, Extra
from swarms.agents.models.hf import HuggingFaceLLM
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

@ -1 +0,0 @@
from swarms.agents.models.llm import LLM

@ -1,5 +1,3 @@
from transformers import AutoTokenizer
from petals import AutoDistributedForCasualLM
class PetalsHFLLM:
def __init__(self, model_name: str = None, prompt: str = None, device: str = None, use_fast = False, add_bos_token: str = None, cuda=False):

@ -1,3 +1,2 @@
# from swarms.agents.workers import multimodal_agent_tool
from swarms.agents.tools.main import process_csv, ReadFileTool, WriteFileTool, BaseTool, DuckDuckGoSearchRun
# Terminal, CodeWriter, CodeEditor

@ -1,36 +1,12 @@
# ---------- Dependencies ----------
import os
import asyncio
import faiss
from typing import Any, Optional, List
from contextlib import contextmanager
from pydantic import BaseModel, Field
from langchain import LLMChain, OpenAI, PromptTemplate
from langchain.chains.base import Chain
from langchain.experimental import BabyAGI
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores.base import VectorStore
from langchain.vectorstores import FAISS
from langchain.docstore import InMemoryDocstore
from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain
from langchain.agents import ZeroShotAgent, Tool, AgentExecutor
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.tools import BaseTool, DuckDuckGoSearchRun
from langchain.tools.file_management.read import ReadFileTool
from langchain.tools.file_management.write import WriteFileTool
from langchain.tools.human.tool import HumanInputRun
from swarms.agents.tools.main import process_csv, WebpageQATool
from langchain.experimental.autonomous_agents.autogpt.agent import AutoGPT
from langchain.chat_models import ChatOpenAI
from langchain.tools import tool
# ---------- Constants ----------
ROOT_DIR = "./data/"

@ -1,7 +1,7 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Any, Awaitable, Callable, Dict, List, Optional, Type, Union
from typing import Any, Callable, Optional, Type, Union
from pydantic import BaseModel
class ToolException(Exception):

@ -4,9 +4,8 @@ import json
import re
import uuid
from dataclasses import dataclass
from dotenv import load_dotenv
from io import BytesIO
from typing import Any, List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
from typing import Any, List, Optional, Sequence, Tuple, Union
from pydantic import BaseModel, BaseSettings, root_validator
@ -727,9 +726,9 @@ class CodeInterpreterSession:
for file in self.output_files:
if str(file.name) in final_response:
# rm ![Any](file.name) from the response
final_response = re.sub(rf"\n\n!\[.*\]\(.*\)", "", final_response)
final_response = re.sub(r"\n\n!\[.*\]\(.*\)", "", final_response)
if self.output_files and re.search(rf"\n\[.*\]\(.*\)", final_response):
if self.output_files and re.search(r"\n\[.*\]\(.*\)", final_response):
final_response = await remove_download_link(final_response, self.llm)
return CodeInterpreterResponse(content=final_response, files=self.output_files)

@ -10,7 +10,6 @@ from langchain.agents import load_tools
from langchain.agents.tools import BaseTool
from langchain.llms.base import BaseLLM
from langchain.chat_models import ChatOpenAI
import requests
@ -58,9 +57,8 @@ class ToolWrapper:
) -> BaseTool:
func = self.func
if self.is_per_session():
func = lambda *args, **kwargs: self.func(
*args, **kwargs, get_session=get_session
)
def func(*args, **kwargs):
return self.func(*args, **kwargs, get_session=get_session)
return Tool(
name=self.name,
@ -170,7 +168,7 @@ class ExitConversation(BaseToolSet):
_, executor = get_session()
del executor
logger.debug(f"\nProcessed ExitConversation.")
logger.debug("\nProcessed ExitConversation.")
return message
@ -422,8 +420,6 @@ class ToolsFactory:
import os
import subprocess
import time
from datetime import datetime
from typing import Dict, List
from swarms.utils.main import ANSI, Color, Style # test
@ -940,7 +936,7 @@ class CodeEditor(BaseToolSet):
@tool(
name="CodeEditor.READ",
description="Read and understand code. "
f"Input should be filename and line number group. ex. test.py|1-10 "
"Input should be filename and line number group. ex. test.py|1-10 "
"and the output will be code. ",
)
def read(self, inputs: str) -> str:
@ -1470,14 +1466,11 @@ import pandas as pd
from langchain.agents.agent_toolkits.pandas.base import create_pandas_dataframe_agent
from langchain.docstore.document import Document
import asyncio
import nest_asyncio
# Tools
from contextlib import contextmanager
from typing import Optional
from langchain.agents import tool
from langchain.tools.file_management.read import ReadFileTool
from langchain.tools.file_management.write import WriteFileTool
ROOT_DIR = "./data/"
@ -1485,7 +1478,7 @@ from langchain.tools import BaseTool, DuckDuckGoSearchRun
from langchain.text_splitter import RecursiveCharacterTextSplitter
from pydantic import Field
from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain, BaseCombineDocumentsChain
from langchain.chains.qa_with_sources.loading import BaseCombineDocumentsChain
@ -1787,14 +1780,6 @@ web_search = DuckDuckGoSearchRun()
######################## ######################################################## file system
from langchain.tools.file_management import (
ReadFileTool,
CopyFileTool,
DeleteFileTool,
MoveFileTool,
WriteFileTool,
ListDirectoryTool,
)
from langchain.agents.agent_toolkits import FileManagementToolkit
from tempfile import TemporaryDirectory

@ -1,30 +1,23 @@
"""Chain that takes in an input and produces an action and action input."""
from __future__ import annotations
import asyncio
import json
import logging
import time
from abc import abstractmethod
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
import yaml
from pydantic import BaseModel, root_validator
from langchain.agents.agent_types import AgentType
from langchain.agents.tools import InvalidTool
from langchain.callbacks.base import BaseCallbackManager
from langchain.callbacks.manager import (
AsyncCallbackManagerForChainRun,
AsyncCallbackManagerForToolRun,
CallbackManagerForChainRun,
CallbackManagerForToolRun,
Callbacks,
)
from langchain.chains.base import Chain
from langchain.chains.llm import LLMChain
from langchain.input import get_color_mapping
from langchain.prompts.few_shot import FewShotPromptTemplate
from langchain.prompts.prompt import PromptTemplate
from langchain.schema import (
@ -32,12 +25,10 @@ from langchain.schema import (
AgentFinish,
BaseOutputParser,
BasePromptTemplate,
OutputParserException,
)
from langchain.schema.language_model import BaseLanguageModel
from langchain.schema.messages import BaseMessage
from langchain.tools.base import BaseTool
from langchain.utilities.asyncio import asyncio_timeout
logger = logging.getLogger(__name__)

@ -51,17 +51,17 @@ class EVALCallbackHandler(BaseCallbackHandler):
def on_chain_start(
self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any
) -> None:
logger.info(ANSI(f"Entering new chain.").to(Color.green(), Style.italic()))
logger.info(ANSI("Entering new chain.").to(Color.green(), Style.italic()))
logger.info(ANSI("Prompted Text").to(Color.yellow()) + f': {inputs["input"]}\n')
def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None:
logger.info(ANSI(f"Finished chain.").to(Color.green(), Style.italic()))
logger.info(ANSI("Finished chain.").to(Color.green(), Style.italic()))
def on_chain_error(
self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any
) -> None:
logger.error(
ANSI(f"Chain Error").to(Color.red()) + ": " + dim_multiline(str(error))
ANSI("Chain Error").to(Color.red()) + ": " + dim_multiline(str(error))
)
def on_tool_start(

@ -1,4 +1,3 @@
import os
import logging
from typing import Dict, Optional
from celery import Task
@ -7,7 +6,6 @@ from langchain.callbacks.manager import CallbackManager
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain.memory.chat_memory import BaseChatMemory
from swarms.agents.tools.main import BaseToolSet, ToolsFactory
from swarms.agents.prompts.prompts import EVAL_PREFIX, EVAL_SUFFIX
from swarms.agents.utils.agent_setup import AgentSetup
# from .callback import EVALCallbackHandler, ExecutionTracingCallbackHandler
@ -31,7 +29,7 @@ class AgentCreator:
raise TypeError("Session must be a string")
if not session:
raise ValueError("Session is empty")
if not (session in self.memories):
if session not in self.memories:
self.memories[session] = self.create_memory()
return self.memories[session]

@ -45,10 +45,8 @@ Orchestrate(WorkerNode, autoscale=True, nodes=int, swarm_type="flat")
"""
#in a shared state, provide 3 communication times, during task assignment, task compeltion, and feedback or inability to complete a task.
from abc import ABC, abstractmethod
import celery
from typing import List, Dict, Any
import numpy as np
import threading
from swarms.agents.memory.ocean import OceanDB

@ -2,10 +2,9 @@ import logging
import asyncio
from swarms.agents.tools.agent_tools import *
from swarms.workers.worker_node import WorkerNodeInitializer, worker_node
from swarms.workers.worker_node import WorkerNodeInitializer
from swarms.boss.boss_node import BossNodeInitializer as BossNode
from swarms.utils.task import Task
from swarms.agents.models.hf import HuggingFaceLLM
# from langchain import LLMMathChain

@ -1 +0,0 @@
from swarms.utils.embeddings.base import Embeddings

@ -1,2 +0,0 @@
from .worker_node import worker_node
from .worker_ultra_node import WorkerUltraNode

@ -1,7 +1,7 @@
import logging
import re
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional
############
from langchain.prompts import PromptTemplate
@ -19,7 +19,6 @@ logger = logging.getLogger(__name__)
#######################
from pydantic import BaseModel, Field
class WorkerSims(BaseMemory):
llm: BaseLanguageModel

@ -1 +0,0 @@
from GroundingDINO import groundingdino

@ -2,7 +2,6 @@ import typer
from groundingdino.util.inference import load_model, load_image, predict
from tqdm import tqdm
import torchvision
import torch
import fiftyone as fo
@ -23,7 +22,6 @@ def main(
dataset = fo.Dataset.from_images_dir(image_directory)
samples = []
if subsample is not None:

@ -1,12 +1,8 @@
import argparse
from functools import partial
import cv2
import requests
import os
from io import BytesIO
from PIL import Image
import numpy as np
from pathlib import Path
import warnings
@ -26,7 +22,7 @@ import gradio as gr
from groundingdino.models import build_model
from groundingdino.util.slconfig import SLConfig
from groundingdino.util.utils import clean_state_dict
from groundingdino.util.inference import annotate, load_image, predict
from groundingdino.util.inference import annotate, predict
import groundingdino.datasets.transforms as T
from huggingface_hub import hf_hub_download
@ -71,7 +67,6 @@ model = load_model_hf(config_file, ckpt_repo_id, ckpt_filenmae)
def run_grounding(input_image, grounding_caption, box_threshold, text_threshold):
init_image = input_image.convert("RGB")
original_size = init_image.size
_, image_tensor = image_transform_grounding(init_image)
image_pil: Image = image_transform_grounding_for_vis(init_image)

@ -1,6 +1,5 @@
import argparse
import os
import sys
import numpy as np
import torch
@ -8,7 +7,6 @@ from PIL import Image, ImageDraw, ImageFont
import groundingdino.datasets.transforms as T
from groundingdino.models import build_model
from groundingdino.util import box_ops
from groundingdino.util.slconfig import SLConfig
from groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap
from groundingdino.util.vl_utils import create_positive_map_from_span

@ -1,12 +1,9 @@
import argparse
import os
import sys
import time
import numpy as np
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, DistributedSampler
from torch.utils.data import DataLoader
from groundingdino.models import build_model
import groundingdino.datasets.transforms as T

@ -12,4 +12,3 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
# ------------------------------------------------------------------------
from .groundingdino import build_groundingdino

@ -24,7 +24,7 @@ import torchvision
from torch import nn
from torchvision.models._utils import IntermediateLayerGetter
from groundingdino.util.misc import NestedTensor, clean_state_dict, is_main_process
from groundingdino.util.misc import NestedTensor, is_main_process
from .position_encoding import build_position_encoding
from .swin_transformer import build_swin_transformer

@ -6,11 +6,7 @@
# ------------------------------------------------------------------------
import torch
import torch.nn.functional as F
import torch.utils.checkpoint as checkpoint
from torch import Tensor, nn
from torchvision.ops.boxes import nms
from transformers import BertConfig, BertModel, BertPreTrainedModel
from torch import nn
from transformers.modeling_outputs import BaseModelOutputWithPoolingAndCrossAttentions

@ -20,32 +20,22 @@ from typing import List
import torch
import torch.nn.functional as F
from torch import nn
from torchvision.ops.boxes import nms
from transformers import AutoTokenizer, BertModel, BertTokenizer, RobertaModel, RobertaTokenizerFast
from groundingdino.util import box_ops, get_tokenlizer
from groundingdino.util import get_tokenlizer
from groundingdino.util.misc import (
NestedTensor,
accuracy,
get_world_size,
interpolate,
inverse_sigmoid,
is_dist_avail_and_initialized,
nested_tensor_from_tensor_list,
)
from groundingdino.util.utils import get_phrases_from_posmap
from groundingdino.util.visualizer import COCOVisualizer
from groundingdino.util.vl_utils import create_positive_map_from_span
from ..registry import MODULE_BUILD_FUNCS
from .backbone import build_backbone
from .bertwarper import (
BertModelWarper,
generate_masks_with_special_tokens,
generate_masks_with_special_tokens_and_transfer_map,
)
from .transformer import build_transformer
from .utils import MLP, ContrastiveEmbed, sigmoid_focal_loss
from .utils import MLP, ContrastiveEmbed
class GroundingDINO(nn.Module):
@ -152,7 +142,7 @@ class GroundingDINO(nn.Module):
self.backbone = backbone
self.aux_loss = aux_loss
self.box_pred_damping = box_pred_damping = None
self.box_pred_damping = None
self.iter_update = iter_update
assert iter_update, "Why not iter_update?"
@ -308,7 +298,7 @@ class GroundingDINO(nn.Module):
masks.append(mask)
poss.append(pos_l)
input_query_bbox = input_query_label = attn_mask = dn_meta = None
input_query_bbox = input_query_label = attn_mask = None
hs, reference, hs_enc, ref_enc, init_box_proposal = self.transformer(
srcs, masks, input_query_bbox, poss, input_query_label, attn_mask, text_dict
)

@ -250,7 +250,6 @@ class Transformer(nn.Module):
valid_ratios = torch.stack([self.get_valid_ratio(m) for m in masks], 1)
# two stage
enc_topk_proposals = enc_refpoint_embed = None
#########################################################
# Begin Encoder

@ -17,16 +17,11 @@ Copy-paste from torch.nn.Transformer with modifications:
from typing import Optional
import torch
import torch.nn.functional as F
from torch import Tensor, nn
from .utils import (
MLP,
_get_activation_fn,
_get_clones,
gen_encoder_output_proposals,
gen_sineembed_for_position,
sigmoid_focal_loss,
)

@ -5,7 +5,6 @@
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
# ------------------------------------------------------------------------
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from .GroundingDINO import build_groundingdino
def build_model(args):

@ -1,4 +1,4 @@
from transformers import AutoTokenizer, BertModel, BertTokenizer, RobertaModel, RobertaTokenizerFast
from transformers import AutoTokenizer, BertModel, RobertaModel
import os
def get_tokenlizer(text_encoder_type):

@ -268,7 +268,8 @@ def get_embedder(multires, i=0):
}
embedder_obj = Embedder(**embed_kwargs)
embed = lambda x, eo=embedder_obj: eo.embed(x)
def embed(x, eo=embedder_obj):
return eo.embed(x)
return embed, embedder_obj.out_dim

@ -9,7 +9,6 @@
import datetime
import os
import cv2
import matplotlib.pyplot as plt
import numpy as np
import torch
@ -134,7 +133,7 @@ class COCOVisualizer:
def addtgt(self, tgt):
""" """
if tgt is None or not "boxes" in tgt:
if tgt is None or "boxes" not in tgt:
ax = plt.gca()
if "caption" in tgt:

@ -3,27 +3,5 @@
# from .GroundingDINO.groundingdino.util import box_ops, SLConfig
# from .GroundingDINO.groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap
# from .segment_anything.segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator
from swarms.workers.models.GroundingDINO.groundingdino.datasets.transforms import (
Compose,
Normalize,
ToTensor,
crop,
hflip,
resize,
pad,
ResizeDebug,
RandomCrop,
RandomSizeCrop,
CenterCrop,
RandomHorizontalFlip,
RandomResize,
RandomPad,
RandomSelect
)
from swarms.workers.models.GroundingDINO.groundingdino.models import build_model
from swarms.workers.models.GroundingDINO.groundingdino.util import box_ops
from swarms.workers.models.GroundingDINO.groundingdino.util.slconfig import SLConfig
from swarms.workers.models.GroundingDINO.groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap
from swarms.workers.models.segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator

@ -1 +0,0 @@
from segment_anything import segment_anything

@ -4,12 +4,3 @@
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from .build_sam import (
build_sam,
build_sam_vit_h,
build_sam_vit_l,
build_sam_vit_b,
sam_model_registry,
)
from .predictor import SamPredictor
from .automatic_mask_generator import SamAutomaticMaskGenerator

@ -4,8 +4,3 @@
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from .sam import Sam
from .image_encoder import ImageEncoderViT
from .mask_decoder import MaskDecoder
from .prompt_encoder import PromptEncoder
from .transformer import TwoWayTransformer

@ -1 +0,0 @@
from swarms.workers.multi_modal_workers.omni_agent.omni_chat import chat_huggingface

@ -11,10 +11,7 @@ import math
import numpy as np
import argparse
import inspect
import tempfile
from transformers import CLIPSegProcessor, CLIPSegForImageSegmentation
from transformers import pipeline, BlipProcessor, BlipForConditionalGeneration, BlipForQuestionAnswering
from transformers import AutoImageProcessor, UperNetForSemanticSegmentation
from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline, StableDiffusionInstructPix2PixPipeline
from diffusers import EulerAncestralDiscreteScheduler
@ -34,22 +31,10 @@ from swarms.workers.models import (
Compose,
Normalize,
ToTensor,
crop,
hflip,
resize,
pad,
ResizeDebug,
RandomCrop,
RandomSizeCrop,
CenterCrop,
RandomHorizontalFlip,
RandomResize,
RandomPad,
RandomSelect
RandomResize
)
from swarms.workers.models import build_model
from swarms.workers.models import box_ops
from swarms.workers.models import SLConfig
from swarms.workers.models import clean_state_dict, get_phrases_from_posmap
@ -1019,8 +1004,6 @@ class Segmenting:
sorted_anns = sorted(masks, key=(lambda x: x['area']), reverse=True)
ax = plt.gca()
ax.set_autoscale_on(False)
polygons = []
color = []
for ann in sorted_anns:
m = ann['segmentation']
img = np.ones((m.shape[0], m.shape[1], 3))
@ -1363,7 +1346,7 @@ class ObjectSegmenting:
image = self.sam.show_mask(mask[0].cpu().numpy(), image, random_color=True, transparency=0.3)
merged_mask_image = Image.fromarray(merged_mask)
Image.fromarray(merged_mask)
return merged_mask
@ -1371,7 +1354,7 @@ class ObjectSegmenting:
class ImageEditing:
template_model = True
def __init__(self, Text2Box:Text2Box, Segmenting:Segmenting, Inpainting:Inpainting):
print(f"Initializing ImageEditing")
print("Initializing ImageEditing")
self.sam = Segmenting
self.grounding = Text2Box
self.inpaint = Inpainting

@ -8,24 +8,18 @@ from diffusers import DiffusionPipeline, StableDiffusionControlNetPipeline, Cont
from diffusers.utils import load_image
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
from diffusers.utils import export_to_video
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5ForSpeechToSpeech
from transformers import BlipProcessor, BlipForConditionalGeneration
from transformers import TrOCRProcessor, VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
from transformers import SpeechT5Processor, SpeechT5HifiGan, SpeechT5ForSpeechToSpeech
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
from datasets import load_dataset
from PIL import Image
# import flask
# from flask import request, jsonify
import waitress
# from flask_cors import CORS
import io
from torchvision import transforms
import torch
import torchaudio
from speechbrain.pretrained import WaveformEnhancement
import joblib
from huggingface_hub import hf_hub_url, cached_download
from transformers import AutoImageProcessor, TimesformerForVideoClassification
from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation, AutoFeatureExtractor
from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation
from controlnet_aux import OpenposeDetector, MLSDdetector, HEDdetector, CannyDetector, MidasDetector
from controlnet_aux.open_pose.body import Body
from controlnet_aux.mlsd.models.mbv2_mlsd_large import MobileV2_MLSD_Large
@ -119,7 +113,7 @@ def load_pipes(local_deployment):
"device": device
},
"espnet/kan-bayashi_ljspeech_vits": {
"model": Text2Speech.from_pretrained(f"espnet/kan-bayashi_ljspeech_vits"),
"model": Text2Speech.from_pretrained("espnet/kan-bayashi_ljspeech_vits"),
"device": device
},
"lambdalabs/sd-image-variations-diffusers": {

@ -20,11 +20,9 @@ import threading
from queue import Queue
# import flask
# from flask import request, jsonify
import waitress
# from flask_cors import CORS, cross_origin
from swarms.workers.multi_modal_workers.omni_agent.get_token_ids import get_token_ids_for_task_parsing, get_token_ids_for_choose_model, count_tokens, get_max_context_length
from huggingface_hub.inference_api import InferenceApi
from huggingface_hub.inference_api import ALL_TASKS
parser = argparse.ArgumentParser()
parser.add_argument("--config", type=str, default="swarms/agents/workers/multi_modal_workers/omni_agent/config.yml")
@ -253,7 +251,7 @@ def record_case(success, **args):
def image_to_bytes(img_url):
img_byte = io.BytesIO()
type = img_url.split(".")[-1]
img_url.split(".")[-1]
load_image(img_url).save(img_byte, format="png")
img_data = img_byte.getvalue()
return img_data
@ -809,7 +807,7 @@ def run_task(input, command, results, api_key, api_type, api_endpoint):
else:
logger.warning(f"Task {command['task']} is not available. ControlNet need to be deployed locally.")
record_case(success=False, **{"input": input, "task": command, "reason": f"Task {command['task']} is not available. ControlNet need to be deployed locally.", "op":"message"})
inference_result = {"error": f"service related to ControlNet is not available."}
inference_result = {"error": "service related to ControlNet is not available."}
results[id] = collect_result(command, "", inference_result)
return False
elif task in ["summarization", "translation", "conversational", "text-generation", "text2text-generation"]: # ChatGPT Can do
@ -872,7 +870,7 @@ def run_task(input, command, results, api_key, api_type, api_endpoint):
reason = choose["reason"]
best_model_id = choose["id"]
hosted_on = "local" if best_model_id in all_avaliable_models["local"] else "huggingface"
except Exception as e:
except Exception:
logger.warning(f"the response [ {choose_str} ] is not a valid JSON, try to find the model id and reason in the response.")
choose_str = find_json(choose_str)
best_model_id, reason, choose = get_id_reason(choose_str)

@ -1,30 +1,23 @@
import os
import logging
from typing import Optional, Type
from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from swarms.agents.tools.agent_tools import *
from typing import List, Any, Dict, Optional
from typing import List, Dict
from langchain.memory.chat_message_histories import FileChatMessageHistory
import logging
from pydantic import BaseModel, Extra
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
from typing import List, Any, Dict, Optional
from typing import List, Dict
from langchain.memory.chat_message_histories import FileChatMessageHistory
from swarms.utils.main import BaseHandler, FileHandler, FileType
from swarms.utils.main import BaseHandler, FileType
from swarms.agents.tools.main import ExitConversation, RequestsGet, CodeEditor, Terminal
from swarms.utils.main import CsvToDataframe
from swarms.agents.tools.main import BaseToolSet
from swarms.utils.main import StaticUploader
class WorkerUltraNode:

@ -1,16 +1,8 @@
from swarms.agents.tools.agent_tools import *
from langchain.tools import BaseTool
from typing import Optional, Type
from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from typing import List, Any, Dict, Optional
from langchain.memory.chat_message_histories import FileChatMessageHistory
import logging
from pydantic import BaseModel, Extra
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
from swarms.agents.tools.main import Terminal

@ -1,5 +1,5 @@
import pytest
from unittest.mock import Mock, MagicMock
from unittest.mock import Mock
from swarms.agents.memory.oceandb import OceanDB

@ -1,7 +1,7 @@
import unittest
import os
from unittest.mock import patch, MagicMock
from langchain import PromptTemplate, HuggingFaceHub, ChatOpenAI, LLMChain
from unittest.mock import patch
from langchain import HuggingFaceHub, ChatOpenAI
from swarms.agents.models.llm import LLM

@ -1,8 +1,7 @@
import pytest
import torch
from unittest.mock import Mock, MagicMock
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from swarms.agents.models.hf import HuggingFaceLLM # replace with actual import
from unittest.mock import Mock
from swarms.agents.models.hf import HuggingFaceLLM
@pytest.fixture
@ -50,7 +49,7 @@ def test_init_with_quantize(hugging_face_llm, mock_autotokenizer, mock_automodel
}
mock_bitsandbytesconfig.return_value = quantization_config
hugging_face_llm = HuggingFaceLLM(model_id='test', quantize=True)
HuggingFaceLLM(model_id='test', quantize=True)
mock_bitsandbytesconfig.assert_called_once_with(**quantization_config)
mock_autotokenizer.from_pretrained.assert_called_once_with('test')

@ -1,5 +1,4 @@
import pytest
from unittest.mock import Mock
from swarms.worker.omni_worker import OmniWorkerAgent # replace 'yourmodule' with the actual module name
@pytest.fixture

@ -1,6 +1,6 @@
import pytest
from unittest.mock import Mock, MagicMock
from swarms.workers.worker_agent_ultra import WorkerUltraNode, WorkerUltraNodeInitializer # import your module here
from unittest.mock import Mock
from swarms.workers.worker_agent_ultra import WorkerUltraNode # import your module here
def test_create_agent():
mock_llm = Mock()
@ -42,4 +42,4 @@ def test_worker_node():
def test_worker_node_no_key():
with pytest.raises(ValueError):
worker = worker_ultra_node(None)
worker_ultra_node(None)

@ -1,7 +1,6 @@
import pytest
from swarms.agents.tools.agent_tools import *
from unittest.mock import MagicMock, patch
from pydantic import ValidationError
from swarms.worker.worker_node import WorkerNodeInitializer, WorkerNode # replace your_module with actual module name

@ -58,6 +58,6 @@ def test_worker_ultra_node_initializer_initialize_vectorstore(worker_ultra_node_
assert vectorstore is not None
def test_worker_ultra_node_initializer_create_worker_node(worker_ultra_node_initializer):
with patch.object(worker_ultra_node_initializer, 'initialize_llm') as mock_llm, patch.object(worker_ultra_node_initializer, 'initialize_toolsets') as mock_toolsets, patch.object(worker_ultra_node_initializer, 'initialize_vectorstore') as mock_vectorstore:
with patch.object(worker_ultra_node_initializer, 'initialize_llm'), patch.object(worker_ultra_node_initializer, 'initialize_toolsets'), patch.object(worker_ultra_node_initializer, 'initialize_vectorstore'):
worker_node = worker_ultra_node_initializer.create_worker_node()
assert worker_node is not None

@ -1,6 +1,5 @@
import pytest
from unittest.mock import Mock, patch
from pydantic import ValidationError
from swarms.agents.tools.agent_tools import *
from swarms.boss.boss_node import BossNodeInitializer, BossNode
# For initializing BossNodeInitializer in multiple tests

@ -1,6 +1,6 @@
import pytest
import logging
from unittest.mock import Mock, patch
from unittest.mock import patch
from swarms.swarms import HierarchicalSwarm # replace with your actual module name
@pytest.fixture
@ -69,5 +69,5 @@ def test_initialize_tools_with_extra_tools(mock_llm, swarm):
@patch('your_module.FAISS')
def test_initialize_vectorstore(mock_faiss, mock_openai_embeddings, swarm):
mock_openai_embeddings.return_value.embed_query = 'embed_query'
vectorstore = swarm.initialize_vectorstore()
swarm.initialize_vectorstore()
mock_faiss.assert_called_once_with('embed_query', instance_of(faiss.IndexFlatL2), instance_of(InMemoryDocstore), {})

Loading…
Cancel
Save