-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement DescribeImageUtililty utility
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import io | ||
from langchain_core.pydantic_v1 import BaseModel, Field | ||
from langchain_core.output_parsers import JsonOutputParser | ||
|
||
from ..models_toolkit import ModelsToolkit | ||
from ....models.handlers_input import Person, Context, Message | ||
|
||
|
||
class AudioInformation(BaseModel): | ||
# TODO: move this to prompt manager | ||
audio_description: str = Field(description="a short description of the audio") | ||
|
||
|
||
async def describe_audio(in_memory_image_stream: io.BytesIO) -> AudioInformation: | ||
# Encode in base64: | ||
parser = JsonOutputParser(pydantic_object=AudioInformation) | ||
|
||
# TODO: implement moderation | ||
|
||
return AudioInformation( | ||
audio_description="an audio" | ||
) | ||
|
||
|
||
class DescribeImageUtililty: | ||
def __init__( | ||
self, | ||
person: Person, | ||
context: Context, | ||
message: Message, | ||
models_toolkit: ModelsToolkit, | ||
): | ||
self.person = person | ||
self.context = context | ||
self.message = message | ||
self.models_toolkit = models_toolkit | ||
|
||
def run(self, in_memory_image_stream: io.BytesIO) -> AudioInformation: | ||
return describe_audio(in_memory_image_stream) |