Skip to content

Commit

Permalink
[fix] stream field in llmconfig not work
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei-Jianan committed May 9, 2024
1 parent f201b2f commit 8f209bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion metagpt/provider/base_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
wait_random_exponential,
)

from metagpt.config2 import config
from metagpt.configs.llm_config import LLMConfig
from metagpt.const import LLM_API_TIMEOUT, USE_CONFIG_TIMEOUT
from metagpt.logs import logger
Expand Down Expand Up @@ -132,7 +133,7 @@ async def aask(
format_msgs: Optional[list[dict[str, str]]] = None,
images: Optional[Union[str, list[str]]] = None,
timeout=USE_CONFIG_TIMEOUT,
stream=True,
stream=None,
) -> str:
if system_msgs:
message = self._system_msgs(system_msgs)
Expand All @@ -146,6 +147,8 @@ async def aask(
message.append(self._user_msg(msg, images=images))
else:
message.extend(msg)
if stream is None:
stream = config.llm.stream
logger.debug(message)
rsp = await self.acompletion_text(message, stream=stream, timeout=self.get_timeout(timeout))
return rsp
Expand Down
2 changes: 1 addition & 1 deletion metagpt/rag/benchmark/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def mean_reciprocal_rank(self, nodes: list[NodeWithScore], reference_docs: list[
return mrr_sum

return mrr_sum

async def semantic_similarity(self, response: str, reference: str) -> float:
result = await self.evaluator.aevaluate(
response=response,
Expand Down
10 changes: 6 additions & 4 deletions metagpt/rag/factories/ranker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from metagpt.rag.rankers.object_ranker import ObjectSortPostprocessor
from metagpt.rag.schema import (
BaseRankerConfig,
BGERerankConfig,
CohereRerankConfig,
ColbertRerankConfig,
LLMRankerConfig,
ObjectRankerConfig,
CohereRerankConfig,
BGERerankConfig
)


Expand Down Expand Up @@ -60,13 +60,15 @@ def _create_cohere_rerank(self, config: CohereRerankConfig, **kwargs) -> LLMRera

def _create_bge_rerank(self, config: BGERerankConfig, **kwargs) -> LLMRerank:
try:
from llama_index.postprocessor.flag_embedding_reranker import FlagEmbeddingReranker
from llama_index.postprocessor.flag_embedding_reranker import (
FlagEmbeddingReranker,
)
except ImportError:
raise ImportError(
"`llama-index-postprocessor-flag-embedding-reranker` package not found, please run `pip install llama-index-postprocessor-flag-embedding-reranker`"
)
return FlagEmbeddingReranker(**config.model_dump())

def _create_object_ranker(self, config: ObjectRankerConfig, **kwargs) -> LLMRerank:
return ObjectSortPostprocessor(**config.model_dump())

Expand Down

0 comments on commit 8f209bf

Please sign in to comment.