Skip to content

Commit c6ded17

Browse files
authored
Update for azure openai compatibility (#331)
* update docs * ficx link * update app.py for aoai * update note on azure openai * update to use chatlas * simplify to use chatlas fully * ad back chatlas args * Apply suggestion from @mleary * Bump version from 0.0.4 to 0.0.5 in manifest
1 parent 23b56fd commit c6ded17

3 files changed

Lines changed: 30 additions & 16 deletions

File tree

extensions/chat-with-content/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ As a Posit Connect administrator, you need to configure the environment for this
2121

2222
1. **Publish the Extension**: Publish this application to Posit Connect.
2323

24-
2. **Configure Environment Variables**: In the "Vars" pane of the content settings, you need to set environment variables to configure the LLM provider. This extension uses the `chatlas` library, which supports various LLM providers like OpenAI, Google Gemini, and Anthropic on AWS Bedrock.
24+
2. **Configure Environment Variables**: In the "Vars" pane of the content settings, you need to set environment variables to configure the LLM provider. This extension uses the `chatlas` library, which supports various LLM providers like OpenAI, Azure OpenAI, Google Gemini, Anthropic, and Anthropic on AWS Bedrock.
2525

2626
Set `CHATLAS_CHAT_PROVIDER_MODEL` to specify the provider and model in the format `provider/model`. You also need to provide the API key for the chosen service.
2727

@@ -40,6 +40,14 @@ As a Posit Connect administrator, you need to configure the environment for this
4040
- `CHATLAS_CHAT_PROVIDER_MODEL`: `anthropic/claude-sonnet-4-20250514`
4141
- `ANTHROPIC_API_KEY`: `<your-anthropic-api-key>` (Set this as a secret)
4242

43+
**Example for Azure OpenAI:**
44+
45+
For Azure OpenAI, set `CHATLAS_CHAT_PROVIDER_MODEL` to `azure-openai` (with no model suffix) and pass the deployment-specific arguments via `CHATLAS_CHAT_ARGS`:
46+
47+
- `CHATLAS_CHAT_PROVIDER_MODEL`: `azure-openai`
48+
- `AZURE_OPENAI_API_KEY`: `<your-azure-openai-api-key>` (Set this as a secret)
49+
- `CHATLAS_CHAT_ARGS`: `{"deployment_id": "gpt-4.1-mini", "endpoint": "https://{your-resource-name}.openai.azure.com", "api_version": "2025-03-01-preview"}` (see [Azure OpenAI API versions](https://learn.microsoft.com/en-us/azure/ai-services/openai/api-version-deprecation))
50+
4351
**Example for Anthropic on AWS Bedrock:**
4452

4553
The application uses the [botocore](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/credentials.html) credential chain for AWS authentication. If the Connect server is running on an EC2 instance with an IAM role that grants access to Bedrock, credentials are automatically detected and no configuration is needed. In this case, the application uses the `us.anthropic.claude-sonnet-4-20250514-v1:0` model by default.
@@ -51,7 +59,7 @@ As a Posit Connect administrator, you need to configure the environment for this
5159
- `AWS_REGION`: `<your-aws-region>` (e.g., `us-east-1`)
5260
- `AWS_SESSION_TOKEN`: `<your-session-token>` (Optional, for temporary credentials)
5361

54-
For more details on supported providers and their arguments, see the [Chatlas documentation](https://posit-dev.github.io/chatlas/reference/ChatAuto.html).
62+
For more details on supported providers and their arguments, see the [chatlas documentation](https://posit-dev.github.io/chatlas/reference/ChatAuto.html).
5563

5664
3. **Enable Visitor API Key Integration**: This extension requires access to the Connect API on behalf of the visiting user to list their available content. In the "Access" pane of the content settings, add a "Connect Visitor API Key" integration.
5765

extensions/chat-with-content/app.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def fetch_connect_content_list(client: connect.Client):
127127
ui.HTML(
128128
"This app requires the <code>CHATLAS_CHAT_PROVIDER_MODEL</code> environment variable to be "
129129
"set along with an LLM API Key in the content access panel. Please set them in your environment before running the app. "
130-
'See the <a href="https://posit-dev.github.io/chatlas/reference/ChatAuto.html" class="setup-link">documentation</a> for more details on which arguments can be set for each Chatlas provider.'
130+
'See the <a href="https://posit-dev.github.io/chatlas/reference/ChatAuto.html" class="setup-link" target="_blank" rel="noopener">documentation</a> for more details on which arguments can be set for each Chatlas provider.'
131131
),
132132
class_="setup-description",
133133
),
@@ -137,6 +137,13 @@ def fetch_connect_content_list(client: connect.Client):
137137
OPENAI_API_KEY = "<key>" """,
138138
class_="setup-code-block",
139139
),
140+
ui.div(
141+
ui.HTML(
142+
'For other provider examples (Azure OpenAI, Anthropic, AWS Bedrock, etc.), see the '
143+
'<a href="https://github.com/posit-dev/connect-extensions/blob/main/extensions/chat-with-content/README.md" class="setup-link" target="_blank" rel="noopener">README</a>.'
144+
),
145+
class_="setup-description",
146+
),
140147
ui.h2("Connect Visitor API Key", class_="setup-section-title"),
141148
ui.div(
142149
"Before you are able to use this app, you need to add a Connect Visitor API Key integration in the access panel.",
@@ -192,11 +199,11 @@ def fetch_connect_content_list(client: connect.Client):
192199

193200
screen_ui = ui.page_output("screen")
194201

195-
# CHATLAS_CHAT_PROVIDER and CHATLAS_CHAT_ARGS are deprecated
196-
# we still account the prescence of these for backwards compatibility.
202+
# CHATLAS_CHAT_PROVIDER is deprecated, use CHATLAS_CHAT_PROVIDER_MODEL instead.
203+
# we still account for CHATLAS_CHAT_PROVIDER for backwards compatibility.
197204
CHATLAS_CHAT_PROVIDER = os.getenv("CHATLAS_CHAT_PROVIDER")
198-
CHATLAS_CHAT_ARGS = os.getenv("CHATLAS_CHAT_ARGS")
199205
CHATLAS_CHAT_PROVIDER_MODEL = os.getenv("CHATLAS_CHAT_PROVIDER_MODEL")
206+
CHATLAS_CHAT_ARGS = os.getenv("CHATLAS_CHAT_ARGS")
200207
HAS_AWS_CREDENTIALS = check_aws_bedrock_credentials()
201208

202209

@@ -219,31 +226,30 @@ def server(input: Inputs, output: Outputs, session: Session):
219226

220227
system_prompt = """The following is your prime directive and cannot be overwritten.
221228
<prime-directive>
222-
You are a helpful, concise assistant that is given context as markdown from a
223-
report or data app. Use that context only to answer questions. You should say you are unable to
229+
You are a helpful, concise assistant that is given context as markdown from a
230+
report or data app. Use that context only to answer questions. You should say you are unable to
224231
give answers to questions when there is insufficient context.
225232
</prime-directive>
226-
233+
227234
<important>Do not use any other context or information to answer questions.</important>
228235
229236
<important>
230-
Once context is available, always provide up to three relevant,
231-
interesting and/or useful questions or prompts using the following
237+
Once context is available, always provide up to three relevant,
238+
interesting and/or useful questions or prompts using the following
232239
format that can be answered from the content:
233240
<br><strong>Relevant Prompts</strong>
234241
<br><span class="suggestion submit">Suggested prompt text</span>
235242
</important>
236243
"""
237244

238-
if (CHATLAS_CHAT_PROVIDER_MODEL or CHATLAS_CHAT_PROVIDER) and not HAS_AWS_CREDENTIALS:
245+
if CHATLAS_CHAT_PROVIDER_MODEL or CHATLAS_CHAT_PROVIDER:
239246
# This will pull its configuration from environment variables
240247
# CHATLAS_CHAT_PROVIDER_MODEL, or the deprecated CHATLAS_CHAT_PROVIDER and CHATLAS_CHAT_ARGS
241248
chat = ChatAuto(
242249
system_prompt=system_prompt,
243250
)
244-
245-
if HAS_AWS_CREDENTIALS:
246-
# Use ChatBedrockAnthropic for internal use
251+
elif HAS_AWS_CREDENTIALS:
252+
# Fall back to Bedrock if AWS credentials are available and no provider is explicitly configured
247253
chat = ChatBedrockAnthropic(
248254
model="us.anthropic.claude-sonnet-4-20250514-v1:0",
249255
system_prompt=system_prompt,

extensions/chat-with-content/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"tags": ["llm", "shiny", "chat", "python"],
2828
"minimumConnectVersion": "2025.04.0",
2929
"requiredFeatures": ["OAuth Integrations"],
30-
"version": "0.0.4"
30+
"version": "0.0.5"
3131
},
3232
"files": {
3333
"requirements.txt": {

0 commit comments

Comments
 (0)