mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
community[patch]: Fix MiniMaxChat validate_environment error (#23770)
- **Description:** Fix some issues in MiniMaxChat - Fix `minimax_api_host` not in `values` error - Remove `minimax_group_id` from reading environment variables, the `minimax_group_id` no longer use in MiniMaxChat - Invoke callback prior to yielding token, the issus #16913
This commit is contained in:
parent
acc457f645
commit
e4e28a6ff5
@ -186,15 +186,20 @@ class MiniMaxChat(BaseChatModel):
|
||||
"MINIMAX_API_KEY",
|
||||
)
|
||||
)
|
||||
values["minimax_group_id"] = get_from_dict_or_env(
|
||||
values, ["minimax_group_id", "group_id"], "MINIMAX_GROUP_ID"
|
||||
)
|
||||
|
||||
default_values = {
|
||||
name: field.default
|
||||
for name, field in cls.__fields__.items()
|
||||
if field.default is not None
|
||||
}
|
||||
default_values.update(values)
|
||||
|
||||
# Get custom api url from environment.
|
||||
values["minimax_api_host"] = get_from_dict_or_env(
|
||||
values,
|
||||
"minimax_api_host",
|
||||
["minimax_api_host", "base_url"],
|
||||
"MINIMAX_API_HOST",
|
||||
values["minimax_api_host"],
|
||||
default_values["minimax_api_host"],
|
||||
)
|
||||
return values
|
||||
|
||||
@ -316,9 +321,10 @@ class MiniMaxChat(BaseChatModel):
|
||||
chunk = ChatGenerationChunk(
|
||||
message=chunk, generation_info=generation_info
|
||||
)
|
||||
yield chunk
|
||||
if run_manager:
|
||||
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||
yield chunk
|
||||
|
||||
if finish_reason is not None:
|
||||
break
|
||||
|
||||
@ -394,8 +400,9 @@ class MiniMaxChat(BaseChatModel):
|
||||
chunk = ChatGenerationChunk(
|
||||
message=chunk, generation_info=generation_info
|
||||
)
|
||||
yield chunk
|
||||
if run_manager:
|
||||
await run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||
yield chunk
|
||||
|
||||
if finish_reason is not None:
|
||||
break
|
||||
|
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from langchain_core.messages import AIMessage
|
||||
|
||||
from langchain_community.chat_models import MiniMaxChat
|
||||
|
||||
|
||||
def test_chat_minimax_not_group_id() -> None:
|
||||
if "MINIMAX_GROUP_ID" in os.environ:
|
||||
del os.environ["MINIMAX_GROUP_ID"]
|
||||
chat = MiniMaxChat() # type: ignore[call-arg]
|
||||
response = chat.invoke("你好呀")
|
||||
assert isinstance(response, AIMessage)
|
||||
assert isinstance(response.content, str)
|
||||
|
||||
|
||||
def test_chat_minimax_with_stream() -> None:
|
||||
chat = MiniMaxChat() # type: ignore[call-arg]
|
||||
for chunk in chat.stream("你好呀"):
|
||||
assert isinstance(chunk, AIMessage)
|
||||
assert isinstance(chunk.content, str)
|
Loading…
Reference in New Issue
Block a user