Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use mentat api for finetuned models #81

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/rawdog/llm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rawdog.logging import log_conversation
from rawdog.parsing import parse_script
from rawdog.prompts import script_examples, script_prompt
from rawdog.utils import EnvInfo, rawdog_log_path
from rawdog.utils import EnvInfo, is_finetuned_model, rawdog_log_path


class LLMClient:
Expand All @@ -35,10 +35,6 @@ def __init__(self, config: dict):
{"role": "system", "content": script_examples},
{"role": "system", "content": EnvInfo(config=self.config).render_prompt()},
]
model = self.config.get("llm_model")
if "ft:" in model or "rawdog" in model or "abante" in model:
# A finetuned model shouldn't need our system prompt
self.conversation = self.conversation[2:]
self.session_cost = 0

def add_message(self, role: str, content: str):
Expand All @@ -49,7 +45,7 @@ def get_python_package(self, import_name: str):
model = self.config.get("pip_model")
llm_model = self.config.get("llm_model")
if model is None:
if "ft:" in llm_model or "rawdog" in llm_model or "abante" in llm_model:
if is_finetuned_model(llm_model):
model = "gpt-3.5-turbo"
else:
model = llm_model
Expand Down Expand Up @@ -95,6 +91,9 @@ def get_script(self, prompt: Optional[str] = None, stream=False):
"response": None,
"cost": None,
}
if is_finetuned_model(model):
base_url = "https://api.mentat.ai"
custom_llm_provider = "openai"
try:
response = completion(
base_url=base_url,
Expand Down
4 changes: 4 additions & 0 deletions src/rawdog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ def render_prompt(self):
last_commit=self.last_commit,
retries=self.retries,
)


def is_finetuned_model(model: str):
return "ft:" in model or "rawdog" in model or "abante" in model
PCSwingle marked this conversation as resolved.
Show resolved Hide resolved
Loading