fromlangchain_openaiimportChatOpenAIimportosfromconfig.secretimportsecretimportbase64os.environ["OPENAI_API_KEY"]="MyAPIKey"model=ChatOpenAI(model="오디오 다루기 가능한 모델")withopen("data/audio/sample/hello_im_rocky.wav","rb")asf:base64_data=base64.b64encode(f.read()).decode()message={"role":"user","content":[{"type":"text","text":"오디오에서 자기소개를 하는 사람의 이름은?"},{"type":"audio","base64":base64_data,"mime_type":"audio/wav"},]}model.invoke([message])
fromopenaiimportOpenAIfromlangchain_openaiimportChatOpenAIimportosfromconfig.secretimportsecretos.environ["OPENAI_API_KEY"]="MyAPIKey"model=ChatOpenAI(model="gpt-4o-mini")client=OpenAI(api_key=secret["apikey"]["openai"])withopen("data/audio/sample/hello_im_rocky.wav","rb")asf:transcript=client.audio.transcriptions.create(model="whisper-1",file=f,response_format="text")message={"role":"user","content":[{"type":"text","text":"주어진 transcription에서 자기소개를 하는 사람의 이름은?"},{"type":"text","text":transcript},]}model.invoke([message])
1
2
# 답변
자기소개하는사람의이름은로키입니다.
(3) LLM 제공자 관리 File ID 로 오디오 보내기
LLM 제공자(예: OpenAI, Anthropic)가 내부적으로 관리하는 파일의 고유 ID를 참조하는 옵션
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fromlangchain_openaiimportChatOpenAIimportosos.environ["OPENAI_API_KEY"]="MyAPIKey"model=ChatOpenAI(model="gpt-4o")# From provider-managed File ID
message={"role":"user","content":[{"type":"text","text":"Describe the content of this audio."},{"type":"audio","file_id":"file-abc123"},]}model.invoke([message])
Comments