Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Create Llama
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Create Llama
Commits
5fe2d519
Unverified
Commit
5fe2d519
authored
9 months ago
by
Huu Le
Committed by
GitHub
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
chore: Add Azure OpenAI model provider python (#110)
parent
09f1db3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
templates/types/streaming/fastapi/app/settings.py
+41
-10
41 additions, 10 deletions
templates/types/streaming/fastapi/app/settings.py
with
41 additions
and
10 deletions
templates/types/streaming/fastapi/app/settings.py
+
41
−
10
View file @
5fe2d519
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment