Spaces:
Running
Running
File size: 1,419 Bytes
29e9295 a1b1b32 29e9295 4969145 29e9295 4969145 29e9295 |
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 |
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 |