Skip to content
Snippets Groups Projects
Unverified Commit 5fe2d519 authored by Huu Le's avatar Huu Le Committed by GitHub
Browse files

chore: Add Azure OpenAI model provider python (#110)

parent 09f1db3b
No related branches found
No related tags found
No related merge requests found
...@@ -5,16 +5,19 @@ from llama_index.core.settings import Settings ...@@ -5,16 +5,19 @@ from llama_index.core.settings import Settings
def init_settings(): def init_settings():
model_provider = os.getenv("MODEL_PROVIDER") model_provider = os.getenv("MODEL_PROVIDER")
if model_provider == "openai": match model_provider:
init_openai() case "openai":
elif model_provider == "ollama": init_openai()
init_ollama() case "ollama":
elif model_provider == "anthropic": init_ollama()
init_anthropic() case "anthropic":
elif model_provider == "gemini": init_anthropic()
init_gemini() case "gemini":
else: init_gemini()
raise ValueError(f"Invalid model provider: {model_provider}") case "azure-openai":
init_azure_openai()
case _:
raise ValueError(f"Invalid model provider: {model_provider}")
Settings.chunk_size = int(os.getenv("CHUNK_SIZE", "1024")) Settings.chunk_size = int(os.getenv("CHUNK_SIZE", "1024"))
Settings.chunk_overlap = int(os.getenv("CHUNK_OVERLAP", "20")) Settings.chunk_overlap = int(os.getenv("CHUNK_OVERLAP", "20"))
...@@ -52,6 +55,34 @@ def init_openai(): ...@@ -52,6 +55,34 @@ def init_openai():
Settings.embed_model = OpenAIEmbedding(**config) Settings.embed_model = OpenAIEmbedding(**config)
def init_azure_openai():
from llama_index.llms.azure_openai import AzureOpenAI
from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
from llama_index.core.constants import DEFAULT_TEMPERATURE
llm_deployment = os.getenv("AZURE_OPENAI_LLM_DEPLOYMENT")
embedding_deployment = os.getenv("AZURE_OPENAI_EMBEDDING_DEPLOYMENT")
max_tokens = os.getenv("LLM_MAX_TOKENS")
api_key = os.getenv("AZURE_OPENAI_API_KEY")
llm_config = {
"api_key": api_key,
"deployment_name": llm_deployment,
"model": os.getenv("MODEL"),
"temperature": float(os.getenv("LLM_TEMPERATURE", DEFAULT_TEMPERATURE)),
"max_tokens": int(max_tokens) if max_tokens is not None else None,
}
Settings.llm = AzureOpenAI(**llm_config)
dimensions = os.getenv("EMBEDDING_DIM")
embedding_config = {
"api_key": api_key,
"deployment_name": embedding_deployment,
"model": os.getenv("EMBEDDING_MODEL"),
"dimensions": int(dimensions) if dimensions is not None else None,
}
Settings.embed_model = AzureOpenAIEmbedding(**embedding_config)
def init_anthropic(): def init_anthropic():
from llama_index.llms.anthropic import Anthropic from llama_index.llms.anthropic import Anthropic
from llama_index.embeddings.huggingface import HuggingFaceEmbedding from llama_index.embeddings.huggingface import HuggingFaceEmbedding
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment