Skip to content

Commit

Permalink
move client model to runtimehost (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan authored Jan 23, 2025
1 parent 36785b0 commit ee01fb7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export interface Host {
options?: { token?: boolean } & CancellationOptions & TraceOptions
): Promise<LanguageModelConfiguration | undefined>
log(level: LogLevel, msg: string): void
clientLanguageModel?: LanguageModel

// fs
statFile(name: string): Promise<{
Expand Down Expand Up @@ -131,6 +130,7 @@ export interface RuntimeHost extends Host {
workspace: Omit<WorkspaceFileSystem, "grep">
azureToken: AzureTokenResolver
modelAliases: Readonly<ModelConfigurations>
clientLanguageModel?: LanguageModel

pullModel(
cfg: LanguageModelConfiguration,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
MODEL_PROVIDERS,
MODEL_WHISPERASR_PROVIDER,
} from "./constants"
import { host } from "./host"
import { runtimeHost } from "./host"
import { OllamaModel } from "./ollama"
import { LocalOpenAICompatibleModel } from "./openai"
import { TransformersModel } from "./transformers"
Expand All @@ -23,7 +23,7 @@ import { WhiserAsrModel } from "./whisperasr"

export function resolveLanguageModel(provider: string): LanguageModel {
if (provider === MODEL_PROVIDER_CLIENT) {
const m = host.clientLanguageModel
const m = runtimeHost.clientLanguageModel
if (!m) throw new Error("Client language model not available")
return m
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ export async function resolveModelConnectionInfo(
withToken: askToken,
reportError: false,
})
if (!res.info.error && res.info.token) return res
if (!res.info.error && res.info.token) {
logVerbose(` resolved ${candidate}`)
return res
}
}
return {
info: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"genaiscript.cli.path": "../cli/built/genaiscript.cjs",
"genaiscript.languageChatModels": {
"client:gpt-4": "gpt-4",
"client:gpt-4o": "github.copilot-chat/2/gpt-4",
"client:gpt-4o": "gpt-4o",
"client:*": "github.copilot-chat/2/gpt-4"
}
}
1 change: 0 additions & 1 deletion packages/vscode/src/vshost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ export class VSCodeHost extends EventTarget implements Host {
await vscode.workspace.fs.delete(uri, { recursive: true })
}

clientLanguageModel?: LanguageModel
async getLanguageModelConfiguration(
modelId: string,
options?: { token?: boolean } & CancellationOptions & TraceOptions
Expand Down

0 comments on commit ee01fb7

Please sign in to comment.