Skip to content

Commit f73e74e

Browse files
committed
Adding chatops aliases, unit tests, misc corrections
1 parent 3646388 commit f73e74e

File tree

9 files changed

+106
-1
lines changed

9 files changed

+106
-1
lines changed

openai/.github/CODEOWNERS

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence, users and
6+
# teams which are put in owners will be requested for review
7+
# when someone opens a pull request.
8+
9+
# This is base configuration. These owners could review the
10+
# whole file in this repository.
11+
* @dalarsen @StackStorm-Exchange/tsc @floatingstatic
12+
13+
# CI configuration files should be reviewed by specific owners
14+
# who are more responsible for ensuring the quality of this pack
15+
# or orchestrate StackStorm-Exchanges.
16+
.circleci/** @StackStorm-Exchange/tsc

openai/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## v0.1.0
4+
5+
* Initial release

openai/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ The configuration schema contains two attributes:
1313

1414
* `chat_completion` - Perform a chat completion query (text-based "chat" query)
1515
* `image_generation` - Request a OpenAI generative graphical image
16+
17+
## Maintainers
18+
Active pack maintainers with review & write repository access:
19+
* Dave Larsen ([@dalarsen](https://github.com/dalarsen))

openai/aliases/chat_completion.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: openai_chat_completion
3+
action_ref: openai.chat_completion
4+
description: Make a chat completion query to the OpenAI API
5+
formats:
6+
- "ask chatgpt {{query}}"
7+
ack:
8+
format: "Sending your ChatGPT chat completion query now, please wait..."
9+
enabled: true
10+
result:
11+
format: |
12+
Response from OpenAI for the ChatGPT chat completion query {{execution.parameters.question}}:
13+
14+
{% if execution.status == 'succeeded' %}
15+
{% for choice in execution.result.result.choices %}
16+
-----
17+
{{ choice.message.content }}
18+
{% endfor %}
19+
{% else %}
20+
Query to OpenAI failed: {{execution}}
21+
{% endif %}

openai/aliases/image_generation.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: openai_image_generation
3+
action_ref: openai.image_generation
4+
description: Make an image generation query to the OpenAI API
5+
formats:
6+
- "ask dall-e {{query}}"
7+
ack:
8+
format: "Sending your DALL-E image generation query now, please wait..."
9+
enabled: true
10+
result:
11+
format: |
12+
Response from OpenAI for the DALL-E image generation query {{execution.parameters.question}}:
13+
14+
{% if execution.status == 'succeeded' %}
15+
{{ execution.result.result.data }}
16+
{% else %}
17+
Query to OpenAI failed: {{execution}}
18+
{% endif %}

openai/openai.yaml.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
openai_token: 'abcdefghikjl1234567890'
3+
openai_org: 'nobody_org'

openai/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
openai
1+
openai == 0.27.8
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from st2tests.base import BaseActionTestCase
2+
from openai.openai_object import OpenAIObject
3+
4+
import chat_completion
5+
import mock
6+
7+
__all__ = ["TestChatCompletion"]
8+
9+
10+
class TestChatCompletion(BaseActionTestCase):
11+
action_cls = chat_completion.ChatCompletion
12+
13+
@mock.patch("chat_completion.openai.ChatCompletion.create")
14+
def test_chat_completion_makes_valid_chat_completion_request(self, mock_openai):
15+
mock_openai.return_value = OpenAIObject()
16+
action = self.get_action_instance()
17+
action.run("fake query", "mock_model")
18+
mock_openai.assert_called_with(
19+
model="mock_model", messages=[{"role": "user", "content": "fake query"}]
20+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from st2tests.base import BaseActionTestCase
2+
from openai.openai_object import OpenAIObject
3+
4+
import image_generation
5+
import mock
6+
7+
__all__ = ["TestChatCompletion"]
8+
9+
10+
class TestChatCompletion(BaseActionTestCase):
11+
action_cls = image_generation.ImageGeneration
12+
13+
@mock.patch("chat_completion.openai.Image.create")
14+
def test_image_generation_makes_valid_image_generation_request(self, mock_openai):
15+
mock_openai.return_value = OpenAIObject()
16+
action = self.get_action_instance()
17+
action.run("fake query", "512x512")
18+
mock_openai.assert_called_with(prompt="fake query", size="512x512")

0 commit comments

Comments
 (0)