AWEsumCare-Demo / service_provider_config.py
Arjen Robben
llama index upgrade version migration and ollama chat backend
a1b1b32
raw
history blame
1.42 kB
from dotenv import load_dotenv
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.azure_openai import AzureOpenAI
from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
from schemas import ServiceProvider, ChatbotVersion
load_dotenv()
def get_service_provider_config(service_provider: ServiceProvider, model_name: str=ChatbotVersion.CHATGPT_35.value):
if service_provider == ServiceProvider.AZURE:
return get_azure_openai_config()
if service_provider == ServiceProvider.OPENAI:
llm = OpenAI(model=model_name)
embed_model = OpenAIEmbedding()
return llm, embed_model
def get_azure_openai_config():
api_key = "<api-key>"
azure_endpoint = "https://<your-resource-name>.openai.azure.com/"
api_version = "2023-07-01-preview"
llm = AzureOpenAI(
model="gpt-35-turbo-16k",
deployment_name="my-custom-llm",
api_key=api_key,
azure_endpoint=azure_endpoint,
api_version=api_version,
)
# You need to deploy your own embedding model as well as your own chat completion model
embed_model = AzureOpenAIEmbedding(
model="text-embedding-ada-002",
deployment_name="my-custom-embedding",
api_key=api_key,
azure_endpoint=azure_endpoint,
api_version=api_version,
)
return llm, embed_model