forked from SolaceLabs/solace-ai-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples Update + Code Refactor (#25)
* Removed StorageManager * Added examples for OpenAI, Bedrock, Anthropic, and VertexAI * Updating old examples (1/2) * Updating old examples (2/2)
- Loading branch information
Showing
27 changed files
with
534 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# This will create a flow like this: | ||
# Solace -> Anthropic -> Solace | ||
# | ||
# It will subscribe to `demo/question` and expect an event with the payload: | ||
# | ||
# The input message has the following schema: | ||
# { | ||
# "text": "<question or request as text>" | ||
# } | ||
# | ||
# It will then send an event back to Solace with the topic: `demo/question/response` | ||
# | ||
# Dependencies: | ||
# pip install -U langchain-anthropic | ||
# | ||
# required ENV variables: | ||
# - ANTHROPIC_API_KEY | ||
# - ANTHROPIC_API_ENDPOINT | ||
# - MODEL_NAME | ||
# - SOLACE_BROKER_URL | ||
# - SOLACE_BROKER_USERNAME | ||
# - SOLACE_BROKER_PASSWORD | ||
# - SOLACE_BROKER_VPN | ||
|
||
--- | ||
log: | ||
stdout_log_level: INFO | ||
log_file_level: DEBUG | ||
log_file: solace_ai_connector.log | ||
|
||
shared_config: | ||
- broker_config: &broker_connection | ||
broker_type: solace | ||
broker_url: ${SOLACE_BROKER_URL} | ||
broker_username: ${SOLACE_BROKER_USERNAME} | ||
broker_password: ${SOLACE_BROKER_PASSWORD} | ||
broker_vpn: ${SOLACE_BROKER_VPN} | ||
|
||
# Take from Slack and publish to Solace | ||
flows: | ||
# Slack chat input processing | ||
- name: Simple template to LLM | ||
components: | ||
# Input from a Solace broker | ||
- component_name: solace_sw_broker | ||
component_module: broker_input | ||
component_config: | ||
<<: *broker_connection | ||
broker_queue_name: demo_question | ||
broker_subscriptions: | ||
- topic: demo/question | ||
qos: 1 | ||
payload_encoding: utf-8 | ||
payload_format: json | ||
|
||
# | ||
# Do an LLM request | ||
# | ||
- component_name: llm_request | ||
component_module: langchain_chat_model | ||
component_config: | ||
langchain_module: langchain_anthropic | ||
langchain_class: ChatAnthropic | ||
langchain_component_config: | ||
api_key: ${ANTHROPIC_API_KEY} | ||
base_url: ${ANTHROPIC_API_ENDPOINT} | ||
model: ${MODEL_NAME} | ||
temperature: 0.01 | ||
input_transforms: | ||
- type: copy | ||
source_expression: | | ||
template:You are a helpful AI assistant. Please help with the user's request below: | ||
<user-question> | ||
{{text://input.payload:text}} | ||
</user-question> | ||
dest_expression: user_data.llm_input:messages.0.content | ||
- type: copy | ||
source_expression: static:user | ||
dest_expression: user_data.llm_input:messages.0.role | ||
component_input: | ||
source_expression: user_data.llm_input | ||
|
||
# Send response back to broker | ||
- component_name: send_response | ||
component_module: broker_output | ||
component_config: | ||
<<: *broker_connection | ||
payload_encoding: utf-8 | ||
payload_format: json | ||
copy_user_properties: true | ||
input_transforms: | ||
- type: copy | ||
source_expression: previous | ||
dest_expression: user_data.output:payload | ||
- type: copy | ||
source_expression: template:{{text://input.topic}}/response | ||
dest_expression: user_data.output:topic | ||
component_input: | ||
source_expression: user_data.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# This will create a flow like this: | ||
# Solace -> OpenAI -> Solace | ||
# | ||
# It will subscribe to `demo/joke/subject` and expect an event with the payload: | ||
# | ||
# { | ||
# "joke": { | ||
# "subject": "<subject for the joke>" | ||
# } | ||
# } | ||
# | ||
# It will then send an event back to Solace with the topic: `demo/joke/subject/response` | ||
# | ||
# Dependencies: | ||
# pip install -U langchain_openai openai | ||
# | ||
# required ENV variables: | ||
# - OPENAI_API_KEY | ||
# - OPENAI_API_ENDPOINT - optional | ||
# - MODEL_NAME | ||
# - SOLACE_BROKER_URL | ||
# - SOLACE_BROKER_USERNAME | ||
# - SOLACE_BROKER_PASSWORD | ||
# - SOLACE_BROKER_VPN | ||
|
||
--- | ||
log: | ||
stdout_log_level: INFO | ||
log_file_level: DEBUG | ||
log_file: solace_ai_connector.log | ||
|
||
shared_config: | ||
- broker_config: &broker_connection | ||
broker_type: solace | ||
broker_url: ${SOLACE_BROKER_URL} | ||
broker_username: ${SOLACE_BROKER_USERNAME} | ||
broker_password: ${SOLACE_BROKER_PASSWORD} | ||
broker_vpn: ${SOLACE_BROKER_VPN} | ||
|
||
# Take from Slack and publish to Solace | ||
flows: | ||
# Slack chat input processing | ||
- name: Simple template to LLM | ||
components: | ||
# Input from a Solace broker | ||
- component_name: solace_sw_broker | ||
component_module: broker_input | ||
component_config: | ||
<<: *broker_connection | ||
broker_queue_name: ed_demo_joke | ||
broker_subscriptions: | ||
- topic: demo/joke/subject | ||
qos: 1 | ||
payload_encoding: utf-8 | ||
payload_format: json | ||
|
||
# Go to the LLM and keep history | ||
- component_name: chat_request_llm | ||
component_module: langchain_chat_model_with_history | ||
component_config: | ||
langchain_module: langchain_openai | ||
langchain_class: ChatOpenAI | ||
langchain_component_config: | ||
api_key: ${OPENAI_API_KEY} | ||
base_url: ${OPENAI_API_ENDPOINT} | ||
model: ${MODEL_NAME} | ||
temperature: 0.01 | ||
history_module: langchain_core.chat_history | ||
history_class: InMemoryChatMessageHistory | ||
history_max_turns: 20 | ||
history_max_length: 6000 | ||
input_transforms: | ||
- type: copy | ||
source_expression: template:Write a joke about {{text://input.payload:joke.subject}} | ||
dest_expression: user_data.input:messages.0.content | ||
- type: copy | ||
source_value: user | ||
dest_expression: user_data.input:messages.0.role | ||
component_input: | ||
source_expression: user_data.input | ||
|
||
# Send response back to broker | ||
- component_name: send_response | ||
component_module: broker_output | ||
component_config: | ||
<<: *broker_connection | ||
payload_encoding: utf-8 | ||
payload_format: json | ||
copy_user_properties: true | ||
input_transforms: | ||
- type: copy | ||
source_expression: previous | ||
dest_expression: user_data.output:payload | ||
- type: copy | ||
source_expression: template:{{text://input.topic}}/response | ||
dest_expression: user_data.output:topic | ||
component_input: | ||
source_expression: user_data.output |
Oops, something went wrong.