Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,397 Bytes
886d8e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
---
title: Custom Models
---
In addition to hosted and local language models, Open Interpreter also supports custom models.
As long as your system can accept an input and stream an output (and can be interacted with via a Python generator) it can be used as a language model in Open Interpreter.
Simply replace the OpenAI-compatible `completions` function in your language model with one of your own:
```python
def custom_language_model(openai_message):
"""
OpenAI-compatible completions function (this one just echoes what the user said back).
"""
users_content = openai_message[-1].get("content") # Get last message's content
# To make it OpenAI-compatible, we yield this first:
yield {"delta": {"role": "assistant"}}
for character in users_content:
yield {"delta": {"content": character}}
# Tell Open Interpreter to power the language model with this function
interpreter.llm.completion = custom_language_model
```
Then, set the following settings:
```
interpreter.llm.context_window = 2000 # In tokens
interpreter.llm.max_tokens = 1000 # In tokens
interpreter.llm.supports_vision = False # Does this completions endpoint accept images?
interpreter.llm.supports_functions = False # Does this completions endpoint accept/return function calls?
```
And start using it:
```
interpreter.chat("Hi!") # Returns/displays "Hi!" character by character
``` |