-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
232 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Generate Config Schema | ||
description: Generate the JSON schema for operagents config | ||
|
||
inputs: | ||
output-path: | ||
description: Output path for the generated schema | ||
required: false | ||
default: "operagents/config/operagents.schema.json" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Generate | ||
run: | | ||
poetry run python ./scripts/generate_config_schema.py {{ inputs.output-path }} | ||
echo "output-path={{ inputs.output-path }}" >> "$GITHUB_OUTPUT" | ||
shell: bash |
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,24 @@ | ||
name: Setup Python | ||
description: Setup Python | ||
|
||
inputs: | ||
python-version: | ||
description: Python version | ||
required: false | ||
default: "3.10" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install poetry | ||
run: pipx install poetry | ||
shell: bash | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
architecture: "x64" | ||
cache: "poetry" | ||
|
||
- run: poetry install | ||
shell: bash |
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,60 @@ | ||
name: GitHub Pages | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
generate-config-schema: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Python environment | ||
uses: ./.github/actions/setup-python | ||
|
||
- name: Generate | ||
id: generate-schema | ||
uses: ./.github/actions/generate-schema | ||
|
||
- name: Upload | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: operagents-config-schema | ||
path: ${{ steps.generate-schema.outputs.output-path }} | ||
retention-days: 1 | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
needs: generate-config-schema | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: gh-pages | ||
fetch-depth: 1 | ||
|
||
- name: Download Schema | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: operagents-config-schema | ||
path: schemas/ | ||
|
||
- name: Upload GitHub Pages artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
if: ${{ github.event_name == 'push' }} | ||
permissions: | ||
pages: write | ||
id-token: write | ||
environment: | ||
name: website | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: Deploy GitHub Pages site | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
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 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
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,11 +1,61 @@ | ||
import abc | ||
from typing import ClassVar | ||
from typing import Literal, ClassVar, TypeAlias | ||
from typing_extensions import Required, TypedDict | ||
|
||
|
||
class Function(TypedDict): | ||
name: str | ||
"""The name of the function to call.""" | ||
arguments: str | ||
""" | ||
The arguments to call the function with, as generated by the model in JSON | ||
format. Note that the model does not always generate valid JSON, and may | ||
hallucinate parameters not defined by your function schema. Validate the | ||
arguments in your code before calling your function. | ||
""" | ||
|
||
|
||
class MessageToolCall(TypedDict): | ||
type: Literal["function"] | ||
"""The type of the tool. Currently, only `function` is supported.""" | ||
id: str | ||
"""The ID of the tool call.""" | ||
function: Function | ||
"""The function that the model called.""" | ||
|
||
|
||
class SystemMessage(TypedDict): | ||
role: Literal["system"] | ||
"""The role of the messages author, in this case `system`.""" | ||
content: str | ||
"""The contents of the system message.""" | ||
|
||
|
||
class UserMessage(TypedDict): | ||
role: Literal["user"] | ||
"""The role of the messages author, in this case `user`.""" | ||
content: str | ||
"""The contents of the user message.""" | ||
|
||
|
||
class AssistantMessage(TypedDict, total=False): | ||
role: Required[Literal["assistant"]] | ||
"""The role of the messages author, in this case `assistant`.""" | ||
content: str | None | ||
"""The contents of the assistant message. | ||
Required unless `tool_calls` is specified. | ||
""" | ||
tool_calls: list[MessageToolCall] | ||
"""The tool calls generated by the model, such as function calls.""" | ||
|
||
|
||
Message: TypeAlias = SystemMessage | UserMessage | AssistantMessage | ||
|
||
|
||
class Backend(abc.ABC): | ||
type_: ClassVar[str] | ||
|
||
# TODO: messages | ||
@abc.abstractmethod | ||
async def generate(self, messages: list) -> str: | ||
async def generate(self, messages: list[Message]) -> str: | ||
raise NotImplementedError |
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,11 +1,20 @@ | ||
from typing_extensions import override | ||
|
||
from ._base import Backend | ||
from noneprompt import InputPrompt, CancelledError | ||
|
||
from operagents.log import logger | ||
from operagents.exception import OperaFinished | ||
|
||
from ._base import Backend, Message | ||
|
||
|
||
class UserBackend(Backend): | ||
type_ = "user" | ||
|
||
@override | ||
async def generate(self, messages: list) -> str: | ||
return input("You: ") | ||
async def generate(self, messages: list[Message]) -> str: | ||
try: | ||
return await InputPrompt("You: ").prompt_async() | ||
except CancelledError: | ||
await logger.ainfo("User cancelled input.") | ||
raise OperaFinished() from None |
Oops, something went wrong.