-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (35 loc) · 1.41 KB
/
main.py
File metadata and controls
49 lines (35 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import os
import flask
import functions_framework
from bugbug import generative_model_tool
from bugbug.tools.release_notes import ReleaseNotesCommitsSelector
from bugbug.utils import get_secret
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
os.environ["OPENAI_API_KEY"] = get_secret("OPENAI_API_KEY")
tool: ReleaseNotesCommitsSelector | None = None
DEFAULT_LLM_NAME = "openai"
DEFAULT_CHUNK_SIZE = 1000
@functions_framework.http
def handle_release_notes(request: flask.Request):
global tool
if request.method != "GET":
return "Only GET requests are allowed", 405
version = request.args.get("version")
if not version:
return "Missing 'version' query parameter", 400
if (
tool is None
or tool.llm_name != DEFAULT_LLM_NAME
or tool.chunk_size != DEFAULT_CHUNK_SIZE
):
logger.info("Initializing new ReleaseNotesCommitsSelector...")
llm = generative_model_tool.create_llm_from_request(DEFAULT_LLM_NAME, {})
tool = ReleaseNotesCommitsSelector(chunk_size=DEFAULT_CHUNK_SIZE, llm=llm)
tool.llm_name = DEFAULT_LLM_NAME
tool.chunk_size = DEFAULT_CHUNK_SIZE
notes = tool.get_final_release_notes_commits(version=version)
if not notes:
return {"commits": []}, 200, {"Content-Type": "application/json"}
return {"commits": notes}, 200, {"Content-Type": "application/json"}