Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from django.utils.translation import gettext_lazy as _
from langchain.chat_models.base import BaseChatModel
from langchain.schema import BaseMessage
from langchain_core.messages import BaseMessage
from rest_framework import serializers

from application.chat_pipeline.I_base_chat_pipeline import IBaseChatPipelineStep, ParagraphPipelineModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
from django.http import StreamingHttpResponse
from django.utils.translation import gettext as _
from langchain.chat_models.base import BaseChatModel
from langchain.schema import BaseMessage
from langchain.schema.messages import HumanMessage, AIMessage
from langchain_core.messages import AIMessageChunk, SystemMessage
from langchain_core.messages import AIMessageChunk, SystemMessage, BaseMessage, HumanMessage, AIMessage
from rest_framework import status

from application.chat_pipeline.I_base_chat_pipeline import ParagraphPipelineModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Type, List

from django.utils.translation import gettext_lazy as _
from langchain.schema import BaseMessage
from langchain_core.messages import BaseMessage
from rest_framework import serializers

from application.chat_pipeline.I_base_chat_pipeline import IBaseChatPipelineStep, ParagraphPipelineModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"""
from typing import List, Dict

from langchain.schema import BaseMessage, HumanMessage
from langchain_core.messages import SystemMessage
from langchain_core.messages import SystemMessage, BaseMessage, HumanMessage

from application.chat_pipeline.I_base_chat_pipeline import ParagraphPipelineModel
from application.chat_pipeline.step.generate_human_message_step.i_generate_human_message_step import \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import List

from django.utils.translation import gettext as _
from langchain.schema import HumanMessage
from langchain_core.messages import HumanMessage

from application.chat_pipeline.step.reset_problem_step.i_reset_problem_step import IResetProblemStep
from application.models import ChatRecord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

from django.db.models import QuerySet
from django.utils.translation import gettext as _
from langchain.schema import HumanMessage, SystemMessage
from langchain_core.messages import BaseMessage, AIMessage
from langchain_core.messages import BaseMessage, AIMessage, HumanMessage, SystemMessage

from application.flow.i_step_node import NodeResult, INode
from application.flow.step_node.ai_chat_step_node.i_chat_node import IChatNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import reduce

from django.db.models import QuerySet
from langchain.schema import HumanMessage, SystemMessage
from langchain_core.messages import HumanMessage, SystemMessage

from application.flow.i_step_node import INode, NodeResult
from application.flow.step_node.intent_node.i_intent_node import IIntentNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from typing import List, Dict

from django.db.models import QuerySet
from langchain.schema import HumanMessage, SystemMessage
from langchain_core.messages import BaseMessage
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage

from application.flow.i_step_node import NodeResult, INode
from application.flow.step_node.question_node.i_question_node import IQuestionNode
Expand Down
52 changes: 1 addition & 51 deletions apps/models_provider/impl/gemini_model_provider/model/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,10 @@
@Author :Brian Yang
@Date :5/13/24 7:40 AM
"""
from typing import List, Dict, Optional, Sequence, Union, Any, Iterator, cast
from typing import List, Dict, Optional, Any

from google.ai.generativelanguage_v1 import GenerateContentResponse
from google.ai.generativelanguage_v1beta.types import (
Tool as GoogleTool,
)
from langchain_core.callbacks import CallbackManagerForLLMRun
from langchain_core.messages import BaseMessage, get_buffer_string
from langchain_core.outputs import ChatGenerationChunk
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_google_genai._function_utils import _ToolConfigDict, _ToolDict
from langchain_google_genai.chat_models import _chat_with_retry, _response_to_result, \
_FunctionDeclarationType
from langchain_google_genai._common import (
SafetySettingDict,
)

from common.config.tokenizer_manage_config import TokenizerManage
from models_provider.base_model_provider import MaxKBBaseModel
Expand Down Expand Up @@ -60,41 +48,3 @@ def get_num_tokens(self, text: str) -> int:
except Exception as e:
tokenizer = TokenizerManage.get_tokenizer()
return len(tokenizer.encode(text))

def _stream(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
*,
tools: Optional[Sequence[Union[_ToolDict, GoogleTool]]] = None,
functions: Optional[Sequence[_FunctionDeclarationType]] = None,
safety_settings: Optional[SafetySettingDict] = None,
tool_config: Optional[Union[Dict, _ToolConfigDict]] = None,
generation_config: Optional[Dict[str, Any]] = None,
**kwargs: Any,
) -> Iterator[ChatGenerationChunk]:
request = self._prepare_request(
messages,
stop=stop,
tools=tools,
functions=functions,
safety_settings=safety_settings,
tool_config=tool_config,
generation_config=generation_config,
)
response: GenerateContentResponse = _chat_with_retry(
request=request,
generation_method=self.client.stream_generate_content,
**kwargs,
metadata=self.default_metadata,
)
for chunk in response:
_chat_result = _response_to_result(chunk, stream=True)
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
if gen.message:
token_usage = gen.message.usage_metadata
self.__dict__.setdefault('_last_generation_info', {}).update(token_usage)
if run_manager:
run_manager.on_llm_new_token(gen.text)
yield gen
28 changes: 14 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ dependencies = [
"django-mptt==0.17.0",
"psycopg[binary]==3.2.9",
"python-dotenv==1.1.1",
"uuid-utils==0.11.0",
"uuid-utils==0.14.0",
"captcha==0.7.1",
"pytz==2025.2",
"psutil==7.0.0",
"cffi==1.17.1",
"beautifulsoup4==4.13.4",
"jieba==0.42.1",
"langchain-openai==0.3.35",
"langchain-anthropic==0.3.22",
"langchain-community==0.3.31",
"langchain-deepseek==0.1.4",
"langchain-google-genai==2.1.12",
"langchain-mcp-adapters==0.1.13",
"langchain-huggingface==0.3.1",
"langchain-ollama==0.3.10",
"langchain_core==0.3.81",
"langchain-aws==0.2.28",
"langgraph==0.5.3",
"langchain==1.2.9",
"langchain-openai==1.1.9",
"langchain-anthropic==1.3.3",
"langchain-community==0.4.1",
"langchain-deepseek==1.0.1",
"langchain-google-genai==4.2.0",
"langchain-mcp-adapters==0.2.1",
"langchain-huggingface==1.2.0",
"langchain-ollama==1.0.1",
"langchain-aws==1.2.4",
"langgraph==1.0.8",
"torch==2.8.0",
"sentence-transformers==5.0.0",
"qianfan==0.4.12.3",
"zhipuai==2.1.5.20250708",
"volcengine-python-sdk[ark]==4.0.5",
"boto3==1.39.4",
"boto3==1.42.46",
"tencentcloud-sdk-python==3.0.1420",
"xinference-client==1.7.1.post1",
"anthropic==0.74.1",
"anthropic==0.79.0",
"dashscope==1.25.7",
"celery[sqlalchemy]==5.5.3",
"django-celery-beat==2.8.1",
Expand Down