chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# Semantic Kernel Settings
|
||||
|
||||
## AI Service Settings used across SK
|
||||
|
||||
| Provider | Service | Constructor Settings | Environment Variable | Required? | Settings Class |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| OpenAI | [OpenAIChatCompletion](../../../semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_CHAT_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | [OpenAISettings](../../../semantic_kernel/connectors/ai/open_ai/settings/open_ai_settings.py) |
|
||||
| | [OpenAITextCompletion](../../../semantic_kernel/connectors/ai/open_ai/services/open_ai_text_completion.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_TEXT_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | |
|
||||
| | [OpenAITextEmbedding](../../../semantic_kernel/connectors/ai/open_ai/services/open_ai_text_embedding.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_EMBEDDING_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | |
|
||||
| | [OpenAITextToImage](../../../semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_TEXT_TO_IMAGE_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | |
|
||||
| | [OpenAITextToAudio](../../../semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_audio.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_TEXT_TO_AUDIO_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | |
|
||||
| | [OpenAIAudioToText](../../../semantic_kernel/connectors/ai/open_ai/services/open_ai_audio_to_text.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_AUDIO_TO_TEXT_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | |
|
||||
| Azure OpenAI | [AzureChatCompletion](../../../semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py) | deployment_name, <br> api_key, <br> endpoint, <br> api_version, <br> base_url | AZURE_OPENAI_CHAT_DEPLOYMENT_NAME, <br> AZURE_OPENAI_API_KEY, <br> AZURE_OPENAI_ENDPOINT, <br> AZURE_OPENAI_API_VERSION, <br> AZURE_OPENAI_BASE_URL | Yes, <br> No, <br> Yes, <br> Yes, <br> Yes | [AzureOpenAISettings](../../../semantic_kernel/connectors/ai/open_ai/settings/azure_open_ai_settings.py) |
|
||||
| | [AzureTextEmbedding](../../../semantic_kernel/connectors/ai/open_ai/services/azure_text_embedding.py) | deployment_name, <br> api_key, <br> endpoint, <br> api_version, <br> base_url | AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME, <br> AZURE_OPENAI_API_KEY, <br> AZURE_OPENAI_ENDPOINT, <br> AZURE_OPENAI_API_VERSION, <br> AZURE_OPENAI_BASE_URL | Yes, <br> No, <br> Yes, <br> Yes, <br> Yes | |
|
||||
| | [AzureTextToImage](../../../semantic_kernel/connectors/ai/open_ai/services/azure_text_to_image.py) | deployment_name, <br> api_key, <br> endpoint | AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME, <br> AZURE_OPENAI_API_KEY, <br> AZURE_OPENAI_ENDPOINT | Yes, <br> No, <br> Yes | |
|
||||
| | [AzureTextToAudio](../../../semantic_kernel/connectors/ai/open_ai/services/azure_text_to_audio.py) | deployment_name, <br> api_key, <br> endpoint | AZURE_OPENAI_TEXT_TO_AUDIO_DEPLOYMENT_NAME, <br> AZURE_OPENAI_API_KEY, <br> AZURE_OPENAI_ENDPOINT | Yes, <br> No, <br> Yes | |
|
||||
| | [AzureAudioToText](../../../semantic_kernel/connectors/ai/open_ai/services/azure_audio_to_text.py) | deployment_name, <br> api_key, <br> endpoint | AZURE_OPENAI_AUDIO_TO_TEXT_DEPLOYMENT_NAME, <br> AZURE_OPENAI_API_KEY, <br> AZURE_OPENAI_ENDPOINT | Yes, <br> No, <br> Yes | |
|
||||
| Azure AI Inference | [AzureAIInferenceChatCompletion](../../../semantic_kernel/connectors/ai/azure_ai_inference/services/azure_ai_inference_chat_completion.py) | ai_model_id, <br> api_key, <br> endpoint | N/A, <br> AZURE_AI_INFERENCE_API_KEY, <br> AZURE_AI_INFERENCE_ENDPOINT | Yes, <br> No, <br> Yes | [AzureAIInferenceSettings](../../../semantic_kernel/connectors/ai/azure_ai_inference/azure_ai_inference_settings.py) |
|
||||
| | [AzureAIInferenceTextEmbedding](../../../semantic_kernel/connectors/ai/azure_ai_inference/services/azure_ai_inference_text_embedding.py) | ai_model_id, <br> api_key, <br> endpoint | N/A, <br> AZURE_AI_INFERENCE_API_KEY, <br> AZURE_AI_INFERENCE_ENDPOINT | Yes, <br> No, <br> Yes | |
|
||||
| Anthropic | [AnthropicChatCompletion](../../../semantic_kernel/connectors/ai/anthropic/services/anthropic_chat_completion.py) | api_key, <br> ai_model_id | ANTHROPIC_API_KEY, <br> ANTHROPIC_CHAT_MODEL_ID | Yes, <br> Yes | [AnthropicSettings](../../../semantic_kernel/connectors/ai/anthropic/settings/anthropic_settings.py) |
|
||||
| Bedrock | [BedrockChatCompletion](../../../semantic_kernel/connectors/ai/bedrock/services/bedrock_chat_completion.py) | model_id | BEDROCK_CHAT_MODEL_ID | Yes | [BedrockSettings](../../../semantic_kernel/connectors/ai/bedrock/bedrock_settings.py) |
|
||||
| | [BedrockTextCompletion](../../../semantic_kernel/connectors/ai/bedrock/services/bedrock_text_completion.py) | model_id | BEDROCK_TEXT_MODEL_ID | Yes | |
|
||||
| | [BedrockTextEmbedding](../../../semantic_kernel/connectors/ai/bedrock/services/bedrock_text_embedding.py) | model_id | BEDROCK_EMBEDDING_MODEL_ID | Yes | |
|
||||
| Google AI | [GoogleAIChatCompletion](../../../semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py) | gemini_model_id, <br> api_key | GOOGLE_AI_GEMINI_MODEL_ID, <br> GOOGLE_AI_API_KEY | Yes, <br> Yes | [GoogleAISettings](../../../semantic_kernel/connectors/ai/google/google_ai/google_ai_settings.py) |
|
||||
| | [GoogleAITextCompletion](../../../semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py) | gemini_model_id, <br> api_key | GOOGLE_AI_GEMINI_MODEL_ID, <br> GOOGLE_AI_API_KEY | Yes, <br> Yes | |
|
||||
| | [GoogleAITextEmbedding](../../../semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py) | embedding_model_id, <br> api_key | GOOGLE_AI_EMBEDDING_MODEL_ID, <br> GOOGLE_AI_API_KEY | Yes, <br> Yes | |
|
||||
| Vertex AI | [GoogleAIChatCompletion](../../../semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py) | project_id, <br> region, <br> gemini_model_id | GOOGLE_AI_CLOUD_PROJECT_ID, <br> GOOGLE_AI_CLOUD_REGION, <br> GOOGLE_AI_GEMINI_MODEL_ID, <br> GOOGLE_AI_USE_VERTEXAI | Yes, <br> No, <br> Yes, <br> Yes (must set to true) | [GoogleAISettings](../../../semantic_kernel/connectors/ai/google/google_ai/google_ai_settings.py) |
|
||||
| | [GoogleAITextCompletion](../../../semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py) | project_id, <br> region, <br> gemini_model_id | GOOGLE_AI_CLOUD_PROJECT_ID, <br> GOOGLE_AI_CLOUD_REGION, <br> GOOGLE_AI_GEMINI_MODEL_ID, <br> GOOGLE_AI_USE_VERTEXAI | Yes, <br> No, <br> Yes, <br> Yes (must set to true) | |
|
||||
| | [GoogleAITextEmbedding](../../../semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py) | project_id, <br> region, <br> embedding_model_id | GOOGLE_AI_CLOUD_PROJECT_ID, <br> GOOGLE_AI_CLOUD_REGION, <br> GOOGLE_AI_EMBEDDING_MODEL_ID, <br> GOOGLE_AI_USE_VERTEXAI | Yes, <br> No, <br> Yes, <br> Yes (must set to true) | |
|
||||
| HuggingFace | [HuggingFaceTextCompletion](../../../semantic_kernel/connectors/ai/hugging_face/services/hf_text_completion.py) | ai_model_id | N/A | Yes | |
|
||||
| | [HuggingFaceTextEmbedding](../../../semantic_kernel/connectors/ai/hugging_face/services/hf_text_embedding.py) | ai_model_id | N/A | Yes | |
|
||||
| NVIDIA NIM | [NvidiaChatCompletion](../../../semantic_kernel/connectors/ai/nvidia/services/nvidia_chat_completion.py) | ai_model_id, <br> api_key, <br> base_url | NVIDIA_CHAT_MODEL_ID, <br> NVIDIA_API_KEY, <br> NVIDIA_BASE_URL | Yes (default: meta/llama-3.1-8b-instruct), <br> Yes, <br> No | [NvidiaAISettings](../../../semantic_kernel/connectors/ai/nvidia/settings/nvidia_settings.py) |
|
||||
| | [NvidiaTextEmbedding](../../../semantic_kernel/connectors/ai/nvidia/services/nvidia_text_embedding.py) | ai_model_id, <br> api_key, <br> base_url | NVIDIA_API_KEY, <br> NVIDIA_TEXT_EMBEDDING_MODEL_ID, <br> NVIDIA_BASE_URL | Yes | [NvidiaAISettings](../../../semantic_kernel/connectors/ai/nvidia/settings/nvidia_settings.py) |
|
||||
| Mistral AI | [MistralAIChatCompletion](../../../semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_chat_completion.py) | ai_model_id, <br> api_key | MISTRALAI_CHAT_MODEL_ID, <br> MISTRALAI_API_KEY | Yes, <br> Yes | [MistralAISettings](../../../semantic_kernel/connectors/ai/mistral_ai/settings/mistral_ai_settings.py) |
|
||||
| | [MistralAITextEmbedding](../../../semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_text_embedding.py) | ai_model_id, <br> api_key | MISTRALAI_EMBEDDING_MODEL_ID, <br> MISTRALAI_API_KEY | Yes, <br> Yes | |
|
||||
| Ollama | [OllamaChatCompletion](../../../semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py) | ai_model_id, <br> host | OLLAMA_CHAT_MODEL_ID, <br> OLLAMA_HOST | Yes, <br> No | [OllamaSettings](../../../semantic_kernel/connectors/ai/ollama/ollama_settings.py) |
|
||||
| | [OllamaTextCompletion](../../../semantic_kernel/connectors/ai/ollama/services/ollama_text_completion.py) | ai_model_id, <br> host | OLLAMA_TEXT_MODEL_ID, <br> OLLAMA_HOST | Yes, <br> No | |
|
||||
| | [OllamaTextEmbedding](../../../semantic_kernel/connectors/ai/ollama/services/ollama_text_embedding.py) | ai_model_id, <br> host | OLLAMA_EMBEDDING_MODEL_ID, <br> OLLAMA_HOST | Yes, <br> No | |
|
||||
| Onnx | [OnnxGenAIChatCompletion](../../../semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py) | template, <br> ai_model_path | N/A, <br> ONNX_GEN_AI_CHAT_MODEL_FOLDER | Yes, <br> Yes | [OnnxGenAISettings](../../../semantic_kernel/connectors/ai/onnx/onnx_gen_ai_settings.py) |
|
||||
| | [OnnxGenAITextCompletion](../../../semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_text_completion.py) | ai_model_path | ONNX_GEN_AI_TEXT_MODEL_FOLDER | Yes | |
|
||||
|
||||
## Agent Framework Settings used across SK
|
||||
|
||||
| Provider | Service | Constructor Settings | Environment Variable | Required? | Settings Class |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| OpenAI | [OpenAIAssistantAgent](../../../semantic_kernel/agents/open_ai/openai_assistant_agent.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_CHAT_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | [OpenAISettings](../../../semantic_kernel/connectors/ai/open_ai/settings/open_ai_settings.py) |
|
||||
| | [OpenAIResponsesAgent](../../../semantic_kernel/agents/open_ai/openai_responses_agent.py) | ai_model_id, <br> api_key, <br> org_id | OPENAI_RESPONSES_MODEL_ID, <br> OPENAI_API_KEY, <br> OPENAI_ORG_ID | Yes, <br> Yes, <br> No | [OpenAISettings](../../../semantic_kernel/connectors/ai/open_ai/settings/open_ai_settings.py) |
|
||||
| Azure OpenAI | [AzureAssistantAgent](../../../semantic_kernel/agents/open_ai/azure_assistant_agent.py) | deployment_name, <br> api_key, <br> endpoint, <br> api_version, <br> base_url | AZURE_OPENAI_CHAT_DEPLOYMENT_NAME, <br> AZURE_OPENAI_API_KEY, <br> AZURE_OPENAI_ENDPOINT, <br> AZURE_OPENAI_API_VERSION, <br> AZURE_OPENAI_BASE_URL | Yes, <br> No, <br> Yes, <br> Yes, <br> No | [AzureOpenAISettings](../../../semantic_kernel/connectors/ai/open_ai/settings/azure_open_ai_settings.py) |
|
||||
| | [AzureResponsesAgent](../../../semantic_kernel/agents/open_ai/azure_responses_agent.py) | deployment_name, <br> api_key, <br> endpoint, <br> api_version, <br> base_url | AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME, <br> AZURE_OPENAI_API_KEY, <br> AZURE_OPENAI_ENDPOINT, <br> AZURE_OPENAI_API_VERSION, <br> AZURE_OPENAI_BASE_URL | Yes, <br> No, <br> Yes, <br> Yes, <br> No | [AzureOpenAISettings](../../../semantic_kernel/connectors/ai/open_ai/settings/azure_open_ai_settings.py) |
|
||||
| Azure AI | [AzureAIAgent](../../../semantic_kernel/agents/azure_ai/azure_ai_agent.py) | model_deployment_name, <br> endpoint, <br> agent_id, <br> bing_connection_id, <br> azure_ai_search_connection_id, <br> azure_ai_search_index_name, <br> api_version | AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME, <br> AZURE_AI_AGENT_ENDPOINT, <br> AZURE_AI_AGENT_AGENT_ID, <br> AZURE_AI_AGENT_BING_CONNECTION_ID, <br> AZURE_AI_AGENT_AZURE_AI_SEARCH_CONNECTION_ID, <br> AZURE_AI_AGENT_AZURE_AI_SEARCH_INDEX_NAME, <br> AZURE_AI_AGENT_API_VERSION | Yes, <br> Yes, <br> No, <br> No, <br> No, <br> No, <br> No | [AzureAIAgentSettings](../../../semantic_kernel/agents/azure_ai/azure_ai_agent_settings.py) |
|
||||
| Bedrock | [BedrockAgent](../../../semantic_kernel/agents/bedrock/bedrock_agent.py) | agent_resource_role_arn, <br> foundation_model | BEDROCK_AGENT_AGENT_RESOURCE_ROLE_ARN, <br> BEDROCK_AGENT_FOUNDATION_MODEL | Yes, <br> Yes | [BedrockAgentSettings](../../../semantic_kernel/agents/bedrock/bedrock_agent_settings.py) |
|
||||
| Copilot Studio | [CopilotStudioAgent](../../../semantic_kernel/agents/copilot_studio/copilot_studio_agent.py) | app_client_id, <br> tenant_id, <br> environment_id, <br> agent_identifier, <br> cloud, <br> copilot_agent_type, <br> custom_power_platform_cloud, <br> client_secret, <br> client_certificate, <br> user_assertion, <br> auth_mode | COPILOT_STUDIO_AGENT_APP_CLIENT_ID, <br> COPILOT_STUDIO_AGENT_TENANT_ID, <br> COPILOT_STUDIO_AGENT_ENVIRONMENT_ID, <br> COPILOT_STUDIO_AGENT_AGENT_IDENTIFIER, <br> COPILOT_STUDIO_AGENT_CLOUD, <br> COPILOT_STUDIO_AGENT_COPILOT_AGENT_TYPE, <br> COPILOT_STUDIO_AGENT_CUSTOM_POWER_PLATFORM_CLOUD, <br> COPILOT_STUDIO_AGENT_CLIENT_SECRET, <br> COPILOT_STUDIO_AGENT_CLIENT_CERTIFICATE, <br> COPILOT_STUDIO_AGENT_USER_ASSERTION, <br> COPILOT_STUDIO_AGENT_AUTH_MODE | No (varies by mode) | [CopilotStudioAgentSettings](../../../semantic_kernel/agents/copilot_studio/copilot_studio_agent_settings.py) |
|
||||
|
||||
|
||||
|
||||
## Memory Service Settings used across SK
|
||||
|
||||
| Provider | Service | Constructor Settings | Environment Variable | Required? | Settings Class |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| AstraDB | [AstraDBMemoryService](../../../semantic_kernel/connectors/memory/astradb/astradb_memory_store.py) | app_token, <br> db_id, <br> region, <br> keyspace | ASTRADB_APP_TOKEN, <br> ASTRADB_DB_ID, <br> ASTRADB_REGION, <br> ASTRADB_KEYSPACE | Yes, <br> Yes, <br> Yes, <br> Yes | [AstraDBSettings](../../../semantic_kernel/connectors/memory/astradb/astradb_settings.py) |
|
||||
| Azure AI Search | [AzureAISearchMemoryService](../../../semantic_kernel/connectors/memory/azure_cognitive_search/azure_cognitive_search_memory_store.py) | api_key, <br> endpoint, <br> index_name | AZURE_AI_SEARCH_API_KEY, <br> AZURE_AI_SEARCH_ENDPOINT, <br> AZURE_AI_SEARCH_INDEX_NAME | No, <br> Yes, <br> No | [AzureAISearchSettings](../../../semantic_kernel/connectors/memory/azure_cognitive_search/azure_ai_search_settings.py) |
|
||||
| Azure Cosmos DB | [AzureCosmosDBMemoryService](../../../semantic_kernel/connectors/memory/azure_cosmosdb/azure_cosmos_db_memory_store.py) | api, <br> connection_string | AZURE_COSMOS_DB_API, <br> AZURE_COSMOS_DB_CONNECTION_STRING or AZCOSMOS_CONNSTR | No, <br> No | [AzureCosmosDBSettings](../../../semantic_kernel/connectors/memory/azure_cosmosdb/azure_cosmosdb_settings.py) |
|
||||
| Mongo DB Atlas | [MongoDBAtlasMemoryService](../../../semantic_kernel/connectors/memory/mongodb_atlas/mongodb_atlas_memory_store.py) | connection_string, <br> database_name, <br> index_name | MONGODB_ATLAS_CONNECTION_STRING, <br> MONGODB_ATLAS_DATABASE_NAME, <br> MONGODB_ATLAS_INDEX_NAME | Yes, <br> No, <br> No | [MongoDBAtlasSettings](../../../semantic_kernel/connectors/memory/mongodb_atlas/mongodb_atlas_settings.py) |
|
||||
| Pinecone | [PineconeMemoryService](../../../semantic_kernel/connectors/memory/pinecone/pinecone_memory_store.py) | api_key | PINECONE_API_KEY | Yes | [PineconeSettings](../../../semantic_kernel/connectors/memory/pinecone/pinecone_settings.py) |
|
||||
| Postgres | [PostgresMemoryService](../../../semantic_kernel/connectors/memory/postgres/postgres_memory_store.py) | connection_string | POSTGRES_CONNECTION_STRING | Yes | [PostgresSettings](../../../semantic_kernel/connectors/memory/postgres/postgres_settings.py) |
|
||||
| Redis | [RedisMemoryService](../../../semantic_kernel/connectors/memory/redis/redis_memory_store.py) | connection_string | REDIS_CONNECTION_STRING | Yes | [RedisSettings](../../../semantic_kernel/connectors/memory/redis/redis_settings.py) |
|
||||
| Weaviate | [WeaviateMemoryService](../../../semantic_kernel/connectors/memory/weaviate/weaviate_memory_store.py) | url, <br> api_key, <br> use_embed | WEAVIATE_URL, <br> WEAVIATE_API_KEY, <br> WEAVIATE_USE_EMBED | No, <br> No, <br> No | [WeaviateSettings](../../../semantic_kernel/connectors/memory/weaviate/weaviate_settings.py) |
|
||||
|
||||
## Other settings used
|
||||
|
||||
| Provider | Service | Constructor Settings | Environment Variable | Required? | Settings Class |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| Bing | [BingSearch](../../../semantic_kernel/connectors/search_engine/bing_connector.py) | api_key, <br> custom_config | BING_API_KEY, <br> BING_CUSTOM_CONFIG | No, <br> No | [BingSettings](../../../semantic_kernel/connectors/search_engine/bing_connector_settings.py) |
|
||||
| Azure Container Apps Sessions | [ACASessionsPlugin](../../../semantic_kernel/core_plugins/sessions_python_tool/sessions_python_plugin.py) | pool_management_endpoint | ACA_POOL_MANAGEMENT_ENDPOINT | Yes | [ACASessionsSettings](../../../semantic_kernel/core_plugins/sessions_python_tool/sessions_python_settings.py) |
|
||||
@@ -0,0 +1,75 @@
|
||||
# Using environment variables to setup Semantic Kernel
|
||||
|
||||
Semantic Kernel allows you multiple ways to setup your connectors. This guide shows that for OpenAI Connectors.
|
||||
|
||||
After installing the semantic-kernel package, you can try these out.
|
||||
|
||||
## From environment settings
|
||||
using this method will try to find the required settings in the environment variables
|
||||
this is done using pydantic settings, see the full docs of that here: https://docs.pydantic.dev/latest/concepts/pydantic_settings/#usage
|
||||
We use a prefix for all the settings and then have names defined in the OpenAISettings class
|
||||
for OpenAI that is OPENAI_ as the prefix, with the following settings:
|
||||
|
||||
- api_key (`OPENAI_API_KEY`): OpenAI API key, see https://platform.openai.com/account/api-keys
|
||||
- org_id (`OPENAI_ORG_ID`): This is usually optional unless your account belongs to multiple organizations.
|
||||
- chat_model_id (`OPENAI_CHAT_MODEL_ID`): The OpenAI chat model ID to use, for example, gpt-3.5-turbo or gpt-4,
|
||||
this variable is used in the OpenAIChatCompletion class and get's passed to the ai_model_id there.
|
||||
- text_model_id (`OPENAI_TEXT_MODEL_ID`): The OpenAI text model ID to use, for example, gpt-3.5-turbo-instruct,
|
||||
this variable is used in the OpenAITextCompletion class and get's passed to the ai_model_id there.
|
||||
- embedding_model_id (`OPENAI_EMBEDDING_MODEL_ID`): The embedding model ID to use, for example, text-embedding-ada-002,
|
||||
this variable is used in the OpenAITextEmbedding class and get's passed to the ai_model_id there.
|
||||
|
||||
```python
|
||||
import os
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
|
||||
|
||||
try:
|
||||
# when nothing is passed to the constructor,
|
||||
# it will use the above environment variable names to find the required settings,
|
||||
# in this case it will only fail if the OPENAI_CHAT_MODEL_ID and OPENAI_API_KEY are not found
|
||||
service = OpenAIChatCompletion(service_id="openai_chat_service")
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
```
|
||||
|
||||
## From a .env file
|
||||
when you want to store and use your settings from a specific file (any file as long as it is in the .env format) you can pass the path to the file to the constructor this will still look at the same names of the settings as above, but will try to load them from the file
|
||||
|
||||
```python
|
||||
try:
|
||||
# this will try to load the settings from the file at the given path
|
||||
service = OpenAIChatCompletion(service_id="openai_chat_service", env_file_path="path/to/env_file")
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
```
|
||||
|
||||
## From a different value
|
||||
if you want to pass the settings yourself, you can do that by passing the values to the constructor this will ignore the environment variables and the .env file in this case our API_KEY is stored in a env variable called MY_API_KEY_VAR_NAME if using a file for this value, then we first need run the following code to load the .env file from the same folder as this file:
|
||||
|
||||
```python
|
||||
from dotenv import load_dotenv
|
||||
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
|
||||
load_dotenv(dotenv_path)
|
||||
```
|
||||
|
||||
After that pass the value directly to the constructor as shown below we can also fix another value, in this case the ai_model_id, which becomes chat_model_id in the settings, fixed to gpt-4o
|
||||
|
||||
```python
|
||||
try:
|
||||
# this will use the given values as the settings
|
||||
api_key = os.getenv("MY_API_KEY_VAR_NAME")
|
||||
service = OpenAIChatCompletion(
|
||||
service_id="openai_chat_service",
|
||||
api_key=api_key,
|
||||
ai_model_id="gpt-4o",
|
||||
)
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
```
|
||||
|
||||
## One final note:
|
||||
|
||||
It is a convention that env settings are setup with all caps, and with underscores between words the loader that we use is case insensitive, so you can use any case you want in your env variables but it is a good practice to follow the convention and use all caps.
|
||||
@@ -0,0 +1,432 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from semantic_kernel.connectors.ai.chat_completion_client_base import ChatCompletionClientBase
|
||||
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
|
||||
|
||||
|
||||
class Services(str, Enum):
|
||||
"""Enum for supported chat completion services.
|
||||
|
||||
For service specific settings, refer to this documentation:
|
||||
https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/setup/ALL_SETTINGS.md
|
||||
"""
|
||||
|
||||
OPENAI = "openai"
|
||||
AZURE_OPENAI = "azure_openai"
|
||||
AZURE_AI_INFERENCE = "azure_ai_inference"
|
||||
ANTHROPIC = "anthropic"
|
||||
BEDROCK = "bedrock"
|
||||
GOOGLE_AI = "google_ai"
|
||||
MISTRAL_AI = "mistral_ai"
|
||||
OLLAMA = "ollama"
|
||||
ONNX = "onnx"
|
||||
VERTEX_AI = "vertex_ai"
|
||||
DEEPSEEK = "deepseek"
|
||||
NVIDIA = "nvidia"
|
||||
|
||||
|
||||
service_id = "default"
|
||||
|
||||
|
||||
def get_chat_completion_service_and_request_settings(
|
||||
service_name: Services,
|
||||
instruction_role: str | None = None,
|
||||
) -> tuple["ChatCompletionClientBase", "PromptExecutionSettings"]:
|
||||
"""Return service and request settings.
|
||||
|
||||
Args:
|
||||
service_name (Services): The service name.
|
||||
instruction_role (str | None): The role to use for 'instruction' messages, for example,
|
||||
'system' or 'developer'. Defaults to 'system'. Currently only OpenAI reasoning models
|
||||
support 'developer' role.
|
||||
"""
|
||||
# Use lambdas or functions to delay instantiation
|
||||
chat_services = {
|
||||
Services.OPENAI: lambda: get_openai_chat_completion_service_and_request_settings(
|
||||
instruction_role=instruction_role
|
||||
),
|
||||
Services.AZURE_OPENAI: lambda: get_azure_openai_chat_completion_service_and_request_settings(
|
||||
instruction_role=instruction_role
|
||||
),
|
||||
Services.AZURE_AI_INFERENCE: lambda: get_azure_ai_inference_chat_completion_service_and_request_settings(
|
||||
instruction_role=instruction_role
|
||||
),
|
||||
Services.ANTHROPIC: lambda: get_anthropic_chat_completion_service_and_request_settings(),
|
||||
Services.BEDROCK: lambda: get_bedrock_chat_completion_service_and_request_settings(),
|
||||
Services.GOOGLE_AI: lambda: get_google_ai_chat_completion_service_and_request_settings(),
|
||||
Services.MISTRAL_AI: lambda: get_mistral_ai_chat_completion_service_and_request_settings(),
|
||||
Services.OLLAMA: lambda: get_ollama_chat_completion_service_and_request_settings(),
|
||||
Services.ONNX: lambda: get_onnx_chat_completion_service_and_request_settings(),
|
||||
Services.VERTEX_AI: lambda: get_vertex_ai_chat_completion_service_and_request_settings(),
|
||||
Services.DEEPSEEK: lambda: get_deepseek_chat_completion_service_and_request_settings(),
|
||||
Services.NVIDIA: lambda: get_nvidia_chat_completion_service_and_request_settings(),
|
||||
}
|
||||
|
||||
# Call the appropriate lambda or function based on the service name
|
||||
if service_name not in chat_services:
|
||||
raise ValueError(f"Unsupported service name: {service_name}")
|
||||
return chat_services[service_name]()
|
||||
|
||||
|
||||
def get_openai_chat_completion_service_and_request_settings(
|
||||
instruction_role: str | None = None,
|
||||
) -> tuple["ChatCompletionClientBase", "PromptExecutionSettings"]:
|
||||
"""Return OpenAI chat completion service and request settings.
|
||||
|
||||
Args:
|
||||
instruction_role (str | None): The role to use for 'instruction' messages, for example,
|
||||
'developer' or 'system'. (Optional)
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, OpenAIChatPromptExecutionSettings
|
||||
|
||||
chat_service = OpenAIChatCompletion(service_id=service_id, instruction_role=instruction_role)
|
||||
request_settings = OpenAIChatPromptExecutionSettings(
|
||||
service_id=service_id, max_tokens=2000, temperature=0.7, top_p=0.8
|
||||
)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_azure_openai_chat_completion_service_and_request_settings(
|
||||
instruction_role: str | None = None,
|
||||
) -> tuple["ChatCompletionClientBase", "PromptExecutionSettings"]:
|
||||
"""Return Azure OpenAI chat completion service and request settings.
|
||||
|
||||
Args:
|
||||
instruction_role (str | None): The role to use for 'instruction' messages, for example,
|
||||
'developer' or 'system'. (Optional)
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, AzureChatPromptExecutionSettings
|
||||
|
||||
chat_service = AzureChatCompletion(
|
||||
service_id=service_id, instruction_role=instruction_role, credential=AzureCliCredential()
|
||||
)
|
||||
request_settings = AzureChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_azure_ai_inference_chat_completion_service_and_request_settings(
|
||||
instruction_role: str | None = None,
|
||||
) -> tuple["ChatCompletionClientBase", "PromptExecutionSettings"]:
|
||||
"""Return Azure AI Inference chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.azure_ai_inference import (
|
||||
AzureAIInferenceChatCompletion,
|
||||
AzureAIInferenceChatPromptExecutionSettings,
|
||||
)
|
||||
|
||||
# The AI model ID is used as an identifier for developers when they are using serverless endpoints
|
||||
# on AI Foundry. It is not actually used to identify the model in the service as the endpoint points
|
||||
# to only one model.
|
||||
# When developers are using one endpoint that can route to multiple models, the `ai_model_id` will be
|
||||
# used to identify the model. To use the latest routing feature on AI Foundry, please refer to the
|
||||
# following documentation:
|
||||
# https://learn.microsoft.com/en-us/azure/ai-services/multi-service-resource?%3Fcontext=%2Fazure%2Fai-services%2Fmodel-inference%2Fcontext%2Fcontext&pivots=azportal
|
||||
# https://learn.microsoft.com/en-us/azure/ai-foundry/model-inference/how-to/configure-project-connection?pivots=ai-foundry-portal
|
||||
# https://learn.microsoft.com/en-us/azure/ai-foundry/model-inference/how-to/inference?tabs=python
|
||||
|
||||
chat_service = AzureAIInferenceChatCompletion(
|
||||
service_id=service_id,
|
||||
ai_model_id="id",
|
||||
instruction_role=instruction_role,
|
||||
)
|
||||
request_settings = AzureAIInferenceChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_anthropic_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Anthropic chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.anthropic import AnthropicChatCompletion, AnthropicChatPromptExecutionSettings
|
||||
|
||||
chat_service = AnthropicChatCompletion(service_id=service_id)
|
||||
request_settings = AnthropicChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_bedrock_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Bedrock chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.bedrock import BedrockChatCompletion, BedrockChatPromptExecutionSettings
|
||||
|
||||
chat_service = BedrockChatCompletion(service_id=service_id)
|
||||
request_settings = BedrockChatPromptExecutionSettings(
|
||||
# For model specific settings, specify them in the extension_data dictionary.
|
||||
# For example, for Cohere Command specific settings, refer to:
|
||||
# https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages.html
|
||||
service_id=service_id,
|
||||
extension_data={
|
||||
"temperature": 0.8,
|
||||
},
|
||||
)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_google_ai_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Google AI chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.google import GoogleAIChatCompletion, GoogleAIChatPromptExecutionSettings
|
||||
|
||||
chat_service = GoogleAIChatCompletion(service_id=service_id)
|
||||
request_settings = GoogleAIChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_mistral_ai_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Mistral AI chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.mistral_ai import MistralAIChatCompletion, MistralAIChatPromptExecutionSettings
|
||||
|
||||
chat_service = MistralAIChatCompletion(service_id=service_id)
|
||||
request_settings = MistralAIChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_ollama_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Ollama chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.ollama import OllamaChatCompletion, OllamaChatPromptExecutionSettings
|
||||
|
||||
chat_service = OllamaChatCompletion(service_id=service_id)
|
||||
request_settings = OllamaChatPromptExecutionSettings(
|
||||
# For model specific settings, specify them in the options dictionary.
|
||||
# For more information on the available options, refer to the Ollama API documentation:
|
||||
# https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
|
||||
service_id=service_id,
|
||||
options={
|
||||
"temperature": 0.8,
|
||||
},
|
||||
)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_onnx_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Onnx chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.onnx import OnnxGenAIChatCompletion, OnnxGenAIPromptExecutionSettings
|
||||
|
||||
chat_service = OnnxGenAIChatCompletion(template="phi4mm", service_id=service_id)
|
||||
request_settings = OnnxGenAIPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_vertex_ai_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Vertex AI chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.google import GoogleAIChatCompletion, GoogleAIChatPromptExecutionSettings
|
||||
|
||||
chat_service = GoogleAIChatCompletion(service_id=service_id, use_vertexai=True)
|
||||
request_settings = GoogleAIChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_deepseek_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return DeepSeek chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The DeepSeek endpoint can be accessed via the OpenAI connector as the DeepSeek API is compatible with OpenAI API.
|
||||
Set the `OPENAI_API_KEY` environment variable to the DeepSeek API key.
|
||||
Set the `OPENAI_CHAT_MODEL_ID` environment variable to the DeepSeek model ID (deepseek-chat or deepseek-reasoner).
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python
|
||||
"""
|
||||
from openai import AsyncOpenAI
|
||||
|
||||
from semantic_kernel.connectors.ai.open_ai import (
|
||||
OpenAIChatCompletion,
|
||||
OpenAIChatPromptExecutionSettings,
|
||||
OpenAISettings,
|
||||
)
|
||||
|
||||
openai_settings = OpenAISettings()
|
||||
if not openai_settings.api_key:
|
||||
raise ServiceInitializationError("The DeepSeek API key is required.")
|
||||
if not openai_settings.chat_model_id:
|
||||
raise ServiceInitializationError("The DeepSeek model ID is required.")
|
||||
|
||||
chat_service = OpenAIChatCompletion(
|
||||
ai_model_id=openai_settings.chat_model_id,
|
||||
service_id=service_id,
|
||||
async_client=AsyncOpenAI(
|
||||
api_key=openai_settings.api_key.get_secret_value(),
|
||||
base_url="https://api.deepseek.com",
|
||||
),
|
||||
)
|
||||
request_settings = OpenAIChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
|
||||
|
||||
def get_nvidia_chat_completion_service_and_request_settings() -> tuple[
|
||||
"ChatCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return NVIDIA chat completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.nvidia import NvidiaChatCompletion, NvidiaChatPromptExecutionSettings
|
||||
|
||||
chat_service = NvidiaChatCompletion(service_id=service_id)
|
||||
request_settings = NvidiaChatPromptExecutionSettings(service_id=service_id)
|
||||
|
||||
return chat_service, request_settings
|
||||
@@ -0,0 +1,56 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
import os
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
|
||||
|
||||
# Semantic Kernel allows you multiple ways to setup your connectors. This sample shows that for OpenAI Connectors.
|
||||
# After installing the semantic-kernel package, you can use the following code to setup OpenAI Connector
|
||||
|
||||
# 1. From environment settings
|
||||
# Using this method will try to find the required settings in the environment variables.
|
||||
# This is done using pydantic settings, see the full docs of that here: https://docs.pydantic.dev/latest/concepts/pydantic_settings/#usage
|
||||
# We use a prefix for all the settings and then have names defined in the OpenAISettings class.
|
||||
# For OpenAI that is OPENAI_ as the prefix. For a full list of OpenAI settings, refer to:
|
||||
# https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/setup/ALL_SETTINGS.md
|
||||
try:
|
||||
# When nothing is passed to the constructor, it will use the above environment variable names
|
||||
# to find the required settings. In this case it will only fail if the OPENAI_CHAT_MODEL_ID and
|
||||
# OPENAI_API_KEY are not found
|
||||
service = OpenAIChatCompletion(service_id="openai_chat_service")
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
|
||||
# 2. From a .env file
|
||||
# When you want to store and use your settings from a specific file (any file as long as it is in the .env format),
|
||||
# you can pass the path to the file to the constructor. This will still look at the same names of the settings as above,
|
||||
# but will try to load them from the file
|
||||
try:
|
||||
# This will try to load the settings from the file at the given path
|
||||
service = OpenAIChatCompletion(service_id="openai_chat_service", env_file_path="path/to/env_file")
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
|
||||
# 3. From a different value
|
||||
# If you want to pass the settings yourself, you can do that by passing the values to the constructor.
|
||||
# This will ignore the environment variables and the .env file.
|
||||
# In this case our API_KEY is stored in an env variable called MY_API_KEY_VAR_NAME.
|
||||
# We can also hardcode another value, in this case the ai_model_id, which becomes chat_model_id in the
|
||||
# settings, to gpt-4o
|
||||
try:
|
||||
# this will use the given values as the settings
|
||||
api_key = os.getenv("MY_API_KEY_VAR_NAME")
|
||||
service = OpenAIChatCompletion(
|
||||
service_id="openai_chat_service",
|
||||
api_key=api_key,
|
||||
ai_model_id="gpt-4o",
|
||||
)
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
|
||||
# One final note:
|
||||
# It is a convention that env settings are setup with all caps, and with underscores between words
|
||||
# the loader that we use is case insensitive, so you can use any case you want in your env variables
|
||||
# but it is a good practice to follow the convention and use all caps.
|
||||
@@ -0,0 +1,242 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
|
||||
from semantic_kernel.connectors.ai.text_completion_client_base import TextCompletionClientBase
|
||||
|
||||
|
||||
class Services(str, Enum):
|
||||
"""Enum for supported text completion services.
|
||||
|
||||
For service specific settings, refer to this documentation:
|
||||
https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/setup/ALL_SETTINGS.md
|
||||
"""
|
||||
|
||||
OPENAI = "openai"
|
||||
BEDROCK = "bedrock"
|
||||
GOOGLE_AI = "google_ai"
|
||||
HUGGING_FACE = "huggingface"
|
||||
OLLAMA = "ollama"
|
||||
ONNX = "onnx"
|
||||
VERTEX_AI = "vertex_ai"
|
||||
|
||||
|
||||
def get_text_completion_service_and_request_settings(
|
||||
service_name: Services,
|
||||
) -> tuple["TextCompletionClientBase", "PromptExecutionSettings"]:
|
||||
"""Return service and request settings.
|
||||
|
||||
Args:
|
||||
service_name (Services): The service name.
|
||||
"""
|
||||
# Use lambdas or functions to delay instantiation
|
||||
text_services = {
|
||||
Services.OPENAI: lambda: get_openai_text_completion_service_and_request_settings(),
|
||||
Services.BEDROCK: lambda: get_bedrock_text_completion_service_and_request_settings(),
|
||||
Services.GOOGLE_AI: lambda: get_google_ai_text_completion_service_and_request_settings(),
|
||||
Services.HUGGING_FACE: lambda: get_hugging_face_text_completion_service_and_request_settings(),
|
||||
Services.OLLAMA: lambda: get_ollama_text_completion_service_and_request_settings(),
|
||||
Services.ONNX: lambda: get_onnx_text_completion_service_and_request_settings(),
|
||||
Services.VERTEX_AI: lambda: get_vertex_ai_text_completion_service_and_request_settings(),
|
||||
}
|
||||
|
||||
# Call the appropriate lambda or function based on the service name
|
||||
if service_name not in text_services:
|
||||
raise ValueError(f"Unsupported service name: {service_name}")
|
||||
return text_services[service_name]()
|
||||
|
||||
|
||||
def get_openai_text_completion_service_and_request_settings() -> tuple[
|
||||
"TextCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return OpenAI text completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAITextCompletion, OpenAITextPromptExecutionSettings
|
||||
|
||||
text_service = OpenAITextCompletion()
|
||||
request_settings = OpenAITextPromptExecutionSettings(max_tokens=20, temperature=0.7, top_p=0.8)
|
||||
|
||||
return text_service, request_settings
|
||||
|
||||
|
||||
def get_bedrock_text_completion_service_and_request_settings() -> tuple[
|
||||
"TextCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Bedrock text completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.bedrock import BedrockTextCompletion, BedrockTextPromptExecutionSettings
|
||||
|
||||
text_service = BedrockTextCompletion(model_id="amazon.titan-text-premier-v1:0")
|
||||
request_settings = BedrockTextPromptExecutionSettings(
|
||||
# For model specific settings, specify them in the extension_data dictionary.
|
||||
# For example, for Cohere Command specific settings, refer to:
|
||||
# https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-text.html
|
||||
extension_data={
|
||||
"temperature": 0.8,
|
||||
"maxTokenCount": 20,
|
||||
},
|
||||
)
|
||||
|
||||
return text_service, request_settings
|
||||
|
||||
|
||||
def get_google_ai_text_completion_service_and_request_settings() -> tuple[
|
||||
"TextCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Google AI text completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.google.google_ai import (
|
||||
GoogleAITextCompletion,
|
||||
GoogleAITextPromptExecutionSettings,
|
||||
)
|
||||
|
||||
text_service = GoogleAITextCompletion()
|
||||
request_settings = GoogleAITextPromptExecutionSettings()
|
||||
|
||||
return text_service, request_settings
|
||||
|
||||
|
||||
def get_hugging_face_text_completion_service_and_request_settings() -> tuple[
|
||||
"TextCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return HuggingFace text completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.hugging_face import HuggingFacePromptExecutionSettings, HuggingFaceTextCompletion
|
||||
|
||||
# Note this model is a demonstration model that outputs random text.
|
||||
text_service = HuggingFaceTextCompletion(ai_model_id="HuggingFaceM4/tiny-random-LlamaForCausalLM")
|
||||
request_settings = HuggingFacePromptExecutionSettings()
|
||||
|
||||
return text_service, request_settings
|
||||
|
||||
|
||||
def get_ollama_text_completion_service_and_request_settings() -> tuple[
|
||||
"TextCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Ollama text completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.ollama import OllamaTextCompletion, OllamaTextPromptExecutionSettings
|
||||
|
||||
text_service = OllamaTextCompletion()
|
||||
request_settings = OllamaTextPromptExecutionSettings(
|
||||
# For model specific settings, specify them in the options dictionary.
|
||||
# For more information on the available options, refer to the Ollama API documentation:
|
||||
# https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
|
||||
options={
|
||||
"temperature": 0.8,
|
||||
},
|
||||
)
|
||||
|
||||
return text_service, request_settings
|
||||
|
||||
|
||||
def get_onnx_text_completion_service_and_request_settings() -> tuple[
|
||||
"TextCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Onnx text completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.onnx import (
|
||||
OnnxGenAIPromptExecutionSettings,
|
||||
OnnxGenAITextCompletion,
|
||||
ONNXTemplate,
|
||||
)
|
||||
|
||||
text_service = OnnxGenAITextCompletion(
|
||||
ONNXTemplate.PHI3,
|
||||
)
|
||||
request_settings = OnnxGenAIPromptExecutionSettings()
|
||||
|
||||
return text_service, request_settings
|
||||
|
||||
|
||||
def get_vertex_ai_text_completion_service_and_request_settings() -> tuple[
|
||||
"TextCompletionClientBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Vertex AI text completion service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.google import GoogleAITextCompletion, GoogleAITextPromptExecutionSettings
|
||||
|
||||
text_service = GoogleAITextCompletion()
|
||||
request_settings = GoogleAITextPromptExecutionSettings()
|
||||
|
||||
return text_service, request_settings
|
||||
@@ -0,0 +1,305 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from semantic_kernel.connectors.ai.embedding_generator_base import EmbeddingGeneratorBase
|
||||
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
|
||||
|
||||
|
||||
class Services(str, Enum):
|
||||
"""Enum for supported embedding services.
|
||||
|
||||
For service specific settings, refer to this documentation:
|
||||
https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/setup/ALL_SETTINGS.md
|
||||
"""
|
||||
|
||||
OPENAI = "openai"
|
||||
AZURE_OPENAI = "azure_openai"
|
||||
AZURE_AI_INFERENCE = "azure_ai_inference"
|
||||
BEDROCK = "bedrock"
|
||||
GOOGLE_AI = "google_ai"
|
||||
HUGGING_FACE = "huggingface"
|
||||
MISTRAL_AI = "mistral_ai"
|
||||
OLLAMA = "ollama"
|
||||
VERTEX_AI = "vertex_ai"
|
||||
|
||||
|
||||
def get_text_embedding_service_and_request_settings(
|
||||
service_name: Services,
|
||||
) -> tuple["EmbeddingGeneratorBase", "PromptExecutionSettings"]:
|
||||
"""Returns the embedding service and request settings for the given service name.
|
||||
|
||||
Args:
|
||||
service_name (Services): The service name.
|
||||
|
||||
Returns:
|
||||
Tuple[EmbeddingGeneratorBase, PromptExecutionSettings]: The embedding service and request settings.
|
||||
"""
|
||||
# Use lambdas to delay instantiation of the services until needed.
|
||||
embedding_services = {
|
||||
Services.OPENAI: lambda: get_openai_text_embedding_service_and_request_settings(),
|
||||
Services.AZURE_OPENAI: lambda: get_azure_openai_text_embedding_service_and_request_settings(),
|
||||
Services.AZURE_AI_INFERENCE: lambda: get_azure_ai_inference_text_embedding_service_and_request_settings(),
|
||||
Services.BEDROCK: lambda: get_bedrock_text_embedding_service_and_request_settings(),
|
||||
Services.GOOGLE_AI: lambda: get_google_ai_text_embedding_service_and_request_settings(),
|
||||
Services.HUGGING_FACE: lambda: get_hugging_face_text_embedding_service_and_request_settings(),
|
||||
Services.MISTRAL_AI: lambda: get_mistral_ai_text_embedding_service_and_request_settings(),
|
||||
Services.OLLAMA: lambda: get_ollama_text_embedding_service_and_request_settings(),
|
||||
Services.VERTEX_AI: lambda: get_vertex_ai_text_embedding_service_and_request_settings(),
|
||||
}
|
||||
|
||||
# Call the appropriate lambda or function based on the service name
|
||||
if service_name not in embedding_services:
|
||||
raise ValueError(f"Unsupported service name: {service_name}")
|
||||
return embedding_services[service_name]()
|
||||
|
||||
|
||||
def get_openai_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return OpenAI embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIEmbeddingPromptExecutionSettings, OpenAITextEmbedding
|
||||
|
||||
embedding_service = OpenAITextEmbedding(ai_model_id="text-embedding-3-large")
|
||||
# Note: not all models support specifying the dimensions or there may be constraints on the dimensions
|
||||
request_settings = OpenAIEmbeddingPromptExecutionSettings(dimensions=3072)
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_azure_openai_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Azure OpenAI embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel-python
|
||||
"""
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
from semantic_kernel.connectors.ai.open_ai import AzureTextEmbedding, OpenAIEmbeddingPromptExecutionSettings
|
||||
|
||||
embedding_service = AzureTextEmbedding(deployment_name="text-embedding-3-large", credential=AzureCliCredential())
|
||||
# Note: not all models support specifying the dimensions or there may be constraints on the dimensions
|
||||
request_settings = OpenAIEmbeddingPromptExecutionSettings(dimensions=3072)
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_azure_ai_inference_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Azure AI Inference embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.azure_ai_inference import (
|
||||
AzureAIInferenceEmbeddingPromptExecutionSettings,
|
||||
AzureAIInferenceTextEmbedding,
|
||||
)
|
||||
|
||||
# The AI model ID is used as an identifier for developers when they are using serverless endpoints
|
||||
# on AI Foundry. It is not actually used to identify the model in the service as the endpoint points
|
||||
# to only one model.
|
||||
# When developers are using one endpoint that can route to multiple models, the `ai_model_id` will be
|
||||
# used to identify the model. To use the latest routing feature on AI Foundry, please refer to the
|
||||
# following documentation:
|
||||
# https://learn.microsoft.com/en-us/azure/ai-services/multi-service-resource?%3Fcontext=%2Fazure%2Fai-services%2Fmodel-inference%2Fcontext%2Fcontext&pivots=azportal
|
||||
# https://learn.microsoft.com/en-us/azure/ai-foundry/model-inference/how-to/configure-project-connection?pivots=ai-foundry-portal
|
||||
# https://learn.microsoft.com/en-us/azure/ai-foundry/model-inference/how-to/inference?tabs=python
|
||||
|
||||
embedding_service = AzureAIInferenceTextEmbedding(ai_model_id="id")
|
||||
# Note: not all models support specifying the dimensions or there may be constraints on the dimensions
|
||||
request_settings = AzureAIInferenceEmbeddingPromptExecutionSettings(dimensions=1024)
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_bedrock_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Bedrock embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.bedrock import BedrockEmbeddingPromptExecutionSettings, BedrockTextEmbedding
|
||||
|
||||
embedding_service = BedrockTextEmbedding(model_id="amazon.titan-embed-text-v2:0")
|
||||
request_settings = BedrockEmbeddingPromptExecutionSettings(
|
||||
# For model specific settings, specify them in the extension_data dictionary.
|
||||
# For example, for Cohere Command specific settings, refer to:
|
||||
# https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-embed-text.html
|
||||
extension_data={"dimensions": 256},
|
||||
)
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_hugging_face_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return HuggingFace text embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.hugging_face import HuggingFacePromptExecutionSettings, HuggingFaceTextEmbedding
|
||||
|
||||
embedding_service = HuggingFaceTextEmbedding(ai_model_id="sentence-transformers/all-MiniLM-L6-v2")
|
||||
request_settings = HuggingFacePromptExecutionSettings()
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_google_ai_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Google AI text embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.google.google_ai import (
|
||||
GoogleAIEmbeddingPromptExecutionSettings,
|
||||
GoogleAITextEmbedding,
|
||||
)
|
||||
|
||||
embedding_service = GoogleAITextEmbedding()
|
||||
# Note: not all models support specifying the dimensions or there may be constraints on the dimensions
|
||||
request_settings = GoogleAIEmbeddingPromptExecutionSettings(output_dimensionality=768)
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_mistral_ai_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Mistral AI text embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.mistral_ai import MistralAIPromptExecutionSettings, MistralAITextEmbedding
|
||||
|
||||
embedding_service = MistralAITextEmbedding()
|
||||
request_settings = MistralAIPromptExecutionSettings()
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_ollama_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Ollama text embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.ollama import OllamaEmbeddingPromptExecutionSettings, OllamaTextEmbedding
|
||||
|
||||
embedding_service = OllamaTextEmbedding()
|
||||
request_settings = OllamaEmbeddingPromptExecutionSettings(
|
||||
# For model specific settings, specify them in the options dictionary.
|
||||
# For more information on the available options, refer to the Ollama API documentation:
|
||||
# https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
|
||||
options={
|
||||
"temperature": 0.8,
|
||||
},
|
||||
)
|
||||
|
||||
return embedding_service, request_settings
|
||||
|
||||
|
||||
def get_vertex_ai_text_embedding_service_and_request_settings() -> tuple[
|
||||
"EmbeddingGeneratorBase", "PromptExecutionSettings"
|
||||
]:
|
||||
"""Return Vertex AI text embedding service and request settings.
|
||||
|
||||
The service credentials can be read by 3 ways:
|
||||
1. Via the constructor
|
||||
2. Via the environment variables
|
||||
3. Via an environment file
|
||||
|
||||
The request settings control the behavior of the service. The default settings are sufficient to get started.
|
||||
However, you can adjust the settings to suit your needs.
|
||||
Note: Some of the settings are NOT meant to be set by the user.
|
||||
Please refer to the Semantic Kernel Python documentation for more information:
|
||||
https://learn.microsoft.com/en-us/python/api/semantic-kernel/semantic_kernel?view=semantic-kernel
|
||||
"""
|
||||
from semantic_kernel.connectors.ai.google import GoogleAIEmbeddingPromptExecutionSettings, GoogleAITextEmbedding
|
||||
|
||||
embedding_service = GoogleAITextEmbedding()
|
||||
# Note: not all models support specifying the dimensions or there may be constraints on the dimensions
|
||||
request_settings = GoogleAIEmbeddingPromptExecutionSettings(output_dimensionality=768)
|
||||
|
||||
return embedding_service, request_settings
|
||||
Reference in New Issue
Block a user