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

github models support #600

Merged
merged 5 commits into from
Aug 2, 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: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"dbaeumer.vscode-eslint",
"bierner.markdown-mermaid",
"yoavbls.pretty-ts-errors",
"kejun.markdown-alert",
"astro-build.astro-vscode",
"unifiedjs.vscode-mdx",
"streetsidesoftware.code-spell-checker",
Expand All @@ -18,8 +17,9 @@
}
},
"features": {
"ghcr.io/ghcr.io/devcontainers/features/github-cli:1.0.13": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/azure-cli:1.2.5": {},
"ghcr.io/devcontainers/features/python:1.6.2": {}
"ghcr.io/devcontainers/features/python:1.6.3": {}
}
}
43 changes: 43 additions & 0 deletions .github/workflows/github-models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: github models smoke tests
on:
workflow_dispatch:
pull_request:
paths:
- yarn.lock
- ".github/workflows/github-models.yml"
- "packages/core/**/*"
- "packages/cli/**/*"
- "packages/samples/**/*"
push:
branches:
- main
paths:
- yarn.lock
- ".github/workflows/github-models.yml"
- "packages/core/**/*"
- "packages/cli/**/*"
- "packages/samples/**/*"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-github-models
cancel-in-progress: true
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: yarn
- run: yarn install --frozen-lockfile
- name: typecheck
run: yarn typecheck
- name: compile
run: yarn compile
- name: run summarize github-gpt4o
run: yarn test:summarize --model github:gpt-4o --out ./temp
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 46 additions & 1 deletion docs/src/content/docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,51 @@ GENAISCRIPT_DEFAULT_MODEL=openai:gpt-4o

:::

## GitHub Models
<a id="github" href=""></a>

The [GitHub Models](https://github.com/marketplace/models) provider, `github`, allows running models through the GitHub Marketplace.
This provider is useful for prototyping and subject to [rate limits](https://docs.github.com/en/github-models/prototyping-with-ai-models#rate-limits)
depending on your subscription.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link provided for "GitHub Models" does not have a URL, it should point to the actual resource.

generated by pr-docs-review-commit broken_link


<Steps>

<ol>

<li>

Open the [GitHub Marketplace](https://github.com/marketplace/models) and find the model you want to use.

</li>

<li>

Click **Get Started** and follow the instructions to configure the github token, or start a codespace!
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instruction "Click Get Started and follow the instructions to configure the github token, or start a codespace!" is ambiguous. It should clarify whether configuring the GitHub token and starting a codespace are two separate options or part of the same process.

generated by pr-docs-review-commit ambiguous_instruction


</li>

<li>

Copy the model name from the Javascript/Python samples

```js "Phi-3-mini-4k-instruct"
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
const modelName = "Phi-3-mini-4k-instruct";
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code block is incorrectly annotated with "js" and a string "Phi-3-mini-4k-instruct" which seems to be a mistake. The code block should only specify the language (js) without the model name string.

generated by pr-docs-review-commit incorrect_code_fence


to configure your script.

```js
script({
model: "github:Phi-3-mini-4k-instruct"
})
```
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

</li>

</ol>

</Steps>

## Azure OpenAI
<a id="azure" href=""></a>

Expand Down Expand Up @@ -269,7 +314,7 @@ script({

</Steps>

## GitHub Copilot Models
## GitHub Copilot in Visual Studio Code
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section title "GitHub Copilot Models" has been changed to "GitHub Copilot in Visual Studio Code" which might imply a change in content scope or focus. Ensure that the content of the section aligns with the new title.

generated by pr-docs-review-commit section_renaming


If you have access to **GitHub Copilot in Visual Studio Code**,
GenAIScript will be able to leverage those [language models](https://code.visualstudio.com/api/extension-guides/language-model) as well.
Expand Down
31 changes: 31 additions & 0 deletions packages/core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import {
DEFAULT_TEMPERATURE,
DOCS_CONFIGURATION_AICI_URL,
DOCS_CONFIGURATION_AZURE_OPENAI_URL,
DOCS_CONFIGURATION_GITHUB_URL,
DOCS_CONFIGURATION_LITELLM_URL,
DOCS_CONFIGURATION_LLAMAFILE_URL,
DOCS_CONFIGURATION_LOCALAI_URL,
DOCS_CONFIGURATION_OLLAMA_URL,
DOCS_CONFIGURATION_OPENAI_URL,
DOT_ENV_FILENAME,
GITHUB_MODELS_BASE,
LITELLM_API_BASE,
LLAMAFILE_API_BASE,
LOCALAI_API_BASE,
MODEL_PROVIDER_AICI,
MODEL_PROVIDER_AZURE,
MODEL_PROVIDER_CLIENT,
MODEL_PROVIDER_GITHUB,
MODEL_PROVIDER_LITELLM,
MODEL_PROVIDER_LLAMAFILE,
MODEL_PROVIDER_OLLAMA,
Expand Down Expand Up @@ -99,6 +102,24 @@ export async function parseTokenFromEnv(
}
}

if (provider === MODEL_PROVIDER_GITHUB) {
const token = env.GITHUB_TOKEN
if (!token) throw new Error("GITHUB_TOKEN must be set")
const type = "openai"
const base = GITHUB_MODELS_BASE
return {
provider,
model,
base,
type,
token,
source: "env: GITHUB_TOKEN",
curlHeaders: {
Authorization: `Bearer $GITHUB_TOKEN`,
Dismissed Show dismissed Hide dismissed
},
}
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
}

if (provider === MODEL_PROVIDER_AZURE) {
const tokenVar = env.AZURE_OPENAI_API_KEY
? "AZURE_OPENAI_API_KEY"
Expand Down Expand Up @@ -298,6 +319,16 @@ OPENAI_API_TYPE="localai"
model: `${MODEL_PROVIDER_OPENAI}:gpt-3.5-turbo`,
}

if (provider === MODEL_PROVIDER_GITHUB)
return {
config: `
## GitHub Models ${DOCS_CONFIGURATION_GITHUB_URL}
# use "${MODEL_PROVIDER_GITHUB}:<model>" in script({ model: ... })
GITHUB_TOKEN="${PLACEHOLDER_API_KEY}"
`,
model: `${MODEL_PROVIDER_GITHUB}:gpt-4o`,
}
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string GITHUB_TOKEN="${PLACEHOLDER_API_KEY}" is hardcoded. This could lead to issues if the token needs to be changed or updated. Consider using a constant or a configuration file to store such values. 🔄

generated by pr-review-commit hardcoded_string


return {
config: `
## OpenAI ${DOCS_CONFIGURATION_OPENAI_URL}
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const EMOJI_FAIL = "❌"
export const EMOJI_UNDEFINED = "?"

export const MODEL_PROVIDER_OPENAI = "openai"
export const MODEL_PROVIDER_GITHUB = "github"
export const MODEL_PROVIDER_AZURE = "azure"
export const MODEL_PROVIDER_OLLAMA = "ollama"
export const MODEL_PROVIDER_LLAMAFILE = "llamafile"
Expand All @@ -98,12 +99,16 @@ export const MODEL_PROVIDER_CLIENT = "client"

export const TRACE_FILE_PREVIEW_MAX_LENGTH = 240

export const GITHUB_MODELS_BASE = "https://models.inference.ai.azure.com"
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

pelikhan marked this conversation as resolved.
Show resolved Hide resolved
export const DOCS_CONFIGURATION_URL =
"https://microsoft.github.io/genaiscript/getting-started/configuration/"
export const DOCS_CONFIGURATION_OPENAI_URL =
"https://microsoft.github.io/genaiscript/getting-started/configuration/#openai"
export const DOCS_CONFIGURATION_GITHUB_URL =
"https://microsoft.github.io/genaiscript/getting-started/configuration/#github"
export const DOCS_CONFIGURATION_AZURE_OPENAI_URL =
"https://microsoft.github.io/genaiscript/getting-started/configuration/#azure-openai"
"https://microsoft.github.io/genaiscript/getting-started/configuration/#azure"
export const DOCS_CONFIGURATION_OLLAMA_URL =
"https://microsoft.github.io/genaiscript/getting-started/configuration/#ollama"
export const DOCS_CONFIGURATION_LLAMAFILE_URL =
Expand All @@ -121,6 +126,11 @@ export const MODEL_PROVIDERS = Object.freeze([
detail: "OpenAI or compatible",
url: DOCS_CONFIGURATION_OPENAI_URL,
},
{
id: MODEL_PROVIDER_GITHUB,
detail: "GitHub Models",
url: DOCS_CONFIGURATION_GITHUB_URL,
},
{
id: MODEL_PROVIDER_AZURE,
detail: "Azure OpenAI deployment",
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parseModelIdentifier } from "./models"
import assert from "node:assert"
import {
MODEL_PROVIDER_AICI,
MODEL_PROVIDER_GITHUB,
MODEL_PROVIDER_LLAMAFILE,
MODEL_PROVIDER_OLLAMA,
MODEL_PROVIDER_OPENAI,
Expand Down Expand Up @@ -38,6 +39,12 @@ describe("parseModelIdentifier", () => {
assert(family === "*")
assert(model === "llamafile")
})
test("github:gpt4", () => {
const { provider, model, family } = parseModelIdentifier("github:gpt4")
assert(provider === MODEL_PROVIDER_GITHUB)
assert(model === "gpt4")
assert(family === "gpt4")
})
test("gpt4", () => {
const { provider, model, family } = parseModelIdentifier("gpt4")
assert(provider === MODEL_PROVIDER_OPENAI)
Expand Down
6 changes: 6 additions & 0 deletions packages/vscode/src/lmaccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
MODEL_PROVIDER_LITELLM,
MODEL_PROVIDER_OPENAI,
MODEL_PROVIDER_CLIENT,
MODEL_PROVIDER_GITHUB,
} from "../../core/src/constants"
import { APIType } from "../../core/src/host"
import { parseModelIdentifier } from "../../core/src/models"
Expand Down Expand Up @@ -64,6 +65,11 @@ async function generateLanguageModelConfiguration(
provider: MODEL_PROVIDER_AZURE,
apiType: "azure",
},
{
label: "GitHub Models",
detail: `Use a GitHub Models with a GitHub subscription.`,
provider: MODEL_PROVIDER_GITHUB,
},
{
label: "LocalAI",
description: "https://localai.io/",
Expand Down
Loading