Skip to content

Commit

Permalink
feat: add provider for github models
Browse files Browse the repository at this point in the history
  • Loading branch information
Realiserad committed Oct 5, 2024
1 parent 4dcf3a1 commit 62c4cf6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions .devcontainer/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ iterfzf
hugchat
mistralai
binaryornot
azure-ai-inference
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Python and git is installed.
Originally based on [Tom Dörr's `fish.codex` repository](https://github.com/tom-doerr/codex.fish),
but with some additional functionality.

It can be hooked up to OpenAI, Azure OpenAI, Google, Hugging Face, Mistral or a
self-hosted LLM behind any OpenAI-compatible API.
It can be hooked up to OpenAI, Azure OpenAI, Google, Hugging Face, Mistral,
GitHub or a self-hosted LLM behind any OpenAI-compatible API.

If you like it, please add a ⭐. If you don't like it, create a PR. 😆

Expand Down Expand Up @@ -118,6 +118,21 @@ provider = mistral
api_key = <your API key>
```

If you use [GitHub Models](https://github.com/marketplace/models):

```ini
[fish-ai]
configuration = github

[github]
provider = github
api_key = <GitHub PAT>
model = Meta-Llama-3.1-70B-Instruct
```

You can create a personal access token (PAT) [here](https://github.com/settings/tokens).
The PAT does not require any permissions.

### Install `fish-ai`

Install the plugin. You can install it using [`fisher`](https://github.com/jorgebucaran/fisher).
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "fish_ai"
version = "0.9.10"
version = "0.10.0"
authors = [{ name = "Bastian Fredriksson", email = "realiserad@gmail.com" }]
description = "Provides core functionality for fish-ai, an AI plugin for the fish shell."
readme = "README.md"
Expand All @@ -22,6 +22,7 @@ dependencies = [
"hugchat==0.4.11",
"mistralai==1.0.2",
"binaryornot==0.4.4",
"azure-ai-inference==1.0.0b4",
]

[project.urls]
Expand Down
15 changes: 15 additions & 0 deletions src/fish_ai/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from mistralai import Mistral
from fish_ai.redact import redact
import itertools
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential

config = ConfigParser()
config.read(path.expanduser('~/.config/fish-ai.ini'))
Expand Down Expand Up @@ -249,6 +251,19 @@ def get_response(messages):
temperature=float(get_config('temperature') or '0.2'),
)
response = completions.choices[0].message.content.strip(' `')
elif get_config('provider') == 'github':
client = ChatCompletionsClient(
endpoint='https://models.inference.ai.azure.com',
credential=AzureKeyCredential(get_config('api_key')),
)

completions = client.complete(
messages=messages,
model=get_config('model') or 'Meta-Llama-3.1-70B-Instruct',
temperature=float(get_config('temperature') or '0.2'),
max_tokens=1024
)
response = completions.choices[0].message.content.strip(' `')
else:
completions = get_openai_client().chat.completions.create(
model=get_config('model') or 'gpt-4o',
Expand Down

0 comments on commit 62c4cf6

Please sign in to comment.