Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move rag tests to ollama #623

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ollama.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
- name: download ollama docker
run: docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
- name: run summarize-ollama-phi3
run: yarn test:summarize --model ollama:phi3 --out ./temp
run: yarn test:summarize --model ollama:phi3 --out ./temp/summarize-ollama-phi3
- name: run rag
run: yarn run:script rag --out ./temp/rag
- name: test summarize-links-phi3
run: yarn test:scripts summarize-link --models ollama:phi3 --out ./temp
run: yarn test:scripts summarize-link --models ollama:phi3 --out ./temp/summarize-link
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"markdownify",
"memorystream",
"millis",
"nomic",
"ollama",
"openai",
"promptdom",
Expand Down
9 changes: 8 additions & 1 deletion docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@
"Function to do a search using embeddings vector similarity distance.",
})

const embeddingsModel = env.var.embeddingsModel || undefined

Check failure on line 713 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The variable `embeddingsModel` is assigned with `|| undefined` which is redundant since an unset or nullish value defaults to `undefined` in JavaScript.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable embeddingsModel is declared but its value is never read.

generated by pr-docs-review-commit unused_variable

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable embeddingsModel is assigned with || undefined which is redundant since an unset or nullish value defaults to undefined in JavaScript.

generated by pr-docs-review-commit unnecessary_code


defTool(
"retrieval_vector_search",
"Search files using embeddings and similarity distance.",
Expand Down Expand Up @@ -737,7 +739,7 @@
const res = await retrieval.vectorSearch(
q,
files.map((filename) => ({ filename }))
)
, { embeddingsModel })

Check failure on line 742 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

Missing comma after the closing parenthesis of the `vectorSearch` function call.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument label for embeddingsModel is missing in the function call.

generated by pr-docs-review-commit missing_argument_label

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the closing parenthesis of the vectorSearch function call.

generated by pr-docs-review-commit missing_comma

return YAML.stringify(res.map(({ filename }) => filename))
}
)
Expand Down
9 changes: 8 additions & 1 deletion genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion packages/core/src/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ system({
"Function to do a search using embeddings vector similarity distance.",
})

const embeddingsModel = env.var.embeddingsModel || undefined

defTool(
"retrieval_vector_search",
"Search files using embeddings and similarity distance.",
Expand Down Expand Up @@ -31,7 +33,7 @@ defTool(
const res = await retrieval.vectorSearch(
q,
files.map((filename) => ({ filename }))
)
, { embeddingsModel })
return YAML.stringify(res.map(({ filename }) => filename))
}
)
2 changes: 1 addition & 1 deletion packages/core/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
const configuration = await host.getLanguageModelConfiguration(
model,
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token variable name has been changed from 'askToken' to 'withToken'. Please ensure that 'withToken' is defined and holds the correct value. 🕵️‍♀️

generated by pr-review-commit token_change

token: askToken,
token: withToken,

Check failure on line 104 in packages/core/src/models.ts

View workflow job for this annotation

GitHub Actions / build

The token variable name has been changed from `askToken` to `withToken`. Please ensure that `withToken` is defined and has the correct value. 🕵️‍♀️
signal,
trace,
}
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,14 @@
/**
* LLM model to use for embeddings.
*/
embeddingsModel?: "openai:text-embedding-ada-002" | string
embeddingsModel?: OptionsOrString<
"openai:text-embedding-3-small",
"openai:text-embedding-3-large",
"openai:text-embedding-ada-002",
"github:text-embedding-3-small",
"github:text-embedding-3-large",
"ollama:nomic-embed-text"
>

Check failure on line 197 in packages/core/src/types/prompt_template.d.ts

View workflow job for this annotation

GitHub Actions / build

The `embeddingsModel` options have been expanded. Please ensure that all new options are supported and correctly implemented in the code. 🧐

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'embeddingsModel' type has been changed and new options have been added. Please ensure that these new options are supported and handled correctly in the code. 🧐

generated by pr-review-commit embeddingsModel_change

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The embeddingsModel options have been expanded. Please ensure that all new options are supported and correctly implemented in the code. 🧐

generated by pr-review-commit embeddings_model_change

}

interface EmbeddingsModelOptions extends EmbeddingsModelConnectionOptions {}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/vectorsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { EmbeddingCreateParams, EmbeddingCreateResponse } from "./chattypes"
import { LanguageModelConfiguration } from "./host"
import { getConfigHeaders } from "./openai"
import { trimTrailingSlash } from "./util"
import { logVerbose, trimTrailingSlash } from "./util"
import { TraceOptions } from "./trace"

export interface EmbeddingsCacheKey {
Expand Down Expand Up @@ -72,10 +72,11 @@
url = `${trimTrailingSlash(base)}/${model.replace(/\./g, "")}/embeddings?api-version=${AZURE_OPENAI_API_VERSION}`
delete body.model
} else {
url = `${base}/v1/embeddings`
url = `${base}/embeddings`

Check failure on line 75 in packages/core/src/vectorsearch.ts

View workflow job for this annotation

GitHub Actions / build

The URL endpoint for embeddings has been changed from `/v1/embeddings` to `/embeddings`. Please ensure that the new endpoint is correct and functional. 🌐

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL endpoint for embeddings has been changed from '/v1/embeddings' to '/embeddings'. Please ensure that the new endpoint is correct and functional. 🌐

generated by pr-review-commit url_change

}
const fetch = await createFetch({ retryOn: [429] })
if (trace) traceFetchPost(trace, url, headers, body)
logVerbose(`embedding ${model}`)
const resp = await fetch(url, {
method: "POST",
headers,
Expand Down
9 changes: 8 additions & 1 deletion packages/sample/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion packages/sample/genaisrc/node/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion packages/sample/genaisrc/python/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions packages/sample/genaisrc/rag.genai.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
script({
title: "rag",
model: "openai:gpt-3.5-turbo",
model: "ollama:phi3",
files: "src/rag/*",
tests: {
files: "src/rag/*",
keywords: ["lorem", "markdown", "word"],
},
})

$`You are a helpful assistant. Summarize the files in MARKDOWN, PDF, WORD and ALL.`
$`Summarize MARKDOWN, PDF, WORD and ALL. Use one short sentence.`

const embeddingsModel = env.vars.embeddingsModel || "ollama:nomic-embed-text"

def(
"MARKDOWN",
await retrieval.vectorSearch(
"markdown",
env.files.filter((f) => f.filename.endsWith(".md"))
env.files.filter((f) => f.filename.endsWith(".md")),
{ embeddingsModel }
)
)
def(
"PDF",
await retrieval.vectorSearch(
"lorem",
env.files.filter((f) => f.filename.endsWith(".pdf"))
env.files.filter((f) => f.filename.endsWith(".pdf")),
{ embeddingsModel }
)
)
def(
"WORD",
await retrieval.vectorSearch(
"word",
env.files.filter((f) => f.filename.endsWith(".docx"))
env.files.filter((f) => f.filename.endsWith(".docx")),
{ embeddingsModel }
)
)
def("ALL", await retrieval.vectorSearch("lorem", env.files))
def(
"ALL",
await retrieval.vectorSearch("lorem", env.files, {
embeddingsModel,
})
)
9 changes: 8 additions & 1 deletion packages/sample/genaisrc/style/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/sample/genaisrc/summary-of-summary-phi3.genai.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
script({
model: "openai:gpt-4-32k",
model: "ollama:phi3",
title: "summary of summary - phi3",
files: ["src/rag/*.md"],
tests: {
files: ["src/rag/*"],
files: ["src/rag/*.md"],
keywords: ["markdown", "lorem", "microsoft"],
}
})
Expand All @@ -19,4 +20,4 @@ for (const file of env.files) {
def("FILE", { ...file, content: text })
}
// use summary
$`Summarize all the FILE.`
$`Summarize FILE with short sentence.`
9 changes: 8 additions & 1 deletion packages/sample/src/aici/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion packages/sample/src/errors/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion packages/sample/src/makecode/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion packages/sample/src/tla/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion packages/sample/src/vision/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion slides/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.