chore: import upstream snapshot with attribution
Lint and Test / lint_test (3.11) (push) Has been cancelled
Lint and Test / lint_test (3.10) (push) Has been cancelled
Lint and Test / lint_test (3.12) (push) Has been cancelled
Publish to PyPI and release / Build distribution (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Publish to PyPI and release / Publish to PyPI (push) Has been cancelled
Publish to PyPI and release / Make release (push) Has been cancelled
Lint and Test / lint_test (3.11) (push) Has been cancelled
Lint and Test / lint_test (3.10) (push) Has been cancelled
Lint and Test / lint_test (3.12) (push) Has been cancelled
Publish to PyPI and release / Build distribution (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Publish to PyPI and release / Publish to PyPI (push) Has been cancelled
Publish to PyPI and release / Make release (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
import typer
|
||||
from click import UsageError
|
||||
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk
|
||||
from openai.types.chat.chat_completion_chunk import Choice as StreamChoice
|
||||
from openai.types.chat.chat_completion_chunk import ChoiceDelta
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from sgpt import main
|
||||
from sgpt.config import cfg
|
||||
|
||||
runner = CliRunner()
|
||||
app = typer.Typer()
|
||||
app.command()(main)
|
||||
|
||||
|
||||
def assert_usage_error(result, message=None):
|
||||
assert result.exit_code == 1, result
|
||||
assert isinstance(result.exception, UsageError), result.exception
|
||||
if message is not None:
|
||||
assert message in str(result.exception), result.exception
|
||||
|
||||
|
||||
def mock_comp(tokens_string):
|
||||
return [
|
||||
ChatCompletionChunk(
|
||||
id="foo",
|
||||
model=cfg.get("DEFAULT_MODEL"),
|
||||
object="chat.completion.chunk",
|
||||
choices=[
|
||||
StreamChoice(
|
||||
index=0,
|
||||
finish_reason=None,
|
||||
delta=ChoiceDelta(content=token, role="assistant"),
|
||||
),
|
||||
],
|
||||
created=int(datetime.now().timestamp()),
|
||||
)
|
||||
for token in tokens_string
|
||||
]
|
||||
|
||||
|
||||
def cmd_args(**kwargs: Any) -> list[str]:
|
||||
prompt = kwargs.pop("prompt", "")
|
||||
arguments = [prompt]
|
||||
for key, value in kwargs.items():
|
||||
arguments.append(key)
|
||||
if isinstance(value, bool):
|
||||
continue
|
||||
arguments.append(value)
|
||||
arguments.append("--no-cache")
|
||||
arguments.append("--no-functions")
|
||||
return arguments
|
||||
|
||||
|
||||
def comp_args(role, prompt, **kwargs):
|
||||
return {
|
||||
"messages": [
|
||||
{"role": "system", "content": role.role},
|
||||
{"role": "user", "content": prompt},
|
||||
],
|
||||
"model": cfg.get("DEFAULT_MODEL"),
|
||||
"temperature": 0.0,
|
||||
"top_p": 1.0,
|
||||
"stream": True,
|
||||
**kwargs,
|
||||
}
|
||||
Reference in New Issue
Block a user