Skip to content

Commit

Permalink
Allow passing of can_stream in openai_models.py (#600)
Browse files Browse the repository at this point in the history
* Allow passing of can_stream in openai_models.py

Fixes #599 

* Only set can_stream: false if it is false

Refs #600 (comment)

* Docs for can_stream: false

---------

Co-authored-by: Simon Willison <swillison@gmail.com>
  • Loading branch information
cmungall and simonw authored Nov 6, 2024
1 parent 7146fe8 commit 3b2e526
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/other-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ You can set `api_key_name` to the name of a key stored using the {ref}`api-keys`

Add `completion: true` if the model is a completion model that uses a `/completion` as opposed to a `/completion/chat` endpoint.

If a model does not support streaming, add `can_stream: false` to disable the streaming option.

Having configured the model like this, run `llm models` to check that it installed correctly. You can then run prompts against it like so:

```bash
Expand Down
4 changes: 4 additions & 0 deletions llm/default_plugins/openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def register_models(register):
api_version = extra_model.get("api_version")
api_engine = extra_model.get("api_engine")
headers = extra_model.get("headers")
kwargs = {}
if extra_model.get("can_stream") is False:
kwargs["can_stream"] = False
if extra_model.get("completion"):
klass = Completion
else:
Expand All @@ -73,6 +76,7 @@ def register_models(register):
api_version=api_version,
api_engine=api_engine,
headers=headers,
**kwargs,
)
if api_base:
chat_model.needs_key = None
Expand Down

0 comments on commit 3b2e526

Please sign in to comment.