-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: boost - custom modules, intermediate outputs, output styles, ap…
…i keys, model filters, more feat: bench - docker builds chore: v0.1.31 bump
- Loading branch information
Showing
22 changed files
with
1,315 additions
and
285 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,89 @@ | ||
name: Harbor Bench Docker image | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- 'main' | ||
paths: | ||
- bench/** | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
env: | ||
DOCKER_REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }}-bench | ||
TAG: ${{ github.sha }} | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Free Disk Space Before Build | ||
run: | | ||
sudo rm -rf /usr/local/.ghcup | ||
sudo rm -rf /opt/hostedtoolcache/CodeQL | ||
sudo rm -rf /usr/local/lib/android | ||
sudo rm -rf /usr/share/dotnet | ||
sudo rm -rf /opt/ghc | ||
sudo rm -rf /usr/local/share/boost | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
# Log in to the GitHub Container Registry only when not running on a pull request event | ||
- name: Login to Docker Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.DOCKER_REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Debug | ||
run: | | ||
echo "PWD" | ||
pwd | ||
echo "Workspace" | ||
ls -la | ||
echo "Bench" | ||
ls -la ./bench | ||
# Build and push the Docker image to GHCR for the main branch or specific tags | ||
- name: Build and Push Docker Image | ||
if: github.ref == 'refs/heads/main' | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ./bench | ||
file: bench/Dockerfile | ||
push: true | ||
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest | ||
labels: version=${{ github.run_id }} | ||
platforms: linux/amd64,linux/arm64 | ||
|
||
# For tagged releases, build and push the Docker image with the corresponding tag | ||
- name: Build and Push Docker Image (Tagged) | ||
if: startsWith(github.ref, 'refs/tags/') | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ./bench | ||
file: bench/Dockerfile | ||
push: true | ||
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} | ||
labels: version=${{ github.run_id }} | ||
platforms: linux/amd64,linux/arm64 |
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,90 @@ | ||
import random | ||
|
||
from typing import List, Optional | ||
import log | ||
|
||
logger = log.setup_logger(__name__) | ||
|
||
class ChatNode: | ||
id: str | ||
content: str | ||
role: str | ||
|
||
parent: Optional['ChatNode'] | ||
children: List['ChatNode'] | ||
|
||
visits: int | ||
value: float | ||
meta: dict | ||
|
||
def from_conversation(messages): | ||
root_message = messages[0] | ||
node = ChatNode(role=root_message['role'], content=root_message['content']) | ||
|
||
for message in messages[1:]: | ||
node = node.add_child( | ||
ChatNode(role=message['role'], content=message['content']) | ||
) | ||
|
||
return node | ||
|
||
def __init__(self, **kwargs): | ||
self.id = ''.join( | ||
random.choices('abcdefghijklmnopqrstuvwxyz0987654321', k=4) | ||
) | ||
self.content = kwargs.get('content', '') | ||
self.role = kwargs.get('role', '') | ||
|
||
self.parent = kwargs.get('parent', None) | ||
self.children = kwargs.get('children', []) | ||
|
||
self.visits = kwargs.get('visits', 0) | ||
self.value = kwargs.get('value', 0.0) | ||
|
||
self.meta = kwargs.get('meta', {}) | ||
|
||
def add_parent(self, parent: 'ChatNode'): | ||
parent.children.append(self) | ||
self.parent = parent | ||
return self | ||
|
||
def add_child(self, child: 'ChatNode'): | ||
child.parent = self | ||
self.children.append(child) | ||
return child | ||
|
||
def best_child(self): | ||
if not self.children: | ||
return self | ||
return max(self.children, key=lambda c: c.value).best_child() | ||
|
||
def contains(self, substring): | ||
return substring.lower() in self.content.lower() | ||
|
||
def parents(self): | ||
parents = [self] | ||
|
||
while self.parent: | ||
self = self.parent | ||
parents.append(self) | ||
|
||
return parents[::-1] | ||
|
||
def history(self): | ||
node = self | ||
messages = [{ | ||
"role": node.role, | ||
"content": node.content, | ||
}] | ||
|
||
while node.parent: | ||
node = node.parent | ||
messages.append({ | ||
"role": node.role, | ||
"content": node.content, | ||
}) | ||
|
||
return messages[::-1] | ||
|
||
def __str__(self): | ||
return f"{self.role}: {self.content}" |
Oops, something went wrong.