Skip to content

Commit

Permalink
support extra_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ZingLix committed Jan 31, 2024
1 parent 2ccae33 commit 3f6c08b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/qianfan/common/client/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.


import json
from concurrent.futures import ThreadPoolExecutor, wait
from typing import Any, List, Optional, Tuple

Expand Down Expand Up @@ -361,6 +362,11 @@ def chat_entry(
enable_citation: Optional[bool] = typer.Option(
None, help="Enable citation", rich_help_panel=MODEL_ARGUMENTS_PANEL
),
extra_parameters: Optional[str] = typer.Option(
None,
help="Extra parameters for the model. This should be a json string.",
rich_help_panel=MODEL_ARGUMENTS_PANEL,
),
) -> None:
"""
Chat with the LLM in the terminal.
Expand All @@ -384,6 +390,8 @@ def add_if_not_none(key: str, value: Any) -> None:

if stop is not None:
extra_args["stop"] = stop.split(",")
if extra_parameters is not None:
extra_args["extra_parameters"] = json.loads(extra_parameters)

client = ChatClient(model, endpoint, multi_line, debug=debug, **extra_args)
client.chat_in_terminal()
Expand Down
4 changes: 3 additions & 1 deletion src/qianfan/resources/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ def _generate_body(
f"The required key `{key}` is not provided."
)
kwargs["stream"] = stream
kwargs["extra_parameters"] = {"request_source": f"qianfan_py_sdk_v{VERSION}"}
if "extra_parameters" not in kwargs:
kwargs["extra_parameters"] = {}
kwargs["extra_parameters"]["request_source"] = f"qianfan_py_sdk_v{VERSION}"
return kwargs

def _data_postprocess(self, data: QfResponse) -> QfResponse:
Expand Down

0 comments on commit 3f6c08b

Please sign in to comment.