Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Dockerfile and workflow to include version pattern for relea… #2

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/publish_image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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(?<version>\d+\.\d+\.\d+),group=version


- name: Build and push Docker image
id: push
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# openai_api_mock
# 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
```
25 changes: 16 additions & 9 deletions sandbox.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -20,41 +20,48 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"chat_completion = client.chat.completions.create(\n",
" 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",
")"
]
},
{
"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"
}
],
"source": [
"chat_completion.choices"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -73,7 +80,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.12.1"
}
},
"nbformat": 4,
Expand Down
Loading