Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
haruiz committed May 9, 2024
1 parent 7db73ba commit fce835e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
Binary file modified src/.DS_Store
Binary file not shown.
51 changes: 20 additions & 31 deletions src/geminiplayground/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def check_api_key():

@cli.command()
def ui(
host: str = "127.0.0.1",
host: str = "0.0.0.0",
port: int = 8081,
workers: int = os.cpu_count() * 2 + 1,
reload: Annotated[bool, typer.Option("--reload")] = True,
Expand All @@ -32,49 +32,38 @@ def ui(
"""
Launch the web app
"""
import uvicorn
check_api_key()
import uvicorn

run_cmd = (
f"gunicorn "
f"geminiplayground.web.app:app "
f"-w {workers} "
f"--bind {host}:{port} "
f"--timeout {timeout} "
f"-k uvicorn.workers.UvicornWorker ")

if reload:
run_cmd += "--reload"

os.system(run_cmd)
uvicorn.run(
"geminiplayground.web.app:app",
host=host,
port=port,
workers=workers,
reload=reload,
)


@cli.command()
def api(
host: str = "127.0.0.1",
host: str = "0.0.0.0",
port: int = 8081,
workers: int = os.cpu_count() * 2 + 1,
reload: Annotated[bool, typer.Option("--reload")] = True,
timeout: int = 12600,

reload: Annotated[bool, typer.Option("--reload")] = True
):
"""
Launch the API
"""
check_api_key()

run_cmd = (
f"gunicorn "
f"geminiplayground.web.api:api "
f"-w {workers} "
f"--bind {host}:{port} "
f"--timeout {timeout} "
f"-k uvicorn.workers.UvicornWorker ")

if reload:
run_cmd += "--reload"
import uvicorn

os.system(run_cmd)
check_api_key()
uvicorn.run(
"geminiplayground.web.api:api",
host=host,
port=port,
workers=workers,
reload=reload,
)


def run():
Expand Down
2 changes: 1 addition & 1 deletion src/geminiplayground/core/gemini_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def stream(self, model: str, prompt: GenerateRequest | list | str | dict, **kwar
response = (
self.genai_service.models()
.streamGenerateContent(
model=model, body=generate_request.dict(exclude_none=True, by_alias=True) # , alt="json"
model=model, body=generate_request.dict(exclude_none=True, by_alias=True), alt="json"
).
execute()
)
Expand Down

0 comments on commit fce835e

Please sign in to comment.