Skip to content

Commit

Permalink
fix runPrompt + phi3
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Apr 24, 2024
1 parent 8073d3a commit 5d80928
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 54 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export const OpenAIChatCompletion: ChatCompletionHandler = async (
const { signal } = requestOptions || {}
const { headers, ...rest } = requestOptions || {}
const { token, source, ...cfgNoToken } = cfg
const { model } = parseModelIdentifier(req.model)
const { provider, model } = parseModelIdentifier(req.model)

trace.itemValue(`provider`, provider)
trace.itemValue(`model`, model)
trace.itemValue(`temperature`, temperature)
trace.itemValue(`top_p`, top_p)
trace.itemValue(`seed`, seed)
Expand Down Expand Up @@ -91,7 +93,6 @@ export const OpenAIChatCompletion: ChatCompletionHandler = async (
`/chat/completions?api-version=${AZURE_OPENAI_API_VERSION}`
} else throw new Error(`api type ${cfg.type} not supported`)

trace.itemValue(`model`, model)
trace.itemValue(`url`, `[${url}](${url})`)
trace.itemValue(`response_format`, response_format)
if (tools?.length) {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/promptdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { assert, toStringList, trimNewlines } from "./util"
import { YAMLStringify } from "./yaml"
import { MARKDOWN_PROMPT_FENCE, PROMPT_FENCE } from "./constants"
import { fenceMD } from "./markdown"
import { parseModelIdentifier } from "./models"

export interface PromptNode extends ContextExpansionOptions {
type?:
Expand Down Expand Up @@ -461,11 +462,12 @@ export async function tracePromptNode(
}

export async function renderPromptNode(
model: string,
modelId: string,
node: PromptNode,
options?: TraceOptions
): Promise<PromptNodeRender> {
const { trace } = options || {}
const { model } = parseModelIdentifier(modelId)

await resolvePromptNode(model, node, options)
await tracePromptNode(trace, node)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/runpromptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ export function createRunPromptContext(
trace.error("generator missing")
return <RunPromptResult>{ text: "", finishReason: "error" }
}
const { provider, model } = parseModelIdentifier(
const model =
promptOptions?.model ?? options.model ?? DEFAULT_MODEL
)
const runOptions = {
...options,
...(promptOptions || {}), // overrides options
Expand All @@ -115,6 +114,7 @@ export function createRunPromptContext(

const messages: ChatCompletionMessageParam[] = []
// expand template
const { provider } = parseModelIdentifier(model)
if (provider === "aici") {
const { aici } = await renderAICI("prompt", node)
// todo: output processor?
Expand Down
16 changes: 10 additions & 6 deletions packages/sample/genaisrc/genaiscript.d.ts

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

16 changes: 10 additions & 6 deletions packages/sample/genaisrc/node/genaiscript.d.ts

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

16 changes: 10 additions & 6 deletions packages/sample/genaisrc/python/genaiscript.d.ts

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

16 changes: 10 additions & 6 deletions packages/sample/genaisrc/style/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
@@ -1,5 +1,5 @@
script({
title: "summary of summary",
title: "summary of summary - gp35",
})

// summarize each files individually
Expand Down
17 changes: 17 additions & 0 deletions packages/sample/genaisrc/summary-of-summary-phi3.genai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
script({
title: "summary of summary - phi3",
})

// summarize each files individually
for (const file of env.files) {
const { text } = await runPrompt(
(_) => {
_.def("FILE", file)
_.$`Summarize the FILE and respond in plain text with one paragraph. Be consice. Ensure that summary is consistent with the content of FILE.`
},
{ model: "ollama:phi3", cacheName: "summary_phi3" }
)
def("FILE", { ...file, content: text })
}
// use summary
$`Summarize all the FILE.`
16 changes: 10 additions & 6 deletions packages/sample/src/aici/genaiscript.d.ts

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

16 changes: 10 additions & 6 deletions packages/sample/src/makecode/genaiscript.d.ts

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

2 changes: 2 additions & 0 deletions packages/sample/src/questions.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Questions

- What is weather in Seattle?
- What laws were voted in the USA congress last week?
16 changes: 10 additions & 6 deletions packages/sample/src/tla/genaiscript.d.ts

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

16 changes: 10 additions & 6 deletions packages/sample/src/vision/genaiscript.d.ts

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

0 comments on commit 5d80928

Please sign in to comment.