Skip to content

Commit

Permalink
fix model propagagtion
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 16, 2024
1 parent 495f85a commit 51106a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"compile-ext": "yarn --cwd packages/core run prompts:bundle && yarn --cwd packages/vscode run compile",
"compile-cli": "yarn --cwd packages/cli run compile",
"compile": "yarn compile-ext && yarn compile-cli && yarn test:fix",
"compile-debug": "yarn --cwd packages/cli run compile-debug",
"go": "cd packages/cli && yarn go",
"token": "cd packages/sample && yarn token",
"typecheck": "yarn --cwd packages/core run typecheck && yarn --cwd packages/vscode run typecheck && yarn --cwd packages/cli run typecheck",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function runScript(
if (options.label) trace.heading(2, options.label)
const { info } = await resolveModelConnectionInfo(script, {
trace,
model: options.model ?? host.defaultModelOptions.model,
model: options.model ?? script.model ?? host.defaultModelOptions.model,
})
if (info.error) {
trace.error(undefined, info.error)
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export interface ResponseStatus {
}

export interface RetrievalSearchOptions extends VectorSearchOptions {
topK?: number
minScore?: number
}

export interface RetrievalSearchResponse extends ResponseStatus {
Expand Down
19 changes: 12 additions & 7 deletions packages/core/src/promptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {
tracePromptResult,
} from "./chat"
import { host } from "./host"
import { HTMLEscape, arrayify, dotGenaiscriptPath, logVerbose } from "./util"
import {
HTMLEscape,
arrayify,
dotGenaiscriptPath,
logVerbose,
sha256string,
} from "./util"
import { RetrievalSearchResponse, runtimeHost } from "./host"
import { MarkdownTrace } from "./trace"
import { YAMLParse, YAMLStringify } from "./yaml"
Expand Down Expand Up @@ -154,7 +160,7 @@ export function createPromptContext(
},
vectorSearch: async (q, files_, searchOptions) => {
const files = arrayify(files_).map(toWorkspaceFile)
searchOptions = searchOptions || {}
searchOptions = { ...(searchOptions || {}) }
try {
trace.startDetails(
`🔍 vector search <code>${HTMLEscape(q)}</code>`
Expand All @@ -165,19 +171,18 @@ export function createPromptContext(
}

await resolveFileContents(files)
const embeddingsModel =
searchOptions.embeddingsModel =
searchOptions?.embeddingsModel ??
options?.embeddingsModel ??
host.defaultEmbeddingsModelOptions.embeddingsModel
const folderPath = dotGenaiscriptPath(
"vectors",
embeddingsModel
const key = await sha256string(
JSON.stringify({ files, searchOptions })
)
const folderPath = dotGenaiscriptPath("vectors", key)
const res = await vectorSearch(q, files, {
...searchOptions,
folderPath,
trace,
embeddingsModel,
})
// search
trace.files(res, {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/vectorsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OpenAIEmbeddings implements EmbeddingsModel {
this.cache = JSONLineCache.byName<
EmbeddingsCacheKey,
EmbeddingsResponse
>(dotGenaiscriptPath("cache", "embeddings"))
>("embeddings")
}

maxTokens = 512
Expand Down

0 comments on commit 51106a7

Please sign in to comment.