"Helpers for model client for integrating models and parsing the output."fromadalflow.core.typesimportEmbedderOutput,Embedding,Usage
[docs]defparse_embedding_response(api_response,)->EmbedderOutput:r"""Parse embedding model output from the API response to EmbedderOutput. Follows the OpenAI API response pattern. """# Assuming `api_response` has `.embeddings` and `.usage` attributes# and that `embeddings` is a list of objects that can be converted to `Embedding` dataclass# TODO: check if any embedding is missingembeddings=[Embedding(embedding=e.embedding,index=e.index)foreinapi_response.data]usage=Usage(prompt_tokens=api_response.usage.prompt_tokens,total_tokens=api_response.usage.total_tokens,)# Assuming `usage` is an object with a `count` attribute# Assuming the model name is part of the response or set statically heremodel=api_response.modelreturnEmbedderOutput(data=embeddings,model=model,usage=usage)