Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement:improve startup time and minor improvement. #1638

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion metagpt/environment/android/text_icon_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@
import cv2
import groundingdino.datasets.transforms as T
import numpy as np
import torch
class LazyTorch:
def __init__(self):
self._torch = None

def _import_torch(self):
if self._torch is None:
import torch
self._torch = torch

def __getattr__(self, item):
self._import_torch()
return getattr(self._torch, item)

# Create the LazyTorch instance
torch = LazyTorch()
from groundingdino.models import build_model
from groundingdino.util.slconfig import SLConfig
from groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap
Expand Down
3 changes: 2 additions & 1 deletion metagpt/repo_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pathlib import Path
from typing import Dict, List, Optional

import pandas as pd
from pydantic import BaseModel, Field, field_validator

from metagpt.const import AGGREGATION, COMPOSITION, GENERALIZATION
Expand Down Expand Up @@ -508,6 +507,8 @@ def generate_dataframe_structure(self, output_path: Path):
Args:
output_path (Path): The path to the CSV file to be generated.
"""
import pandas as pd

files_classes = [i.model_dump() for i in self.generate_symbols()]
df = pd.DataFrame(files_classes)
df.to_csv(output_path, index=False)
Expand Down
25 changes: 13 additions & 12 deletions metagpt/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ def generate_prompt_chunk(
max_token = TOKEN_MAX.get(model_name, 2048) - reserved - 100

while paragraphs:
paragraph = paragraphs.pop(0)
token = count_output_tokens(paragraph, model_name)
if current_token + token <= max_token:
current_lines.append(paragraph)
current_token += token
elif token > max_token:
paragraphs = split_paragraph(paragraph) + paragraphs
continue
else:
yield prompt_template.format("".join(current_lines))
current_lines = [paragraph]
current_token = token
paragraph = paragraphs.pop(0).strip()
if len(paragraph) != 0:
token = count_output_tokens(paragraph, model_name)
if current_token + token <= max_token:
current_lines.append(paragraph)
current_token += token
elif token > max_token:
paragraphs = split_paragraph(paragraph) + paragraphs
continue
else:
yield prompt_template.format("".join(current_lines))
current_lines = [paragraph]
current_token = token

if current_lines:
yield prompt_template.format("".join(current_lines))
Expand Down
Loading