File tree Expand file tree Collapse file tree 8 files changed +550
-19
lines changed Expand file tree Collapse file tree 8 files changed +550
-19
lines changed Original file line number Diff line number Diff line change 1313 rev : 24.2.0
1414 hooks :
1515 - id : black
16+ exclude : ' client/.*'
Original file line number Diff line number Diff line change @@ -30,9 +30,15 @@ format: ## format code
3030 poetry run isort .
3131 poetry run black . --verbose
3232
33+ .PHONY : fix
34+ fix : format # # apply auto-fixes
35+ poetry run ruff check --fix
36+
3337.PHONY : lint
3438lint : # # lint
35- poetry run ruff check .
39+ poetry run ruff check . \
40+ --exclude client \
41+ --respect-gitignore
3642 shellcheck scripts/* .sh
3743
3844.PHONY : test
@@ -121,3 +127,14 @@ azure-functions-functionapp-deploy: ## deploy Azure Functions App
121127.PHONY : generate-openapi-spec
122128generate-openapi-spec : # # generate OpenAPI spec
123129 poetry run python main.py generate-openapi-spec
130+
131+ .PHONY : generate-openapi-client
132+ generate-openapi-client : # # generate OpenAPI client
133+ @kiota generate \
134+ --language Python \
135+ --class-name ApiClient \
136+ --namespace-name client \
137+ --openapi ./specs/openapi.json \
138+ --output ./client
139+ @echo " Get the list of dependencies"
140+ @kiota info -d ./specs/openapi.json --language Python
Original file line number Diff line number Diff line change 11from fastapi import FastAPI
2+ from fastapi .openapi .utils import get_openapi
23
34from backend .routers import azure_openai as azure_openai_router
45from backend .routers import document_intelligence as document_intelligence_router
910
1011app .include_router (azure_openai_router .router )
1112app .include_router (document_intelligence_router .router )
13+
14+
15+ def custom_openapi ():
16+ if app .openapi_schema :
17+ return app .openapi_schema
18+ openapi_schema = get_openapi (
19+ title = "Azure AI Services Solutions" ,
20+ version = "0.0.1" ,
21+ description = "This contains a collection of solutions that leverage Azure AI services." ,
22+ routes = app .routes ,
23+ servers = [
24+ {
25+ "url" : "http://localhost:8000" ,
26+ }
27+ ],
28+ )
29+ openapi_schema ["info" ]["x-logo" ] = {
30+ "url" : "https://news.microsoft.com/wp-content/uploads/prod/2022/05/Microsoft-logo_rgb_c-gray-1024x459.png"
31+ }
32+ openapi_schema ["openapi" ] = "3.0.0"
33+ app .openapi_schema = openapi_schema
34+ return app .openapi_schema
35+
36+
37+ app .openapi_version = "3.0.0" # to use Kiota, downgrade to 3.0.0 (ref. https://github.com/microsoft/kiota/issues/3914)
38+ app .openapi = custom_openapi
Original file line number Diff line number Diff line change 33## Common
44
55- [ Typer] ( https://typer.tiangolo.com/#installation )
6+ - [ Kiota > Generate tailored Python and PHP API clients for any API with Kiota] ( https://devblogs.microsoft.com/microsoft365dev/generate-tailored-python-and-php-api-clients-for-any-api-with-kiota/ )
67
78## Backend
89
Original file line number Diff line number Diff line change 44
55import streamlit as st
66
7- from frontend .solutions .utilities import http_get , http_post
7+ from frontend .solutions .utilities import http_get
88
99logger = logging .getLogger (__name__ )
1010
1111
12+ async def chat_completions_post (
13+ backend_url : str ,
14+ prompt : str ,
15+ ):
16+ from kiota_abstractions .authentication .anonymous_authentication_provider import AnonymousAuthenticationProvider
17+ from kiota_http .httpx_request_adapter import HttpxRequestAdapter
18+
19+ from client .api_client import ApiClient
20+ from client .models .chat_completion_request import ChatCompletionRequest
21+
22+ auth_provider = AnonymousAuthenticationProvider ()
23+ request_adapter = HttpxRequestAdapter (
24+ authentication_provider = auth_provider ,
25+ base_url = backend_url ,
26+ )
27+ client = ApiClient (request_adapter )
28+
29+ response = await client .azure_openai .chat_completions .post (
30+ ChatCompletionRequest (
31+ content = prompt ,
32+ stream = False ,
33+ ),
34+ )
35+ return response .content
36+
37+
1238def start (
1339 backend_url : str ,
1440 log_level : int ,
@@ -42,12 +68,9 @@ def start(
4268 try :
4369 with st .spinner ("Calling API..." ):
4470 response = asyncio .run (
45- http_post (
46- url = urljoin (base = backend_url , url = "/azure_openai/chat_completions/" ),
47- data = {
48- "content" : prompt ,
49- "stream" : False ,
50- },
71+ chat_completions_post (
72+ backend_url = backend_url ,
73+ prompt = prompt ,
5174 )
5275 )
5376 st .write (response )
You can’t perform that action at this time.
0 commit comments