Skip to content

Commit

Permalink
community[patch]: add stop parameter support to volcengine maas (lang…
Browse files Browse the repository at this point in the history
…chain-ai#19052)

- **Description:** add stop parameter to volcengine maas model
- **Dependencies:** no

---------

Co-authored-by: 江鹏飞 <jiangpengfei.jiangpf@bytedance.com>
  • Loading branch information
joyme123 and 江鹏飞 authored Mar 17, 2024
1 parent bcc771e commit 514fe80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def _stream(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> Iterator[ChatGenerationChunk]:
if stop is not None:
kwargs["stop"] = stop
params = self._convert_prompt_msg_params(messages, **kwargs)
for res in self.client.stream_chat(params):
if res:
Expand All @@ -133,6 +135,8 @@ def _generate(
for chunk in self._stream(messages, stop, run_manager, **kwargs):
completion += chunk.text
else:
if stop is not None:
kwargs["stop"] = stop
params = self._convert_prompt_msg_params(messages, **kwargs)
res = self.client.chat(params)
msg = convert_dict_to_message(res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ def test_stream() -> None:
assert isinstance(response.content, str)


def test_stop() -> None:
"""Test that stop works."""
chat = VolcEngineMaasChat(
model="skylark2-pro-4k", model_version="1.2", streaming=True
)
callback_handler = FakeCallbackHandler()
callback_manager = CallbackManager([callback_handler])
response = chat(
messages=[
HumanMessage(content="repeat: hello world"),
AIMessage(content="hello world"),
HumanMessage(content="repeat: hello world"),
],
stream=True,
callbacks=callback_manager,
stop=["world"],
)
assert callback_handler.llm_streams > 0
assert isinstance(response.content, str)
assert response.content.rstrip() == "hello"


def test_multiple_messages() -> None:
"""Tests multiple messages works."""
chat = VolcEngineMaasChat()
Expand Down

0 comments on commit 514fe80

Please sign in to comment.