forked from 0ai-Cyberviser/Hancock
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub_models_backend.py
More file actions
23 lines (20 loc) · 879 Bytes
/
Copy pathgithub_models_backend.py
File metadata and controls
23 lines (20 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from azure.ai.inference import ChatCompletionsClient
from azure.ai.inference.models import SystemMessage, UserMessage
from azure.core.credentials import AzureKeyCredential
def github_models_chat(prompt: str, model: str = "gpt-4o-mini", max_tokens: int = 2000) -> str:
"""GitHub Models backend - free-tier gpt-4o-mini"""
token = os.getenv("GITHUB_TOKEN")
if not token:
raise ValueError("Set GITHUB_TOKEN env var")
client = ChatCompletionsClient(
endpoint="https://models.github.ai/inference",
credential=AzureKeyCredential(token),
)
response = client.complete(
messages=[SystemMessage("You are Hancock, elite cybersecurity specialist by CyberViser."), UserMessage(prompt)],
temperature=0.7,
max_tokens=max_tokens,
model=model
)
return response.choices[0].message.content