mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
aider: Moved the api_key
setting into the main function and pulled it from os.environ
.
# Aider chat conversation: USER: mov the `api_key` setting into main, and pull it from os.environ ASSISTANT: To move the `api_key` setting into the main function and pull it from `os.environ`, we need to modify the `aider/voice.py` file. Here are the changes: ```python aider/voice.py <<<<<<< HEAD def record_and_transcribe(): # Set your OpenAI API key openai.api_key = 'your-api-key' ======= import os def record_and_transcribe(api_key): >>>>>>> updated ``` ```python aider/voice.py <<<<<<< HEAD if __name__ == "__main__": print(record_and_transcribe()) ======= if __name__ == "__main__": api_key = os.getenv('OPENAI_API_KEY') if not api_key: raise ValueError("Please set the OPENAI_API_KEY environment variable.") print(record_and_transcribe(api_key)) >>>>>>> updated ``` These changes remove the hard-coded API key from the `record_and_transcribe` function and instead pass it as an argument. The API key is retrieved from the `OPENAI_API_KEY` environment variable in the main function. If the environment variable is not set, an error is raised.
This commit is contained in:
parent
c0f6cf6977
commit
c7d23f1b5a
1 changed files with 7 additions and 4 deletions
|
@ -4,9 +4,9 @@ import keyboard
|
|||
import openai
|
||||
import io
|
||||
|
||||
def record_and_transcribe():
|
||||
# Set your OpenAI API key
|
||||
openai.api_key = 'your-api-key'
|
||||
import os
|
||||
|
||||
def record_and_transcribe(api_key):
|
||||
|
||||
# Set the sample rate and duration for the recording
|
||||
sample_rate = 16000 # 16kHz
|
||||
|
@ -36,4 +36,7 @@ def record_and_transcribe():
|
|||
return response['choices'][0]['text']
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(record_and_transcribe())
|
||||
api_key = os.getenv('OPENAI_API_KEY')
|
||||
if not api_key:
|
||||
raise ValueError("Please set the OPENAI_API_KEY environment variable.")
|
||||
print(record_and_transcribe(api_key))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue