bossjones / goob_ai

MIT License
1 stars 0 forks source link

for OpenAIEmbeddings, set a default model setting and dimensions inside of aio_settings.py #55

Open bossjones opened 2 months ago

bossjones commented 2 months ago

eg: https://github.com/vintoniuk/anadeabot/blob/945fb9f998eaf2cf609f9d9f61c467cf05c865ba/anadeabot/database.py#L23

embeddings = OpenAIEmbeddings(
    model=settings.embedding_model,
    api_key=settings.OPENAI_API_KEY,
    dimensions=settings.dimensionality
)

faq_vectorstore = PGVector(
    embeddings=embeddings,
    connection=settings.POSTGRES_URI,
    embedding_length=settings.dimensionality,
    collection_name='faq',
    use_jsonb=True,
)

grounding_vectorstore = PGVector(
    embeddings=embeddings,
    connection=settings.POSTGRES_URI,
    embedding_length=settings.dimensionality,
    collection_name='grounding',
    use_jsonb=True,
)
bossjones commented 2 months ago

https://github.com/vintoniuk/anadeabot/blob/945fb9f998eaf2cf609f9d9f61c467cf05c865ba/anadeabot/settings.py#L7

another example:

from typing import Optional
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    model: str = 'gpt-3.5-turbo'
    embedding_model: str = 'text-embedding-3-large'
    dimensionality: int = 1024

    API_ID: Optional[str] = None
    API_HASH: Optional[str] = None
    BOT_TOKEN: Optional[str] = None

    OPENAI_API_KEY: str

    POSTGRES_URI: str

settings = Settings(_env_file='.env')
bossjones commented 2 months ago

https://api.python.langchain.com/en/latest/openai/embeddings/langchain_openai.embeddings.base.OpenAIEmbeddings.html

from langchain_openai import OpenAIEmbeddings

embed = OpenAIEmbeddings(
    model="text-embedding-3-large"
    # With the `text-embedding-3` class
    # of models, you can specify the size
    # of the embeddings you want returned.
    # dimensions=1024
)