Merge pull request #1590 from hypn4/main

feat: add `extra_body`field and use in model settings.
This commit is contained in:
paul-gauthier 2024-09-24 13:16:38 -07:00 committed by GitHub
commit 0adb7e0fd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 1 deletions

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ _site
.jekyll-cache/
.jekyll-metadata
aider/__version__.py
.venv/

View file

@ -1399,6 +1399,7 @@ class Coder:
self.stream,
temp,
extra_headers=model.extra_headers,
extra_body=model.extra_body,
max_tokens=model.max_tokens,
)
self.chat_completion_call_hashes.append(hash_object.hexdigest())

View file

@ -74,6 +74,7 @@ class ModelSettings:
reminder: str = "user"
examples_as_sys_msg: bool = False
extra_headers: Optional[dict] = None
extra_body: Optional[dict] = None
max_tokens: Optional[int] = None
cache_control: bool = False
caches_by_default: bool = False

View file

@ -53,6 +53,7 @@ def send_completion(
stream,
temperature=0,
extra_headers=None,
extra_body=None,
max_tokens=None,
):
from aider.llm import litellm
@ -71,6 +72,8 @@ def send_completion(
kwargs["tool_choice"] = {"type": "function", "function": {"name": function["name"]}}
if extra_headers is not None:
kwargs["extra_headers"] = extra_headers
if extra_body is not None:
kwargs["extra_body"] = extra_body
if max_tokens is not None:
kwargs["max_tokens"] = max_tokens
@ -93,7 +96,7 @@ def send_completion(
@lazy_litellm_retry_decorator
def simple_send_with_retries(model_name, messages, extra_headers=None):
def simple_send_with_retries(model_name, messages, extra_headers=None, extra_body=None):
try:
kwargs = {
"model_name": model_name,
@ -103,6 +106,8 @@ def simple_send_with_retries(model_name, messages, extra_headers=None):
}
if extra_headers is not None:
kwargs["extra_headers"] = extra_headers
if extra_body is not None:
kwargs["extra_body"] = extra_body
_hash, response = send_completion(**kwargs)
return response.choices[0].message.content