File size: 1,890 Bytes
6abb254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from storage import LocalStorage, Storage
from setting import Settings
from embedding import AzureOpenAITextAda002, Embedding, OpenAITextAda002
from index import Index, QDrantVectorStore
from model.user import User
from qdrant_client import QdrantClient

def initialize_di_for_test() -> tuple[Settings, Storage,Embedding,Index]:
    SETTINGS = Settings(_env_file='./test/.env.test')
    STORAGE = LocalStorage('./test/test_storage')
    if SETTINGS.embedding_use_azure:
        EMBEDDING = AzureOpenAITextAda002(
            api_base=SETTINGS.embedding_azure_openai_api_base,
            model_name=SETTINGS.embedding_azure_openai_model_name,
            api_key=SETTINGS.embedding_azure_openai_api_key,
        )
    else:
        EMBEDDING = OpenAITextAda002(SETTINGS.openai_api_key)
    INDEX = QDrantVectorStore(
        embedding=EMBEDDING,
        client= QdrantClient(
            url=SETTINGS.qdrant_url,
            api_key=SETTINGS.qdrant_api_key,),
        
        collection_name='test_collection',
    )
    INDEX.create_collection_if_not_exists()

    return SETTINGS, STORAGE, EMBEDDING, INDEX

def initialize_di_for_app() -> tuple[Settings, Storage,Embedding,Index]:
    SETTINGS = Settings(_env_file='.env')
    STORAGE = LocalStorage('.local_storage')
    if SETTINGS.embedding_use_azure:
        EMBEDDING = AzureOpenAITextAda002(
            api_base=SETTINGS.embedding_azure_openai_api_base,
            model_name=SETTINGS.embedding_azure_openai_model_name,
            api_key=SETTINGS.embedding_azure_openai_api_key,
        )
    else:
        EMBEDDING = OpenAITextAda002(SETTINGS.openai_api_key)
    INDEX = QDrantVectorStore(
        embedding=EMBEDDING,
        client= QdrantClient(
            url=SETTINGS.qdrant_url,
            api_key=SETTINGS.qdrant_api_key,),
        collection_name='collection',
    )


    return SETTINGS, STORAGE, EMBEDDING, INDEX