From 953c1061694c6907bace5fb79a9847ae5084e02d Mon Sep 17 00:00:00 2001 From: Sander Niels Hummerich <64867257+hummerichsander@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:35:11 +0000 Subject: [PATCH] Refactor Dockerfile and workflow to include version pattern for release branches --- .github/workflows/publish_image.yaml | 4 ++++ README.md | 15 ++++++++++++++- sandbox.ipynb | 25 ++++++++++++++++--------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish_image.yaml b/.github/workflows/publish_image.yaml index e81f323..5a3b652 100644 --- a/.github/workflows/publish_image.yaml +++ b/.github/workflows/publish_image.yaml @@ -35,6 +35,10 @@ jobs: uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=branch,pattern=release/v(?\d+\.\d+\.\d+),group=version + - name: Build and push Docker image id: push diff --git a/README.md b/README.md index cd0beb4..16df7d1 100644 --- a/README.md +++ b/README.md @@ -1 +1,14 @@ -# openai_api_mock \ No newline at end of file +# OpenAI API server mockup +This is a simple fastapi based server mock that implements the OpenAI API. + +Available endpoints: +- /v1/chat/completion + +Instead of running a LLM model to generate completions, it simply returns a response generated by surrogate models. Available surrogate models are: +- "yes_no": returns random "yes" or "no" response +- "lorem_ipsum": returns random "lorem ipsum" text + +## Run via docker: +```bash +docker pull ghcr.io/hummerichsander/openai_api_server_mock:v ... # replace ... with the latest version +``` diff --git a/sandbox.ipynb b/sandbox.ipynb index 8e331ff..1d04f78 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 23, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -28,9 +28,9 @@ " model=\"yes_no\",\n", " messages=[\n", " {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n", - " {\"role\": \"user\", \"content\": \"was geht ab?\"}\n", + " {\"role\": \"user\", \"content\": \"Is the sky blue?\"}\n", " ],\n", - " max_tokens=3,\n", + " max_tokens=1,\n", " logprobs=True,\n", " top_logprobs=3,\n", ")" @@ -38,16 +38,16 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[Choice(finish_reason='stop', index=0, logprobs=ChoiceLogprobs(content=[ChatCompletionTokenLogprob(token='No', bytes=None, logprob=-0.07924283253114733, top_logprobs=[TopLogprob(token='No', bytes=None, logprob=-0.10242905896332069), TopLogprob(token='Yes', bytes=None, logprob=-1.2416030261034656), TopLogprob(token='No', bytes=None, logprob=-0.8485894646489763)])], refusal=None), message=ChatCompletionMessage(content='No', refusal=None, role='assistant', function_call=None, tool_calls=None, name=None))]" + "[Choice(finish_reason='stop', index=0, logprobs=ChoiceLogprobs(content=[ChatCompletionTokenLogprob(token='No', bytes=None, logprob=-0.4558056105339685, top_logprobs=[TopLogprob(token='Yes', bytes=None, logprob=-2.1267604392490442), TopLogprob(token='No', bytes=None, logprob=-0.7188313398698458), TopLogprob(token='Yes', bytes=None, logprob=-3.7428107344910946)])], refusal=None), message=ChatCompletionMessage(content='Yes', refusal=None, role='assistant', function_call=None, tool_calls=None, name=None))]" ] }, - "execution_count": 31, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -55,6 +55,13 @@ "source": [ "chat_completion.choices" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -73,7 +80,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.12.1" } }, "nbformat": 4,