Skip to content

Commit

Permalink
Merge pull request #38 from jepler/misc-updates
Browse files Browse the repository at this point in the history
Update anthropic back-end & other small changes
  • Loading branch information
jepler authored Jun 23, 2024
2 parents 271792e + 0a98049 commit 18616ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/chap/backends/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Anthropic(AutoAskMixin):
@dataclass
class Parameters:
url: str = "https://api.anthropic.com"
model: str = "claude-3-sonnet-20240229"
model: str = "claude-3-5-sonnet-20240620"
max_new_tokens: int = 1000

def __init__(self) -> None:
Expand Down Expand Up @@ -94,5 +94,5 @@ def get_key(cls) -> str:


def factory() -> Backend:
"""Uses the huggingface text-generation-interface web API"""
"""Uses the anthropic text-generation-interface web API"""
return Anthropic()
16 changes: 11 additions & 5 deletions src/chap/backends/llama_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ class Parameters:
url: str = "http://localhost:8080/completion"
"""The URL of a llama.cpp server's completion endpoint."""

start_prompt: str = "<s>"
system_format: str = "<<SYS>>{}<</SYS>>"
user_format: str = " [INST] {} [/INST]"
assistant_format: str = " {}</s>"
start_prompt: str = "<|begin_of_text|>"
system_format: str = (
"<|start_header_id|>system<|end_header_id|>\n\n{}<|eot_id|>"
)
user_format: str = "<|start_header_id|>user<|end_header_id|>\n\n{}<|eot_id|>"
assistant_format: str = (
"<|start_header_id|>assistant<|end_header_id|>\n\n{}<|eot_id|>"
)
end_prompt: str = "<|start_header_id|>assistant<|end_header_id|>\n\n"
stop: str | None = None

def __init__(self) -> None:
super().__init__()
Expand Down Expand Up @@ -59,7 +65,7 @@ async def aask(
params = {
"prompt": self.make_full_query(session + [User(query)], max_query_size),
"stream": True,
"stop": ["</s>", "<s>", "[INST]"],
"stop": ["</s>", "<s>", "[INST]", "<|eot_id|>"],
}
new_content: list[str] = []
try:
Expand Down
6 changes: 5 additions & 1 deletion src/chap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ def configure_api_from_environment(
setattr(api.parameters, field.name, tv)


def get_api(ctx: click.Context, name: str = "openai_chatgpt") -> Backend:
def get_api(ctx: click.Context | None = None, name: str | None = None) -> Backend:
if ctx is None:
ctx = click.Context(click.Command("chap"))
if name is None:
name = os.environ.get("CHAP_BACKEND", "openai_chatgpt")
name = name.replace("-", "_")
backend = cast(
Backend, importlib.import_module(f"{__package__}.backends.{name}").factory()
Expand Down

0 comments on commit 18616ac

Please sign in to comment.