Skip to content

Commit

Permalink
mode specific configs
Browse files Browse the repository at this point in the history
  • Loading branch information
roodboi committed Jan 2, 2024
1 parent 4d7e262 commit 10178fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/instructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default class Instructor {
...jsonSchema.definitions.response_model
}

const paramsForMode = MODE_TO_PARAMS[this.mode](definition, params)
const paramsForMode = MODE_TO_PARAMS[this.mode](definition, params, this.mode)

return {
stream: false,
Expand Down
16 changes: 15 additions & 1 deletion src/oai/params.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MODE } from "@/constants/modes"

export function OAIBuildFunctionParams(definition, params) {
return {
...params,
Expand All @@ -19,9 +21,21 @@ export function OAIBuildToolFunctionParams(definition, params) {
}
}

export function OAIBuildMessageBasedParams(definition, params) {
export function OAIBuildMessageBasedParams(definition, params, mode) {
const MODE_SPECIFIC_CONFIGS = {
[MODE.JSON]: {
response_format: { type: "json_object" }
},
[MODE.JSON_SCHEMA]: {
response_format: { type: "json_object", schema: definition }
}
}

const modeConfig = MODE_SPECIFIC_CONFIGS[mode] ?? {}

return {
...params,
...modeConfig,
messages: [
...(params?.messages ?? []),
{
Expand Down

0 comments on commit 10178fd

Please sign in to comment.