Skip to content

Commit

Permalink
Merge latest changes in prep for PyPi publish (#14)
Browse files Browse the repository at this point in the history
* Remove launch.json

* chore: Refactor SlackReceiver to handle channel events and join new channels

* Add ability for a component to send a message directly to a named flow
* Add ability to stream partial LLM responses to a named flow
* Add a configurable message that is sent to the slack channel that sent a message to slack_input
* Add the ability to clear the ack message and stream partial results to that ack message

* feat: Update default stream_batch_size to 15 in LangChainChatModelWithHistory
- also started on converting absolute paths for imports to relative ones

* Update import statement in main.py

The import statement in `main.py` was updated to remove the relative path and use an absolute import for `SolaceAiConnector` from `solace_ai_connector.solace_ai_connector`. This change improves the code organization and ensures proper module resolution.

* Another major reorganization of directory structure to make it more sensible. This is part of a cleanup before releasing to Pypi

* Fixed some documentation generation after package reorganization

* chore: Remove unused slack.yaml configuration file

* Made some changes in utils.py for dynamic loading. We will no longer do a directory search looking for modules. We are more explicit now

Also promote the gen_docs tool to an installed script so that it can be used for plugins

* Moved slack components into their own plugin: solace-ai-connector-slack.
Adjusted the importing of modules from config files to be more friendly for plugins and added a 'component_package' properly that will be auto-installed if it is specified and the package is not present.

* chore: Update component_base.py to include flow_lock_manager and flow_kv_store

This commit updates the component_base.py file to include the flow_lock_manager and flow_kv_store attributes. These attributes are necessary for components to access the flow-level lock manager and key-value store. By adding these attributes, components can now utilize the lock manager to synchronize access to shared resources and the key-value store to store and retrieve data across multiple components within the flow. This change improves the flexibility and functionality of the component_base.py file.

Changed the default location of the trust_store for the Solace API to be provided by the certifi module.

Added a configuration item for the ChatModel with History component to be able to limit the size of entries being added to the chat history

* chore: Update trust_store_path for Solace API

This commit updates the trust_store_path for the Solace API in the solace_messaging.py file. The trust_store_path is now provided by the certifi module, which ensures that the default location of the trust store is used. This change improves the security and reliability of the Solace API integration.

```

* Bump up to latest Solace API and small fix in a debug log

* DATAGO-79372: Add Publish workflow (#3)

* DATAGO-78654 : Add CI (#4)

* DATAGO-78654: Add ci

---------

Co-authored-by: Aman Riat <[email protected]>
Co-authored-by: Art Morozov <[email protected]>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent 1fe3952 commit 1c39679
Show file tree
Hide file tree
Showing 26 changed files with 824 additions and 881 deletions.
156 changes: 156 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: CI
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize]

permissions:
id-token: write
checks: write
issues: read
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest
env:
HATCH_CACHE_DIR: ${{ github.workspace }}/.hatch_cache
HATCH_DATA_DIR: ${{ github.workspace }}/.hatch_data

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Hatch
uses: pypa/hatch@install

- name: Restore Hatch Directory
uses: actions/cache/restore@v4
id: cache-restore
with:
path: |
${{ env.HATCH_CACHE_DIR }}
${{ env.HATCH_DATA_DIR }}
key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml','requirements.txt') }}

- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
hatch python install 3.8 3.12
- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
hatch env create test
- name: Cache Hatch Directory
uses: actions/cache/save@v4
if: steps.cache-restore.outputs.cache-hit != 'true'
id: cache-hatch
with:
path: |
${{ env.HATCH_CACHE_DIR }}
${{ env.HATCH_DATA_DIR }}
key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml','requirements.txt') }}

- name: Set up Docker Buildx
id: builder
uses: docker/setup-buildx-action@v3

- name: Prepare env file
run: |
cp .env_template .env
shell: bash

- name: Build Docker Image
uses: docker/build-push-action@v6
with:
push: false
tags: solace/solace-ai-connector:local
platforms: linux/amd64
builder: ${{ steps.builder.outputs.name }}
load: true

- name: Run Lint
continue-on-error: true
run: |
hatch run +py=312 lint:ruff check -o lint.json --output-format json ./src ./tests
shell: bash

- name: Run Structured Tests
run: |
hatch run +py=312 test:make structure-test
shell: bash

- name: Run Unit Tests
shell: bash
run: |
hatch test --cover --all --parallel --junitxml=junit.xml
- name: Combine Coverage Reports
continue-on-error: true
run: |
hatch run +py=312 test:coverage combine
shell: bash

- name: Report coverage
run: |
hatch run +py=312 test:coverage xml
shell: bash

- name: SonarQube Scan
if: always()
uses: sonarsource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
with:
args: >
-Dsonar.tests=tests/
-Dsonar.verbose=true
-Dsonar.sources=src/
-Dsonar.projectKey=${{github.repository_owner}}_${{github.event.repository.name}}
-Dsonar.python.coverage.reportPaths=coverage.xml
-Dsonar.python.ruff.reportPaths=lint.json
- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}

# Build and verify packages
- name: Build
run: hatch build

- name: Verify Packages
run: |
ls dist/*.tar.gz | hatch run +py=312 test:xargs -n1 twine check
ls dist/*.whl | hatch run +py=312 test:xargs -n1 twine check
shell: bash

- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
with:
# A list of JUnit XML files, directories containing the former, and wildcard
# patterns to process.
# See @actions/glob for supported patterns.
path: junit.xml

# (Optional) Add a summary of the results at the top of the report
summary: true

# (Optional) Select which results should be included in the report.
# Follows the same syntax as `pytest -r`
display-options: fEX

# (Optional) Fail the workflow if no JUnit XML was found.
fail-on-empty: true

# (Optional) Title of the test results section in the workflow summary
title: Unit Test results
74 changes: 74 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Release
on:
workflow_dispatch:
inputs:
version:
type: choice
required: true
description: "Version bump type"
options:
- patch
- minor
- major

jobs:
release:
name: Release
timeout-minutes: 20
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/solace_ai_connector
permissions:
id-token: write
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ secrets.COMMIT_KEY }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install hatch
run: |
pip install --upgrade pip
pip install hatch
- name: Bump Version
run: |
CURRENT_VERSION=$(hatch version)
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV
hatch version "${{ github.event.inputs.version }}"
NEW_VERSION=$(hatch version)
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
- name: Fail if the current version doesn't exist
if: env.CURRENT_VERSION == ''
run: exit 1

- name: Build project for distribution
run: hatch build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*.whl"
makeLatest: true
generateReleaseNotes: true
tag: ${{ env.CURRENT_VERSION }}

- name: Commit new version
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -a -m "[ci skip] Bump version to $NEW_VERSION"
git push
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ RUN apt-get update && \
apt-get clean

#Install main program
COPY . /app
COPY /src /app/src
COPY requirements.txt /app

RUN python3.10 -m pip install -r requirements.txt
ENV PYTHONUNBUFFERED=1

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include .env
VERSION ?= local

gen-docs:
@python3 src/tools/gen_component_docs.py
@python3 src/solace_ai_connector/tools/gen_component_docs.py

build-pypi:
@python3 -m build
Expand Down
2 changes: 0 additions & 2 deletions docs/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
| [langchain_vector_store_embedding_search](langchain_vector_store_embedding_search.md) | Use LangChain Vector Stores to search a vector store with a semantic search. This will take text, run it through an embedding model with a query embedding and then find the closest matches in the store. |
| [message_filter](message_filter.md) | A filtering component. This will apply a user configurable expression. If the expression evaluates to True, the message will be passed on. If the expression evaluates to False, the message will be discarded. If the message is discarded, any previous components that require an acknowledgement will be acknowledged. |
| [pass_through](pass_through.md) | What goes in comes out |
| [slack_input](slack_input.md) | Slack input component. The component connects to Slack using the Bolt API and receives messages from Slack channels. |
| [slack_output](slack_output.md) | Slack output component. The component sends messages to Slack channels using the Bolt API. |
| [stdin_input](stdin_input.md) | STDIN input component. The component will prompt for input, which will then be placed in the message payload using the output schema below. |
| [stdout_output](stdout_output.md) | STDOUT output component |
| [timer_input](timer_input.md) | An input that will generate a message at a specified interval. |
Expand Down
2 changes: 2 additions & 0 deletions docs/components/langchain_chat_model_with_history.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ component_config:
langchain_component_config: <string>
llm_response_format: <string>
history_max_turns: <string>
history_max_message_size: <string>
history_max_tokens: <string>
history_module: <string>
history_class: <string>
Expand All @@ -29,6 +30,7 @@ component_config:
| langchain_component_config | True | | Model specific configuration for the chat model. See documentation for valid parameter names. |
| llm_response_format | False | | The response format for this LLM request. This can be 'json', 'yaml', or 'text'. If set to 'json' or 'yaml', the response will be parsed by the appropriate parser and the fields will be available in the response object. If set to 'text', the response will be returned as a string. |
| history_max_turns | False | 20 | The maximum number of turns to keep in the history. If not set, the history will be limited to 20 turns. |
| history_max_message_size | False | 1000 | The maximum amount of characters to keep in a single message in the history. |
| history_max_tokens | False | 8000 | The maximum number of tokens to keep in the history. If not set, the history will be limited to 8000 tokens. |
| history_module | False | langchain_community.chat_message_histories | The module that contains the history class. Default: 'langchain_community.chat_message_histories' |
| history_class | False | ChatMessageHistory | The class to use for the history. Default: 'ChatMessageHistory' |
Expand Down
6 changes: 3 additions & 3 deletions docs/components/langchain_vector_store_embedding_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ component_config:
| --- | --- | --- |
| results | True | |
| results.matches | False | |
| resultsmatches[].text | True | |
| resultsmatches[].metadata | False | |
| resultsmatches[].score | False | |
| results.matches[].text | True | |
| results.matches[].metadata | False | |
| results.matches[].score | False | |
85 changes: 0 additions & 85 deletions docs/components/slack_input.md

This file was deleted.

Loading

0 comments on commit 1c39679

Please sign in to comment.