Skip to content

Commit

Permalink
refactor: improve issue reporting and script finding 🛠️ (#931)
Browse files Browse the repository at this point in the history
* refactor: improve issue reporting and script finding 🛠️

* feat: add tools support flag to model providers 🔧
  • Loading branch information
pelikhan authored Dec 11, 2024
1 parent a89ecbe commit 363644d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 70 deletions.
30 changes: 22 additions & 8 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,25 @@ export const DOCS_WEB_SEARCH_BING_SEARCH_URL =
export const DOCS_WEB_SEARCH_TAVILY_URL =
"https://microsoft.github.io/genaiscript/reference/scripts/web-search/#tavily"

export const MODEL_PROVIDERS: readonly {
id: string
detail: string
url: string
seed?: boolean
logit_bias?: boolean
top_p?: boolean
}[] = Object.freeze([
export const MODEL_PROVIDERS = Object.freeze<
{
id: string
detail: string
url: string
/**
* Supports seed
*/
seed?: boolean
/**
* Supports logit_bias (choices)
*/
logit_bias?: boolean
/**
* Supports tools. Set to false to enable fallbackTools
*/
tools?: boolean
}[]
>([
{
id: MODEL_PROVIDER_OPENAI,
detail: "OpenAI or compatible",
Expand Down Expand Up @@ -288,6 +299,7 @@ export const MODEL_PROVIDERS: readonly {
detail: "Google AI",
url: DOCS_CONFIGURATION_GOOGLE_URL,
seed: false,
tools: false,
},
{
id: MODEL_PROVIDER_HUGGINGFACE,
Expand All @@ -303,6 +315,7 @@ export const MODEL_PROVIDERS: readonly {
id: MODEL_PROVIDER_TRANSFORMERS,
detail: "Hugging Face Transformers",
url: DOCS_CONFIGURATION_HUGGINGFACE_TRANSFORMERS_URL,
tools: true,
},
{
id: MODEL_PROVIDER_OLLAMA,
Expand All @@ -324,6 +337,7 @@ export const MODEL_PROVIDERS: readonly {
id: MODEL_PROVIDER_ALIBABA,
detail: "Alibaba models",
url: DOCS_CONFIGURATION_ALIBABA_URL,
tools: false,
},
{
id: MODEL_PROVIDER_LLAMAFILE,
Expand Down
20 changes: 4 additions & 16 deletions packages/core/src/tools.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import {
MODEL_PROVIDER_ALIBABA,
MODEL_PROVIDER_AZURE_OPENAI,
MODEL_PROVIDER_AZURE_SERVERLESS_MODELS,
MODEL_PROVIDER_GITHUB,
MODEL_PROVIDER_GOOGLE,
MODEL_PROVIDER_OLLAMA,
MODEL_PROVIDER_OPENAI,
MODEL_PROVIDER_TRANSFORMERS,
MODEL_PROVIDERS,
} from "./constants"
import { parseModelIdentifier } from "./models"

export function isToolsSupported(modelId: string): boolean | undefined {
if (!modelId) return undefined
const { provider, model } = parseModelIdentifier(modelId)

if (/^o1-(mini|preview)/.test(model)) {
return false
}

if (provider === MODEL_PROVIDER_TRANSFORMERS) return false
const info = MODEL_PROVIDERS.find(({ id }) => provider === id)
if (info?.tools === false) return false

// https://discuss.ai.google.dev/t/multi-turn-tool-usage-with-gemini-openai/53202
if (provider === MODEL_PROVIDER_GOOGLE) return false
if (/^o1-(mini|preview)/.test(model)) return false

const oai = {
"o1-preview": false,
Expand Down Expand Up @@ -49,15 +43,9 @@ export function isToolsSupported(modelId: string): boolean | undefined {
[MODEL_PROVIDER_OPENAI]: oai,
[MODEL_PROVIDER_AZURE_OPENAI]: oai,
[MODEL_PROVIDER_AZURE_SERVERLESS_MODELS]: oai,
[MODEL_PROVIDER_GOOGLE]: {
// all supported
},
[MODEL_PROVIDER_GITHUB]: {
"Phi-3.5-mini-instruct": false,
},
[MODEL_PROVIDER_ALIBABA]: {
// all supported
},
}

return data[provider]?.[model]
Expand Down
63 changes: 33 additions & 30 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,40 @@ export async function activate(context: ExtensionContext) {
registerCommand("genaiscript.info.env", async () => {
state.host.server.client.infoEnv()
}),
registerCommand("genaiscript.openIssueReporter", async () => {
const issueBody: string[] = [
`## Describe the issue`,
`A clear and concise description of what the bug is.`,
``,
`## To Reproduce`,
`Steps to reproduce the behavior`,
``,
`## Expected behavior`,
`A clear and concise description of what you expected to happen.`,
``,
`## Environment`,
``,
]
issueBody.push(`vscode: ${vscode.version}`)
issueBody.push(
`extension: ${context.extension?.packageJSON?.version || "?"}`
)
if (state.aiRequest?.trace) {
issueBody.push(`## Trace\n\n`)
issueBody.push(state.aiRequest?.trace?.content)
issueBody.push(`\n\n`)
}
await vscode.commands.executeCommand(
"workbench.action.openIssueReporter",
{
extensionId: EXTENSION_ID,
issueBody: issueBody.join("\n"),
registerCommand(
"genaiscript.openIssueReporter",
async (body: string[]) => {
const issueBody: string[] = body || [
`## Describe the issue`,
`A clear and concise description of what the bug is.`,
``,
`## To Reproduce`,
`Steps to reproduce the behavior`,
``,
`## Expected behavior`,
`A clear and concise description of what you expected to happen.`,
``,
]
issueBody.push(
`## Environment`,
``,
`vscode: ${vscode.version}`,
`extension: ${context.extension?.packageJSON?.version || "?"}`
)
if (state.aiRequest?.trace) {
issueBody.push(`## Trace\n\n`)
issueBody.push(state.aiRequest?.trace?.content)
issueBody.push(`\n\n`)
}
)
})
await vscode.commands.executeCommand(
"workbench.action.openIssueReporter",
{
extensionId: EXTENSION_ID,
issueBody: issueBody.join("\n"),
}
)
}
)
)

await state.activate()
Expand Down
53 changes: 37 additions & 16 deletions packages/vscode/src/fragmentcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,41 @@ export function activateFragmentCommands(state: ExtensionState) {

const findScript = (filename: vscode.Uri) => {
const fsPath = state.host.path.resolve(filename.fsPath)
return state.project.scripts
const allScripts = state.project.scripts
const script = allScripts
.filter((p) => !!p.filename)
.find(
(p) =>
state.host.path.resolve(
state.host.projectFolder(),
p.filename
) === fsPath
.find((p) =>
state.host.path.isAbsolute(p.filename)
? p.filename
: state.host.path.resolve(
state.host.projectFolder(),
p.filename
) === fsPath
)

if (!script) {
const reportIssue = "Report Issue"
vscode.window
.showErrorMessage(
`Could not find a GenAiScript ${fsPath}. This is most likely a bug in GenAIScript.`,
"Report Issue"
)
.then((cmd) => {
if (cmd === reportIssue) {
vscode.commands.executeCommand(
"genaiscript.openIssueReporter",
[
`Could not find a GenAiScript issue`,
`Requested script: ${fsPath}`,
`Known scripts:`,
...allScripts.map((s) => s.filename),
]
)
}
})
}

return script
}

const pickTemplate = async (options?: {
Expand Down Expand Up @@ -152,11 +178,9 @@ export function activateFragmentCommands(state: ExtensionState) {
fragment instanceof vscode.Uri &&
GENAI_ANY_REGEX.test(fragment.path)
) {
template = findScript(fragment)
const file = fragment
template = findScript(file)
if (!template) {
vscode.window.showErrorMessage(
`Could not find a GenAiScript ${fragment.fsPath}. This is most likely a bug in GenAIScript.`
)
return
}
fragment = undefined
Expand Down Expand Up @@ -188,9 +212,6 @@ export function activateFragmentCommands(state: ExtensionState) {
if (GENAI_ANY_REGEX.test(file.path)) {
template = findScript(file)
if (!template) {
vscode.window.showErrorMessage(
`Could not find a GenAiScript ${file.fsPath}. This is most likely a bug in GenAIScript.`
)
return
}
files = vscode.window.visibleTextEditors
Expand All @@ -214,7 +235,7 @@ export function activateFragmentCommands(state: ExtensionState) {
),
]
const configuration = cliPath
? <vscode.DebugConfiguration>{
? ((<vscode.DebugConfiguration>{
type: "node",
name: TOOL_NAME,
request: "launch",
Expand All @@ -223,7 +244,7 @@ export function activateFragmentCommands(state: ExtensionState) {
skipFiles: ["<node_internals>/**", dotGenaiscriptPath("**")],

args: [cliPath, ...args],
} satisfies vscode.DebugConfiguration
}) satisfies vscode.DebugConfiguration)
: <vscode.DebugConfiguration>{
type: "node",
name: TOOL_NAME,
Expand Down

0 comments on commit 363644d

Please sign in to comment.