Merge branch 'main' of https://github.com/continuedev/continue
This commit is contained in:
commit
281f5aa237
3 changed files with 6 additions and 6 deletions
|
|
@ -17,11 +17,11 @@ class FunctionCall(ContinueBaseModel):
|
|||
|
||||
class ChatMessage(ContinueBaseModel):
|
||||
role: ChatMessageRole
|
||||
content: str | None
|
||||
name: str | None
|
||||
content: Union[str, None] = None
|
||||
name: Union[str, None] = None
|
||||
# A summary for pruning chat context to fit context window. Often the Step name.
|
||||
summary: str
|
||||
function_call: FunctionCall | None = None
|
||||
function_call: Union[FunctionCall, None] = None
|
||||
|
||||
def to_dict(self, with_functions: bool) -> Dict:
|
||||
d = self.dict()
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class ProxyServer(LLM):
|
|||
except:
|
||||
raise Exception(await resp.text())
|
||||
|
||||
async def stream_chat(self, messages: List[ChatMessage] = [], **kwargs) -> Coroutine[Any, Any, Generator[Any | List | Dict, None, None]]:
|
||||
async def stream_chat(self, messages: List[ChatMessage] = [], **kwargs) -> Coroutine[Any, Any, Generator[Union[Any, List, Dict], None, None]]:
|
||||
args = self.default_args | kwargs
|
||||
messages = compile_chat_messages(
|
||||
self.default_model, messages, None, with_functions=args["model"].endswith("0613"))
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def encoding_for_model(model: str):
|
|||
return tiktoken.encoding_for_model(aliases.get(model, model))
|
||||
|
||||
|
||||
def count_tokens(model: str, text: str | None):
|
||||
def count_tokens(model: str, text: Union[str, None]):
|
||||
if text is None:
|
||||
return 0
|
||||
encoding = encoding_for_model(model)
|
||||
|
|
@ -74,7 +74,7 @@ def prune_chat_history(model: str, chat_history: List[ChatMessage], max_tokens:
|
|||
return chat_history
|
||||
|
||||
|
||||
def compile_chat_messages(model: str, msgs: List[ChatMessage], prompt: str | None = None, with_functions: bool = False, system_message: Union[str, None] = None) -> List[Dict]:
|
||||
def compile_chat_messages(model: str, msgs: List[ChatMessage], prompt: Union[str, None] = None, with_functions: bool = False, system_message: Union[str, None] = None) -> List[Dict]:
|
||||
prompt_tokens = count_tokens(model, prompt)
|
||||
msgs = prune_chat_history(model,
|
||||
msgs, MAX_TOKENS_FOR_MODEL[model], prompt_tokens + 1000 + count_tokens(model, system_message))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue