You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having implemented this in multiple languages and even Elixir HTTP frameworks, i'd like to add it to langchain here as it would streamline this for some other folks too.
The question/discussion i'd like to have is where to put it and how to name the module.
The shortest version of this function i've hacked together is this here, which is used to transport browser/user-audio wav to the backend.
defmodulePetalProWeb.LangChainHelpersdo@moduledocfalsealiasHTTPoison.Response@openai_transcription_url"https://api.openai.com/v1/audio/transcriptions"defpget_authorization_headersdoopenai_api_key=Application.get_env(:langchain,:openai_key)openai_org_id=Application.get_env(:langchain,:openai_org_id)openai_proj_id=Application.get_env(:langchain,:openai_proj_id)headers=[{"Authorization","Bearer #{openai_api_key}"},{"Openai-Organization",openai_org_id}]ifopenai_proj_idin[nil,""],do: headers,else:headers++[{"Openai-Project",openai_proj_id}]end@doc""" This function illustrates how one can do plain OpenAI requests relatively simple to do things like transcription with whisper, which langchain does not provide us. Only takes wav from the browser right now. """defopenai_wav_transcription(file_path,params\\[])dobody_params=Enum.map(params,fn{k,v}->{Atom.to_string(k),v}end)body={:multipart,[{:file,file_path,{"form-data",[{:name,"file"},{:filename,Path.basename(file_path)<>".wav"}]},[]}]++body_params}caseHTTPoison.post(@openai_transcription_url,body,get_authorization_headers())do{:ok,%Response{status_code: 200,body: {:ok,body}}}->res=Map.new(body,fn{k,v}->{String.to_atom(k),v}end){:ok,res}{:ok,%Response{status_code: 200,body: body}}->{:ok,body}{:ok,%Response{body: {:ok,body}}}->{:error,body}{:ok,%Response{body: {:error,body}}}->{:error,body}# html error responses{:ok,%Response{status_code: status_code,body: body}}->{:error,%{status_code: status_code,body: body}}{:error,%HTTPoison.Error{reason: reason}}->{:error,reason}endendend
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Having implemented this in multiple languages and even Elixir HTTP frameworks, i'd like to add it to langchain here as it would streamline this for some other folks too.
The question/discussion i'd like to have is where to put it and how to name the module.
The shortest version of this function i've hacked together is this here, which is used to transport browser/user-audio wav to the backend.
Beta Was this translation helpful? Give feedback.
All reactions