-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add audio model classes and clean up unused function (#46)
* feat: enhance LLM response handling and add client function - Updated `get_litellm_response` to include a default method for OpenAI style requests. - Introduced a new function `get_llm_client` for LLM client initialization, currently a placeholder. * feat: add audio model classes and clean up unused function - Added `AudioModel` and `SpeechModel` to the `__init__.py` for better model organization. - Removed the unused `get_llm_client` function from `utils.py` to streamline the codebase. * chore: code format * docs: update README with environment setup instructions and remove setup_guide.md - Added instructions for setting environment variables `OPENAI_API_KEY`, `NERIF_DEFAULT_LLM_MODEL`, and `NERIF_DEFAULT_EMBEDDING_MODEL` in README.md. - Provided an example of how to export these variables in a bash environment. - Removed the outdated setup_guide.md file to streamline documentation.
- Loading branch information
Showing
5 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from .audio_model import AudioModel, SpeechModel | ||
from .model import LogitsChatModel, SimpleChatModel, SimpleEmbeddingModel, VisionModel | ||
|
||
__all__ = [ | ||
"LogitsChatModel", | ||
"SimpleChatModel", | ||
"SimpleEmbeddingModel", | ||
"VisionModel", | ||
"AudioModel", | ||
"SpeechModel", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import base64 | ||
from pathlib import Path | ||
from typing import Any, List, Optional | ||
|
||
from openai import OpenAI | ||
|
||
from ..utils import ( | ||
LOGGER, | ||
NERIF_DEFAULT_LLM_MODEL, | ||
OPENAI_MODEL, | ||
MessageType, | ||
NerifTokenCounter, | ||
get_litellm_embedding, | ||
get_litellm_response, | ||
get_ollama_response, | ||
get_sllm_response, | ||
get_vllm_response, | ||
) | ||
|
||
|
||
class AudioModel: | ||
""" | ||
A simple agent for audio tasks. (audio transcription, speech to text) | ||
""" | ||
|
||
def __init__(self): | ||
self.client = OpenAI() | ||
|
||
def transcribe(self, file: Path): | ||
with open(file, "rb") as audio_file: | ||
transcription = self.client.audio.transcriptions.create( | ||
model="whisper-1", | ||
file=audio_file, | ||
) | ||
return transcription | ||
|
||
|
||
class SpeechModel: | ||
""" | ||
A simple agent for speech tasks. (speech model, text to speech) | ||
""" | ||
|
||
def __init__(self): | ||
self.client = OpenAI() | ||
|
||
def text_to_speech(self, text: str, voice: str = "alloy"): | ||
response = self.client.audio.speech.create( | ||
model="tts-1", | ||
input=text, | ||
voice=voice, | ||
) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters