Skip to content

Commit

Permalink
feat: 高级编排支持文件上传(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuruibin committed Nov 6, 2024
1 parent 912149d commit acb1463
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str):
chat_model = node_variable.get('chat_model')
message_tokens = chat_model.get_num_tokens_from_messages(node_variable.get('message_list'))
message_tokens = node_variable['usage_metadata']['output_tokens'] if 'usage_metadata' in node_variable else 0
answer_tokens = chat_model.get_num_tokens(answer)
node.context['message_tokens'] = message_tokens
node.context['answer_tokens'] = answer_tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], **
model=model_name,
openai_api_base=model_credential.get('api_base'),
openai_api_key=model_credential.get('api_key'),
stream_options={"include_usage": True},
**optional_params,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

import base64
import os
from typing import List, Dict, Optional, Iterator, Any, cast
from typing import Dict

from langchain_community.chat_models import ChatOpenAI
from langchain_community.llms.tongyi import generate_with_last_element_mark
from langchain_core.callbacks import CallbackManagerForLLMRun
from langchain_core.language_models import LanguageModelInput
from langchain_core.messages import BaseMessage
from langchain_core.messages import HumanMessage
from langchain_core.outputs import ChatGenerationChunk, ChatGeneration
from langchain_core.runnables import RunnableConfig, ensure_config

from setting.models_provider.base_model_provider import MaxKBBaseModel


class QwenVLChatModel(MaxKBBaseModel, ChatOpenAI):
usage_metadata: dict = {}

@staticmethod
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
Expand All @@ -44,12 +37,5 @@ def generate_message(prompt: str, image) -> list[HumanMessage]:
])]
return [HumanMessage(prompt)]

def get_last_generation_info(self) -> Optional[Dict[str, Any]]:
return self.usage_metadata

def get_num_tokens_from_messages(self, messages: List[BaseMessage]) -> int:
return self.usage_metadata.get('input_tokens', 0)

def get_num_tokens(self, text: str) -> int:
return self.usage_metadata.get('output_tokens', 0)

0 comments on commit acb1463

Please sign in to comment.