-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add gemma2:2b test and ollama pull format as cli #599
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,22 +9,27 @@ import { assert } from "./util" | |
* provider:model | ||
* provider:model:tag where modelId model:tag | ||
*/ | ||
export function parseModelIdentifier(id: string) { | ||
export function parseModelIdentifier(id: string): { | ||
provider: string | ||
family: string | ||
model: string | ||
tag?: string | ||
} { | ||
assert(!!id) | ||
id = id.replace("-35-", "-3.5-") | ||
const parts = id.split(":") | ||
if (parts.length >= 3) | ||
return { | ||
provider: parts[0], | ||
model: parts[1], | ||
family: parts[1], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable
|
||
tag: parts.slice(2).join(":"), | ||
modelId: parts.slice(1).join(":"), | ||
model: parts.slice(1).join(":"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
|
||
} | ||
else if (parts.length === 2) | ||
return { provider: parts[0], model: parts[1], modelId: parts[1] } | ||
return { provider: parts[0], family: parts[1], model: parts[1] } | ||
else if (id === MODEL_PROVIDER_LLAMAFILE) | ||
return { provider: MODEL_PROVIDER_LLAMAFILE, model: "*", modelId: id } | ||
else return { provider: MODEL_PROVIDER_OPENAI, model: id, modelId: id } | ||
return { provider: MODEL_PROVIDER_LLAMAFILE, family: "*", model: id } | ||
else return { provider: MODEL_PROVIDER_OPENAI, family: id, model: id } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable name change from
|
||
} | ||
|
||
export interface ModelConnectionInfo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,23 +16,23 @@ export const OllamaCompletion: ChatCompletionHandler = async ( | |
return await OpenAIChatCompletion(req, cfg, options, trace) | ||
} catch (e) { | ||
if (isRequestError(e)) { | ||
const { modelId } = parseModelIdentifier(req.model) | ||
const { model } = parseModelIdentifier(req.model) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable
|
||
if ( | ||
e.status === 404 && | ||
e.body?.type === "api_error" && | ||
e.body?.message?.includes(`model '${modelId}' not found`) | ||
e.body?.message?.includes(`model '${model}' not found`) | ||
) { | ||
trace.log(`model ${modelId} not found, trying to pull it`) | ||
trace.log(`model ${model} not found, trying to pull it`) | ||
// model not installed locally | ||
// trim v1 | ||
const fetch = await createFetch({ trace }) | ||
const res = await fetch(cfg.base.replace("/v1", "/api/pull"), { | ||
method: "POST", | ||
body: JSON.stringify({ name: modelId, stream: false }), | ||
body: JSON.stringify({ name: model, stream: false }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API endpoint has been changed from "/v1" to "/api/pull". Please ensure that this new endpoint is correct and the server is configured to handle requests at this endpoint. π€
|
||
}) | ||
if (!res.ok) { | ||
throw new Error( | ||
`Failed to pull model ${modelId}: ${res.status} ${res.statusText}` | ||
`Failed to pull model ${model}: ${res.status} ${res.statusText}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable name change from
|
||
) | ||
} | ||
trace.log(`model pulled`) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
script({ | ||
model: "ollama:gemma2:2b", | ||
title: "summarize with ollama gemma 2 2b", | ||
system: [], | ||
files: "src/rag/markdown.md", | ||
tests: { | ||
files: "src/rag/markdown.md", | ||
keywords: "markdown", | ||
}, | ||
}) | ||
|
||
const file = def("FILE", env.files) | ||
|
||
$`Summarize ${file} in a sentence. Make it short. | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
model
is not defined in the current scope. It seems like you meant to usemodelid
instead. π€