Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(server): support cross-origin resource sharing (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
peakji authored Apr 18, 2023
1 parent 6c23300 commit 30b9325
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ENV SERVER_CONNECTION_LIMIT="1024"
ENV SERVER_CHANNEL_TIMEOUT="300"
ENV SERVER_MODEL_NAME=""
ENV SERVER_NO_PLAYGROUND="false"
ENV SERVER_CORS_ORIGINS="*"
ENV COMPLETION_MAX_PROMPT="4096"
ENV COMPLETION_MAX_TOKENS="4096"
ENV COMPLETION_MAX_N="5"
Expand Down
1 change: 1 addition & 0 deletions basaran/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def is_true(value):
SERVER_CHANNEL_TIMEOUT = int(os.getenv("SERVER_CHANNEL_TIMEOUT", "300"))
SERVER_MODEL_NAME = os.getenv("SERVER_MODEL_NAME", "") or MODEL
SERVER_NO_PLAYGROUND = is_true(os.getenv("SERVER_NO_PLAYGROUND", ""))
SERVER_CORS_ORIGINS = os.getenv("SERVER_CORS_ORIGINS", "*")

# Completion-related arguments:
COMPLETION_MAX_PROMPT = int(os.getenv("COMPLETION_MAX_PROMPT", "4096"))
Expand Down
5 changes: 5 additions & 0 deletions basaran/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import waitress
from flask import Flask, Response, abort, jsonify, render_template, request
from flask_cors import CORS

from . import is_true
from .choice import reduce_choice
Expand All @@ -28,6 +29,7 @@
from . import SERVER_CHANNEL_TIMEOUT
from . import SERVER_MODEL_NAME
from . import SERVER_NO_PLAYGROUND
from . import SERVER_CORS_ORIGINS
from . import COMPLETION_MAX_PROMPT
from . import COMPLETION_MAX_TOKENS
from . import COMPLETION_MAX_N
Expand All @@ -52,6 +54,9 @@
app.json.compact = True
app.url_map.strict_slashes = False

# Configure cross-origin resource sharing (CORS).
CORS(app, origins=SERVER_CORS_ORIGINS.split(","))


def parse_options(schema):
"""Parse options specified in query parameters and request body."""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bitsandbytes~=0.38.1
build>=0.10.0
coverage>=6.4.2
flake8>=3.7.9
flask-cors~=3.0.10
flask>=2.2.1
huggingface-hub~=0.13.4
jinja2>=3.1.2
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
packages=find_packages(),
include_package_data=True,
python_requires=">=3.8.0",
install_requires=["flask", "jinja2", "torch", "transformers", "waitress"],
install_requires=[
"flask-cors",
"flask",
"jinja2",
"torch",
"transformers",
"waitress",
],
keywords=["api", "huggingface", "nlp", "openai", "transformer"],
classifiers=[
"Development Status :: 4 - Beta",
Expand Down

0 comments on commit 30b9325

Please sign in to comment.