forked from ubiquity-os-marketplace/command-ask
-
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.
Merge pull request #1 from ubq-testing/development
Base Merge
- Loading branch information
Showing
39 changed files
with
1,664 additions
and
769 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
MY_SECRET="MY_SECRET" | ||
OPENAI_API_KEY="MY_SECRET" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
name: Delete Deployment | ||
|
||
on: | ||
delete: | ||
|
||
jobs: | ||
delete: | ||
runs-on: ubuntu-latest | ||
name: Delete Deployment | ||
steps: | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.10.0" | ||
|
||
- name: Enable corepack | ||
run: corepack enable | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Get Deleted Branch Name | ||
id: get_branch | ||
run: | | ||
branch_name=$(echo '${{ github.event.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g') | ||
echo "branch_name=$branch_name" >> $GITHUB_ENV | ||
- name: Retrieve and Construct Full Worker Name | ||
id: construct_worker_name | ||
run: | | ||
base_name=$(grep '^name = ' wrangler.toml | head -n 1 | sed 's/^name = "\(.*\)"$/\1/') | ||
full_worker_name="${base_name}-${{ env.branch_name }}" | ||
# Make sure that it doesnt exceed 63 characters or it will break RFC 1035 | ||
full_worker_name=$(echo "${full_worker_name}" | cut -c 1-63) | ||
echo "full_worker_name=$full_worker_name" >> $GITHUB_ENV | ||
- name: Delete Deployment with Wrangler | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
command: delete --name ${{ env.full_worker_name }} | ||
|
||
- name: Output Deletion Result | ||
run: | | ||
echo "### Deployment URL" >> $GITHUB_STEP_SUMMARY | ||
echo 'Deployment `${{ env.full_worker_name }}` has been deleted.' >> $GITHUB_STEP_SUMMARY |
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,48 @@ | ||
name: Deploy Worker | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
name: Deploy | ||
steps: | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.10.0" | ||
|
||
- name: Enable corepack | ||
run: corepack enable | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Update wrangler.toml Name Field | ||
run: | | ||
branch_name=$(echo '${{ github.event.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g') | ||
# Extract base name from wrangler.toml | ||
base_name=$(grep '^name = ' wrangler.toml | head -n 1 | sed 's/^name = "\(.*\)"$/\1/') | ||
# Concatenate branch name with base name | ||
new_name="${base_name}-${branch_name}" | ||
# Truncate the new name to 63 characters for RFC 1035 | ||
new_name=$(echo "$new_name" | cut -c 1-63) | ||
# Update the wrangler.toml file | ||
sed -i '0,/^name = .*/{s/^name = .*/name = "'"$new_name"'"/}' wrangler.toml | ||
echo "Updated wrangler.toml name to: $new_name" | ||
- name: Deploy with Wrangler | ||
id: wrangler_deploy | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
secrets: | | ||
OPENAI_API_KEY | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
|
||
- name: Write Deployment URL to Summary | ||
run: | | ||
echo "### Deployment URL" >> $GITHUB_STEP_SUMMARY | ||
echo "${{ steps.wrangler_deploy.outputs.deployment-url }}" >> $GITHUB_STEP_SUMMARY |
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 |
---|---|---|
@@ -1,93 +1,41 @@ | ||
# `@ubiquibot/plugin-template` | ||
# `@ubiquity-os/command-ask` | ||
|
||
## Prerequisites | ||
This is a highly context aware GitHub organization integrated bot that uses the OpenAI GPT-4o model to provide highly relevant answers to questions and queries in GitHub issues and pull requests. | ||
|
||
- A good understanding of how the [kernel](https://github.com/ubiquity/ubiquibot-kernel) works and how to interact with it. | ||
- A basic understanding of the Ubiquibot configuration and how to define your plugin's settings. | ||
## Usage | ||
|
||
## Getting Started | ||
In any repository where your Ubiquity OS app is installed, both issues and pull requests alike, you simply mention `@UbiquityOS` with your question or query and using the latest OpenAi GPT-4o model, the bot will provide you with a highly relevant answer. | ||
|
||
1. Create a new repository using this template. | ||
2. Clone the repository to your local machine. | ||
3. Install the dependencies preferably using `yarn` or `bun`. | ||
## How it works | ||
|
||
## Creating a new plugin | ||
With it's huge context window, we are able to feed the entire conversational history to the model which we obtain by recursively fetching any referenced issues or pull requests from the chat history. This allows the model to have a very deep understanding of the current scope and provide highly relevant answers. | ||
|
||
- If your plugin is to be used as a slash command which should have faster response times as opposed to longer running GitHub action tasks, you should use the `worker` type. | ||
As it receives everything from discussions to pull request diffs and review comments, it is a highly versatile and capable bot that can assist in a wide range of scenarios. | ||
|
||
1. Ensure you understand and have setup the [kernel](https://github.com/ubiquity/ubiquibot-kernel). | ||
2. Update [compute.yml](./.github/workflows/compute.yml) with your plugin's name and update the `id`. | ||
3. Update [context.ts](./src/types/context.ts) with the events that your plugin will fire on. | ||
4. Update [plugin-inputs.ts](./src/types/plugin-inputs.ts) to match the `with:` settings in your org or repo level configuration. | ||
## Installation | ||
|
||
- Your plugin config should look similar to this: | ||
`ubiquibot-config.yml`: | ||
|
||
```yml | ||
- plugin: <plugin-org/owner>/<plugin-repo-name>:compute.yml@development | ||
name: plugin-name | ||
id: plugin-name-command | ||
description: "Plugin description" # small description of what the plugin does | ||
command: "<regex for command>" # if you are creating a plugin with a slash command | ||
example: "<example usage>" # how to invoke the slash command | ||
with: # these are the example settings, the kernel passes these to the plugin. | ||
disabledCommands: [] | ||
timers: | ||
reviewDelayTolerance: 86000 | ||
taskStaleTimeoutDuration: 2580000 | ||
miscellaneous: | ||
maxConcurrentTasks: 3 | ||
labels: | ||
time: [] | ||
priority: [] | ||
plugins: | ||
- uses: | ||
- plugin: http://localhost:4000 | ||
with: | ||
model: "" | ||
openAiBaseUrl: "" | ||
``` | ||
###### At this stage, your plugin will fire on your defined events with the required settings passed in from the kernel. You can now start writing your plugin's logic. | ||
`.dev.vars` (for local testing): | ||
|
||
5. Start building your plugin by adding your logic to the [plugin.ts](./src/plugin.ts) file. | ||
```sh | ||
# OpenAI API key | ||
OPENAI_API_KEY=your-api-key | ||
UBIQUITY_OS_APP_SLUG="UbiquityOS" | ||
## Testing a plugin | ||
### Worker Plugins | ||
- `yarn/bun worker` - to run the worker locally. | ||
- To trigger the worker, `POST` requests to http://localhost:4000/ with an event payload similar to: | ||
|
||
```ts | ||
await fetch("http://localhost:4000/", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
stateId: "", | ||
eventName: "", | ||
eventPayload: "", | ||
settings: "", | ||
ref: "", | ||
authToken: "", | ||
}), | ||
}); | ||
``` | ||
|
||
A full example can be found [here](https://github.com/ubiquibot/assistive-pricing/blob/623ea3f950f04842f2d003bda3fc7b7684e41378/tests/http/request.http). | ||
|
||
### Action Plugins | ||
|
||
- Ensure the kernel is running and listening for events. | ||
- Fire an event in/to the repo where the kernel is installed. This can be done in a number of ways, the easiest being via the GitHub UI or using the GitHub API, such as posting a comment, opening an issue, etc in the org/repo where the kernel is installed. | ||
- The kernel will process the event and dispatch it using the settings defined in your `.ubiquibot-config.yml`. | ||
- The `compute.yml` workflow will run and execute your plugin's logic. | ||
- You can view the logs in the Actions tab of your repo. | ||
## Testing | ||
|
||
[Nektos Act](https://github.com/nektos/act) - a tool for running GitHub Actions locally. | ||
|
||
## More information | ||
|
||
- [Full Ubiquibot Configuration](https://github.com/ubiquity/ubiquibot/blob/0fde7551585499b1e0618ec8ea5e826f11271c9c/src/types/configuration-types.ts#L62) - helpful for defining your plugin's settings as they are strongly typed and will be validated by the kernel. | ||
- [Ubiquibot V1](https://github.com/ubiquity/ubiquibot) - helpful for porting V1 functionality to V2, helper/utility functions, types, etc. Everything is based on the V1 codebase but with a more modular approach. When using V1 code, keep in mind that most all code will need refactored to work with the new V2 architecture. | ||
|
||
## Examples | ||
|
||
- [Start/Stop Slash Command](https://github.com/ubq-testing/start-stop-module) - simple | ||
- [Assistive Pricing Plugin](https://github.com/ubiquibot/assistive-pricing) - complex | ||
- [Conversation Rewards](https://github.com/ubiquibot/conversation-rewards) - really complex | ||
```sh | ||
yarn test | ||
``` |
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,5 @@ | ||
{ | ||
"name": "command-ask", | ||
"description": "A highly context aware organization integrated chatbot", | ||
"ubiquity:listeners": ["issue_comment.created"] | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.