WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 3230e6f

Browse files
authored
Use builtin OpenAI plugin. Adds tool support. (#18)
* Use builtin OpenAI plugin. Adds tool support. The GitHub Copilot completions (`/chat/completions`) API is based on the OpenAI API regardless of whether the backend model is an OpenAI one or not. This means we can greatly simplify the GitHub Copilot plugin by using the builtin OpenAI plugin (`llm.default_plugins.openai_models`) for everything except for the Copilot device-based authentication. In addition to the significant simplification and code reduction, one key benefit of this approach is that we automatically get additional functionality that is implemented by the openai_models plugin such as tool calling, async, schema/structured output, etc. We should also get any future OpenAI plugin functionality automatically (or with minimal changes). Tests have been updated to remove most of the completion tests since this should now be covered by tests in OpenAI plugin itself. Minor updates were needed to the authentication and the CLI tests to get them to work simplified code base. Finally, the fetch_models_data top-level function (wraps _fetch_models_data) has been memoized so that the model data is cached after the first call. * tests: add mock model data to 3 tests. Make sure the model data comes from the mocked data and not accidentally from an actual connection to GitHub Copilot. This updates these tests: test_prompt, test_model_variants, test_options. * Add Dockerfile and test script for isolated testing. Add a Dockerfile that packages up the code and tests so that they can be executed in an isolated environment. This avoids environmental contamination such as auth config/keys may impact certain code paths succeed when they otherwise shouldn't. Example usage: docker build -t llm-github-copilot-test . docker run -it llm-github-copilot-test * Cleanup _GithubCopilot class inheritance. The _GithubCopilot class was inheriting from openai_models.Chat. The derived classes are where the actual inheritance/mixin should happen. The extra inherit seemed to be harmless for now but could cause problems in the future since it could mix Chat and AsyncChat functionality by accident.
1 parent 5b99b3c commit 3230e6f

File tree

6 files changed

+166
-777
lines changed

6 files changed

+166
-777
lines changed

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM python:3.12-slim
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1 \
4+
PYTHONUNBUFFERED=1
5+
6+
WORKDIR /app
7+
8+
# Install system dependencies for building (if needed)
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
build-essential \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Pre-copy only files needed for dependency resolution
14+
COPY pyproject.toml ./
15+
16+
# Install Python dependencies
17+
RUN pip install --upgrade pip \
18+
&& pip install flake8 pytest \
19+
&& pip install .
20+
21+
# Now copy the rest of the source code
22+
COPY README.md llm_github_copilot.py run-tests.sh ./
23+
COPY tests/ ./tests/
24+
25+
ENV PYTHONPATH=/app
26+
27+
CMD ["/app/run-tests.sh"]
28+

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,11 @@ If you want to record new VCR cassettes for tests, set your API key:
169169
export PYTEST_GITHUB_COPILOT_TOKEN=your_token_here
170170
pytest --vcr-record=new_episodes
171171
```
172+
173+
You can also run the tests in a containerized environment to avoid
174+
contamination from the environment (e.g. auth keys/files):
175+
176+
```
177+
docker build -t llm-github-copilot-test .
178+
docker run -it llm-github-copilot-test
179+
```

0 commit comments

Comments
 (0)