Skip to content

Commit

Permalink
fixing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 7, 2024
1 parent bd87a35 commit 1bd1037
Show file tree
Hide file tree
Showing 24 changed files with 217 additions and 220 deletions.
5 changes: 4 additions & 1 deletion packages/cli/src/nodehost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { createNodePath } from "./nodepath"
import { DockerManager } from "./docker"
import { DefaultAzureCredential, AccessToken } from "@azure/identity"
import { LanguageModel } from "../../core/src/chat"
import {
parseDefaultsFromEnv,
parseTokenFromEnv,
} from "../../core/src/connection"
import {
DEFAULT_MODEL,
DEFAULT_TEMPERATURE,
Expand All @@ -36,7 +40,6 @@ import { resolveLanguageModel } from "../../core/src/models"
import { createBundledParsers } from "../../core/src/pdf"
import { AbortSignalOptions, TraceOptions } from "../../core/src/trace"
import { unique } from "../../core/src/util"
import { parseGHTokenFromEnv } from "../../core/src/github"

class NodeServerManager implements ServerManager {
async start(): Promise<void> {
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { WebSocketServer } from "ws"
import { runPromptScriptTests } from "./test"
import { PROMPTFOO_VERSION } from "./version"
import { runScript } from "./run"
import { ServerResponse } from "http"
import { AbortSignalCancellationController } from "../../core/src/cancellation"
import {
SERVER_PORT,
Expand All @@ -16,11 +15,18 @@ import {
errorMessage,
serializeError,
} from "../../core/src/error"
import { ResponseStatus, host } from "../../core/src/host"
import { ResponseStatus, ServerResponse, host } from "../../core/src/host"
import { MarkdownTrace, TraceChunkEvent } from "../../core/src/trace"
import { logVerbose, logError } from "../../core/src/util"
import { CORE_VERSION } from "../../core/src/version"
import { YAMLStringify } from "../../core/src/yaml"
import {
RequestMessages,
PromptScriptProgressResponseEvent,
PromptScriptEndResponseEvent,
ContainerStartResponse,
ShellExecResponse,
} from "../../core/src/server/messages"

export async function startServer(options: { port: string }) {
const port = parseInt(options.port) || SERVER_PORT
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import {
delay,
} from "../../core/src/util"
import { YAMLStringify } from "../../core/src/yaml"
import {
PromptScriptTestRunOptions,
PromptScriptTestRunResponse,
PromptScriptTestResult,
} from "../../core/src/server/messages"
import { generatePromptFooConfiguration } from "../../core/src/test"

function parseModelSpec(m: string): ModelOptions {
const values = parseKeyValuePairs(m)
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/src/airequesttree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
AIRequestSnapshotKey,
ExtensionState,
} from "./state"
import { CACHE_AIREQUEST_PREFIX, CHANGE, CacheEntry } from "genaiscript-core"
import { JSONLineCache } from "genaiscript-core"
import { infoUri } from "./markdowndocumentprovider"
import { toMarkdownString } from "./markdown"
import { CacheEntry, JSONLineCache } from "../../core/src/cache"
import { CHANGE, CACHE_AIREQUEST_PREFIX } from "../../core/src/constants"

type AIRequestTreeNode = CacheEntry<AIRequestSnapshotKey, AIRequestSnapshot>

Expand Down
3 changes: 2 additions & 1 deletion packages/vscode/src/azuremanager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AZURE_OPENAI_TOKEN_SCOPES } from "../../core/src/constants"
import { errorMessage } from "../../core/src/error"
import { ExtensionState } from "./state"
import * as vscode from "vscode"
import { AZURE_OPENAI_TOKEN_SCOPES, errorMessage } from "genaiscript-core"

export class AzureManager {
private _session: vscode.AuthenticationSession
Expand Down
3 changes: 2 additions & 1 deletion packages/vscode/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { errorMessage, TOOL_NAME } from "genaiscript-core"
import * as vscode from "vscode"
import { TOOL_NAME } from "../../core/src/constants"
import { errorMessage } from "../../core/src/error"

export function registerCommand(
id: string,
Expand Down
31 changes: 14 additions & 17 deletions packages/vscode/src/docsnotebook.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import * as vscode from "vscode"
import { ExtensionState } from "./state"
import { Utils } from "vscode-uri"
import { registerCommand } from "./commands"
import { renderMessagesToMarkdown } from "../../core/src/chat"
import {
details,
Fragment,
MARKDOWN_MIME_TYPE,
TOOL_NAME,
renderMessagesToMarkdown,
YAMLStringify,
parsePromptScriptMeta,
EMOJI_FAIL,
errorMessage,
MDX_REGEX,
frontmatterTryParse,
YAMLTryParse,
arrayify,
parseKeyValuePairs,
parseBoolean,
} from "genaiscript-core"
import { Utils } from "vscode-uri"
import { register } from "tsx/cjs/api"
import { registerCommand } from "./commands"
EMOJI_FAIL,
MARKDOWN_MIME_TYPE,
} from "../../core/src/constants"
import { errorMessage } from "../../core/src/error"
import { parseKeyValuePairs } from "../../core/src/fence"
import { frontmatterTryParse } from "../../core/src/frontmatter"
import { details } from "../../core/src/markdown"
import { parsePromptScriptMeta } from "../../core/src/template"
import { arrayify, parseBoolean } from "../../core/src/util"
import { YAMLTryParse, YAMLStringify } from "../../core/src/yaml"
import { Fragment } from "../../core/src/promptrunner"

// parser
// https://raw.githubusercontent.com/microsoft/vscode-markdown-notebook/main/src/markdownParser.ts
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/src/edit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode"
import { Fragment, eolPosition } from "genaiscript-core"
import { ExtensionState } from "./state"
import { eolPosition } from "../../core/src/ast"

export function toPos(p: CharPosition | number) {
if (typeof p === "number") return new vscode.Position(p, 0)
Expand Down
105 changes: 47 additions & 58 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as vscode from "vscode"
import { ExtensionContext } from "vscode"
import { ExtensionState } from "./state"
import { activateStatusBar } from "./statusbar"
import { EXTENSION_ID, TOOL_NAME } from "genaiscript-core"
import { activateFragmentCommands } from "./fragmentcommands"
import { activateMarkdownTextDocumentContentProvider } from "./markdowndocumentprovider"
import { activatePrompTreeDataProvider } from "./prompttree"
Expand All @@ -14,6 +13,7 @@ import { activateModelCompletionProvider } from "./modelcompletionprovider"
import { activateDocsNotebook } from "./docsnotebook"
import { activateTraceTreeDataProvider } from "./tracetree"
import { registerCommand } from "./commands"
import { EXTENSION_ID, TOOL_NAME } from "../../core/src/constants"

export async function activate(context: ExtensionContext) {
const state = new ExtensionState(context)
Expand All @@ -29,68 +29,57 @@ export async function activate(context: ExtensionContext) {
activateDocsNotebook(state)

context.subscriptions.push(
registerCommand(
"genaiscript.request.abort",
async () => {
await state.cancelAiRequest()
registerCommand("genaiscript.request.abort", async () => {
await state.cancelAiRequest()
await vscode.window.showInformationMessage(
`${TOOL_NAME} - request aborted.`
)
}),
registerCommand("genaiscript.request.status", async () => {
const cmds = commandButtons(state)
if (!cmds.length)
await vscode.window.showInformationMessage(
`${TOOL_NAME} - request aborted.`
`${TOOL_NAME} - no request.`
)
else {
const res = await vscode.window.showQuickPick(cmds, {
canPickMany: false,
})
if (res) vscode.commands.executeCommand(res.cmd)
}
),
registerCommand(
"genaiscript.request.status",
async () => {
const cmds = commandButtons(state)
if (!cmds.length)
await vscode.window.showInformationMessage(
`${TOOL_NAME} - no request.`
)
else {
const res = await vscode.window.showQuickPick(cmds, {
canPickMany: false,
})
if (res) vscode.commands.executeCommand(res.cmd)
}
}),
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`)
issueBody.push("`````")
issueBody.push(state.aiRequest?.trace?.content)
issueBody.push("`````")
}
),
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`)
issueBody.push("`````")
issueBody.push(state.aiRequest?.trace?.content)
issueBody.push("`````")
await vscode.commands.executeCommand(
"workbench.action.openIssueReporter",
{
extensionId: EXTENSION_ID,
issueBody: issueBody.join("\n"),
}
await vscode.commands.executeCommand(
"workbench.action.openIssueReporter",
{
extensionId: EXTENSION_ID,
issueBody: issueBody.join("\n"),
}
)
}
)
)
})
)

await state.activate()
Expand Down
20 changes: 7 additions & 13 deletions packages/vscode/src/fragmentcommands.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import * as vscode from "vscode"
import {
Fragment,
GENAI_ANYJS_REGEX,
NotSupportedError,
PromptScript,
assert,
dotGenaiscriptPath,
errorMessage,
groupBy,
promptParameterTypeToJSONSchema,
templateGroup,
} from "genaiscript-core"
import { ExtensionState } from "./state"
import { checkDirectoryExists, checkFileExists } from "./fs"
import { registerCommand } from "./commands"
import { templateGroup } from "../../core/src/ast"
import { GENAI_ANYJS_REGEX } from "../../core/src/constants"
import { NotSupportedError } from "../../core/src/error"
import { promptParameterTypeToJSONSchema } from "../../core/src/parameters"
import { Fragment } from "../../core/src/promptrunner"
import { assert, dotGenaiscriptPath, groupBy } from "../../core/src/util"

type TemplateQuickPickItem = {
template?: PromptScript
Expand Down Expand Up @@ -206,7 +200,7 @@ export function activateFragmentCommands(state: ExtensionState) {

subscriptions.push(
registerCommand("genaiscript.fragment.prompt", fragmentPrompt),
registerCommand("genaiscript.fragment.debug", fragmentDebug),
registerCommand("genaiscript.fragment.debug", fragmentDebug)
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/src/fs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode"
import { JSON5TryParse } from "genaiscript-core"
import { Utils } from "vscode-uri"
import { JSON5TryParse } from "../../core/src/json5"

export async function findFiles(pattern: string) {
return (await vscode.workspace.findFiles(pattern)).map((f) => f.fsPath)
Expand Down
13 changes: 6 additions & 7 deletions packages/vscode/src/llmrequesttree.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as vscode from "vscode"
import { ExtensionState } from "./state"
import { infoUri } from "./markdowndocumentprovider"
import { CacheEntry } from "../../core/src/cache"
import {
CHANGE,
CacheEntry,
CreateChatCompletionRequest,
CACHE_LLMREQUEST_PREFIX,
getChatCompletionCache,
ChatCompletationRequestCache,
ChatCompletationRequestCacheValue,
} from "genaiscript-core"
import { infoUri } from "./markdowndocumentprovider"
ChatCompletationRequestCache,
getChatCompletionCache,
} from "../../core/src/chat"
import { CHANGE, CACHE_LLMREQUEST_PREFIX } from "../../core/src/constants"

type LLMRequestTreeNode = CacheEntry<
CreateChatCompletionRequest,
Expand Down
22 changes: 11 additions & 11 deletions packages/vscode/src/lmaccess.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* eslint-disable @typescript-eslint/naming-convention */
import * as vscode from "vscode"
import { AIRequestOptions, ExtensionState } from "./state"
import { isApiProposalEnabled } from "./proposals"
import { LanguageModel } from "../../core/src/chat"
import {
LanguageModel,
GenerationOptions,
estimateTokens,
logVerbose,
APIType,
MODEL_PROVIDER_OPENAI,
MODEL_PROVIDER_OLLAMA,
MODEL_PROVIDER_LLAMAFILE,
MODEL_PROVIDER_AICI,
updateConnectionConfiguration,
MODEL_PROVIDER_AZURE,
parseModelIdentifier,
MODEL_PROVIDER_LITELLM,
MODEL_PROVIDER_LLAMAFILE,
} from "genaiscript-core"
import { isApiProposalEnabled } from "./proposals"
MODEL_PROVIDER_OPENAI,
} from "../../core/src/constants"
import { APIType } from "../../core/src/host"
import { parseModelIdentifier } from "../../core/src/models"
import { GenerationOptions } from "../../core/src/promptcontext"
import { estimateTokens } from "../../core/src/tokens"
import { logVerbose } from "../../core/src/util"
import { updateConnectionConfiguration } from "../../core/src/connection"

async function generateLanguageModelConfiguration(
state: ExtensionState,
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/src/localai.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICON_LOGO_NAME } from "genaiscript-core"
import * as vscode from "vscode"
import { openUrlInTab } from "./browser"
import { ICON_LOGO_NAME } from "../../core/src/constants"

export async function startLocalAI() {
const name = "LocalAI"
Expand Down
Loading

0 comments on commit 1bd1037

Please sign in to comment.