Skip to content

Commit c1e3612

Browse files
committed
chore: reorganize imports and improve function documentation in main.py
1 parent be00062 commit c1e3612

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

automotive_ai/main.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@
33
"""
44

55
import os
6+
67
import serial
8+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
9+
from dotenv import load_dotenv
10+
from openai import AzureOpenAI, OpenAI
711

8-
from _utils._commands import voice_commands
9-
from automotive_ai._api._openai._gpt_chat import (
10-
chat_gpt,
11-
load_conversation_history,
12-
save_conversation_history,
13-
summarize_conversation_history_direct,
14-
extract_vin,
15-
)
1612
from automotive_ai._api._msal._graph_api import (
1713
create_new_appointment,
1814
get_emails,
1915
get_next_appointment,
2016
send_email_with_attachments,
2117
)
22-
from automotive_ai._utils._commands import ELM327_COMMANDS
23-
from _utils._serial_commands import (
24-
send_command,
18+
from automotive_ai._api._nhtsa._vin_decoder import decode_vin
19+
from automotive_ai._api._openai._gpt_chat import (
20+
chat_gpt,
21+
extract_vin,
22+
load_conversation_history,
23+
save_conversation_history,
24+
summarize_conversation_history_direct,
25+
)
26+
from automotive_ai._audio._audio_output import tts_output
27+
from automotive_ai._utils._commands import ELM327_COMMANDS, voice_commands
28+
from automotive_ai._utils._serial_commands import (
29+
parse_vin_response,
2530
process_data,
31+
send_command,
2632
send_diagnostic_report,
27-
parse_vin_response,
2833
)
29-
from automotive_ai._api._nhtsa._vin_decoder import decode_vin
30-
from automotive_ai._voice._voice_recognition import recognize_speech, recognize_command
31-
from _audio._audio_output import tts_output
32-
from openai import OpenAI, AzureOpenAI
33-
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
34-
from dotenv import load_dotenv
34+
from automotive_ai._voice._voice_recognition import recognize_command, recognize_speech
3535

36-
# Load variables from .env file
3736
load_dotenv()
3837

3938
openai_client = None
@@ -59,7 +58,7 @@ def configure_openai():
5958
Configures the OpenAI client based on environment variables.
6059
6160
This function sets up the OpenAI client using different configurations depending on
62-
the environment variables provided. It supports Azure OpenAI endpoints, and OpenAI API keys.
61+
the environment variables provided. It supports Azure OpenAI, and OpenAI endpoints.
6362
6463
Raises:
6564
ValueError: If required environment variables for Azure OpenAI are missing or
@@ -68,7 +67,7 @@ def configure_openai():
6867
Environment Variables:
6968
AZURE_OPENAI_ENDPOINT: The Azure endpoint for OpenAI.
7069
AZURE_OPENAI_API_KEY: The API key for Azure OpenAI.
71-
AZURE_OPENAI_CHATGPT_DEPLOYMENT_NAME: The deployment name for Azure OpenAI ChatGPT.
70+
AZURE_OPENAI_CHATGPT_DEPLOYMENT_NAME: Deployment name for Azure OpenAI ChatGPT.
7271
AZURE_OPENAI_API_VERSION: The API version for Azure OpenAI.
7372
OPENAICOM_API_KEY: The API key for OpenAI.
7473
OPENAICOM_MODEL: The model name for OpenAI (default is "gpt-4o-mini").
@@ -91,7 +90,7 @@ def configure_openai():
9190
"AZURE_OPENAI_CHATGPT_DEPLOYMENT_NAME is required for Azure OpenAI"
9291
)
9392
openai_client = AzureOpenAI(
94-
api_version=os.getenv("AZURE_OPENAI_API_VERSION") or "2024-10-21",
93+
api_version=os.getenv("OPENAI_API_VERSION") or "2024-10-21",
9594
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
9695
**client_args,
9796
)
@@ -146,7 +145,7 @@ def main_conversation(args, user_object_id=None, use_elm327=False):
146145

147146
while True:
148147
if not standby_mode:
149-
print("\nPlease say a command:")
148+
print("\nSpeech Recognition Active:")
150149
text = recognize_speech()
151150
if text:
152151
lower_text = text.lower()
@@ -288,7 +287,8 @@ def main_conversation(args, user_object_id=None, use_elm327=False):
288287
print(f"{next_appointment}")
289288

290289
elif cmd == "create_appointment":
291-
create_new_appointment(recognize_speech)
290+
appointment_input = recognize_speech()
291+
create_new_appointment(appointment_input, tts_output)
292292
print("New appointment created.")
293293

294294
elif cmd == "check_outlook_email":

0 commit comments

Comments
 (0)