Skip to content

Commit d16ef65

Browse files
authored
Merge pull request #204 from microsoft/vNext-Dev
0.3-Gamma Release Candidate
2 parents 61b5e1c + 439f428 commit d16ef65

File tree

87 files changed

+2067
-552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2067
-552
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ARG USER_GID=$USER_UID
1212

1313
# Set up non-root user
1414
COPY ./scripts/non-root-user.sh /tmp/
15-
RUN bash /tmp/non-root-user.sh "${USERNAME}" "${USER_UID}" "${USER_GID}"
15+
RUN bash "/tmp/non-root-user.sh" "${USERNAME}" "${USER_UID}" "${USER_GID}"
1616

1717
# Set env for tracking that we're running in a devcontainer
1818
ENV DEVCONTAINER=true

.devcontainer/scripts/non-root-user.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ if [ "$(id -u)" -ne 0 ]; then
1313
exit 1
1414
fi
1515

16-
1716
# If in automatic mode, determine if a user already exists, if not use vscode
1817
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
1918
USERNAME=""
@@ -39,11 +38,11 @@ fi
3938
# Create or update a non-root user to match UID/GID.
4039
if id -u ${USERNAME} > /dev/null 2>&1; then
4140
# User exists, update if needed
42-
if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
41+
if [ "${USER_GID}" != "automatic" ] && [ "${USER_GID}" != "999" ] && [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
4342
groupmod --gid $USER_GID $USERNAME
4443
usermod --gid $USER_GID $USERNAME
4544
fi
46-
if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
45+
if [ "${USER_UID}" != "automatic" ] && [ "${USER_GID}" != "999" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
4746
usermod --uid $USER_UID $USERNAME
4847
fi
4948
else

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@
6363
"request": "attach",
6464
"port": 9091,
6565
"preLaunchTask": "func host start"
66+
},
67+
{
68+
"name": "Vite: Debug",
69+
"type": "msedge",
70+
"request": "launch",
71+
"url": "http://localhost:5000",
72+
"webRoot": "${workspaceFolder}/app/backend/static",
73+
"sourceMapPathOverrides": {
74+
"webpack:///src/*": "${webRoot}/*"
75+
},
76+
"skipFiles": ["<node_internals>/**", "**/node_modules/**"]
6677
}
6778
]
6879
}

README.md

Lines changed: 147 additions & 30 deletions
Large diffs are not rendered by default.

app/backend/app.py

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import logging
55
import mimetypes
66
import os
7+
import json
78
import urllib.parse
89
from datetime import datetime, timedelta
910

1011
import openai
1112
from approaches.chatreadretrieveread import ChatReadRetrieveReadApproach
1213
from azure.core.credentials import AzureKeyCredential
1314
from azure.identity import DefaultAzureCredential
15+
from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient
1416
from azure.search.documents import SearchClient
1517
from azure.storage.blob import (
1618
AccountSasPermissions,
@@ -33,10 +35,12 @@
3335
AZURE_SEARCH_SERVICE_KEY = os.environ.get("AZURE_SEARCH_SERVICE_KEY")
3436
AZURE_SEARCH_INDEX = os.environ.get("AZURE_SEARCH_INDEX") or "gptkbindex"
3537
AZURE_OPENAI_SERVICE = os.environ.get("AZURE_OPENAI_SERVICE") or "myopenai"
38+
AZURE_OPENAI_RESOURCE_GROUP = os.environ.get("AZURE_OPENAI_RESOURCE_GROUP") or ""
3639
AZURE_OPENAI_CHATGPT_DEPLOYMENT = (
3740
os.environ.get("AZURE_OPENAI_CHATGPT_DEPLOYMENT") or "chat"
3841
)
3942
AZURE_OPENAI_SERVICE_KEY = os.environ.get("AZURE_OPENAI_SERVICE_KEY")
43+
AZURE_SUBSCRIPTION_ID = os.environ.get("AZURE_SUBSCRIPTION_ID")
4044

4145
KB_FIELDS_CONTENT = os.environ.get("KB_FIELDS_CONTENT") or "merged_content"
4246
KB_FIELDS_CATEGORY = os.environ.get("KB_FIELDS_CATEGORY") or "category"
@@ -83,6 +87,15 @@
8387
)
8488
blob_container = blob_client.get_container_client(AZURE_BLOB_STORAGE_CONTAINER)
8589

90+
# Set up OpenAI management client
91+
openai_mgmt_client = CognitiveServicesManagementClient(
92+
credential=azure_credential,
93+
subscription_id=AZURE_SUBSCRIPTION_ID)
94+
95+
deployment = openai_mgmt_client.deployments.get(
96+
resource_group_name=AZURE_OPENAI_RESOURCE_GROUP,
97+
account_name=AZURE_OPENAI_SERVICE,
98+
deployment_name=AZURE_OPENAI_CHATGPT_DEPLOYMENT)
8699

87100
chat_approaches = {
88101
"rrr": ChatReadRetrieveReadApproach(
@@ -94,6 +107,8 @@
94107
KB_FIELDS_CONTENT,
95108
blob_client,
96109
QUERY_TERM_LANGUAGE,
110+
deployment.properties.model.name,
111+
deployment.properties.model.version
97112
)
98113
}
99114

@@ -105,33 +120,6 @@
105120
def static_file(path):
106121
return app.send_static_file(path)
107122

108-
109-
# Return blob path with SAS token for citation access
110-
@app.route("/content/<path:path>")
111-
def content_file(path):
112-
blob = blob_container.get_blob_client(path).download_blob()
113-
mime_type = blob.properties["content_settings"]["content_type"]
114-
file_extension = blob.properties["name"].split(".")[-1:]
115-
if mime_type == "application/octet-stream":
116-
mime_type = mimetypes.guess_type(path)[0] or "application/octet-stream"
117-
if mime_type == "text/plain" and file_extension[0] in ["htm", "html"]:
118-
mime_type = "text/html"
119-
print(
120-
"Using mime type: "
121-
+ mime_type
122-
+ "for file with extension: "
123-
+ file_extension[0]
124-
)
125-
return (
126-
blob.readall(),
127-
200,
128-
{
129-
"Content-Type": mime_type,
130-
"Content-Disposition": f"inline; filename={urllib.parse.quote(path, safe='')}",
131-
},
132-
)
133-
134-
135123
@app.route("/chat", methods=["POST"])
136124
def chat():
137125
approach = request.json["approach"]
@@ -156,7 +144,6 @@ def chat():
156144
logging.exception("Exception in /chat")
157145
return jsonify({"error": str(e)}), 500
158146

159-
160147
@app.route("/getblobclienturl")
161148
def get_blob_client_url():
162149
sas_token = generate_account_sas(
@@ -177,11 +164,6 @@ def get_blob_client_url():
177164
)
178165
return jsonify({"url": f"{blob_client.url}?{sas_token}"})
179166

180-
181-
if __name__ == "__main__":
182-
app.run()
183-
184-
185167
@app.route("/getalluploadstatus", methods=["POST"])
186168
def get_all_upload_status():
187169
timeframe = request.json["timeframe"]
@@ -192,3 +174,33 @@ def get_all_upload_status():
192174
logging.exception("Exception in /getalluploadstatus")
193175
return jsonify({"error": str(e)}), 500
194176
return jsonify(results)
177+
178+
# Return AZURE_OPENAI_CHATGPT_DEPLOYMENT
179+
@app.route("/getInfoData")
180+
def get_info_data():
181+
response = jsonify(
182+
{
183+
"AZURE_OPENAI_CHATGPT_DEPLOYMENT": f"{AZURE_OPENAI_CHATGPT_DEPLOYMENT}",
184+
"AZURE_OPENAI_MODEL_NAME": f"{deployment.properties.model.name}",
185+
"AZURE_OPENAI_MODEL_VERSION": f"{deployment.properties.model.version}",
186+
"AZURE_OPENAI_SERVICE": f"{AZURE_OPENAI_SERVICE}",
187+
"AZURE_SEARCH_SERVICE": f"{AZURE_SEARCH_SERVICE}",
188+
"AZURE_SEARCH_INDEX": f"{AZURE_SEARCH_INDEX}",
189+
"TARGET_LANGUAGE": f"{QUERY_TERM_LANGUAGE}"
190+
})
191+
return response
192+
193+
@app.route("/getcitation", methods=["POST"])
194+
def get_citation():
195+
citation = urllib.parse.unquote(request.json["citation"])
196+
try:
197+
blob = blob_container.get_blob_client(citation).download_blob()
198+
decoded_text = blob.readall().decode()
199+
results = jsonify(json.loads(decoded_text))
200+
except Exception as e:
201+
logging.exception("Exception in /getalluploadstatus")
202+
return jsonify({"error": str(e)}), 500
203+
return jsonify(results.json)
204+
205+
if __name__ == "__main__":
206+
app.run()

0 commit comments

Comments
 (0)