devin 0.1.19: a chat's response_format is told in the instructions, as the built-in told it
Devin's GetChatMessage has no field for the answer's format, so magpie's built-in Devin (internal/gateway/devin.go, req.inSystem()) told the model in the instructions: the json_schema's schema, or any JSON object for json_object. The plugin dropped response_format, and magpie's generic plugin path falls back to inSystem only when an upstream answers 400 naming the format, so a moved user asking for JSON got prose. build() now adds the built-in's words (format.go's instruction) after the system messages, ahead of the tool descriptions, at the head of the first user message. A json_schema with no schema asks for any JSON object, as the built-in's openAIFormat reads it. Checked against the built-in, no change needed: - Lightning variants (swe-2-high-lightning, swe-1-7-lightning-medium): the built-in's tiers are fast and priority only (devinTiers), so a -lightning id is no effort and no tier and is listed as its own model, as the plugin lists it. - A failed tool's result: magpie sends its content as "Error: …", and build() passes a tool message's text to Devin as it came; a test now holds that. Run: HOME=$(mktemp -d) bun test in packages/devin: 89 pass, 0 fail. structured-output.test.mjs: 3 of its 5 tests red with the index.mjs change taken out (the other two: no format unchanged, and the "Error: " pass-through). bun scripts/check.mjs devin: ok. Not run: a real Devin account, nor magpie end to end.
This commit is contained in:
@@ -1322,6 +1322,18 @@ const inID = (id) => {
|
|||||||
return raw && outID(raw) === id ? raw : id
|
return raw && outID(raw) === id ? raw : id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatText is the structured output a chat's response_format asks for,
|
||||||
|
// said in words as magpie's built-in says it (format.go's instruction):
|
||||||
|
// json_schema's schema, or any JSON object for json_object or a schema of
|
||||||
|
// no shape; "" for text or none.
|
||||||
|
function formatText(f) {
|
||||||
|
if (f?.type === "json_object") return "Respond with a single JSON object and nothing else."
|
||||||
|
if (f?.type !== "json_schema") return ""
|
||||||
|
const schema = f.json_schema ? f.json_schema.schema : f.schema
|
||||||
|
if (schema === undefined || schema === null) return "Respond with a single JSON object and nothing else."
|
||||||
|
return "Respond with a single JSON value and nothing else, matching this JSON schema:\n" + JSON.stringify(schema) + "."
|
||||||
|
}
|
||||||
|
|
||||||
// build is the GetChatMessage request for a chat completion, to the model
|
// build is the GetChatMessage request for a chat completion, to the model
|
||||||
// uid.
|
// uid.
|
||||||
function build(chat, uid, key) {
|
function build(chat, uid, key) {
|
||||||
@@ -1378,6 +1390,10 @@ function build(chat, uid, key) {
|
|||||||
msgs.push({ role: USER, text, images })
|
msgs.push({ role: USER, text, images })
|
||||||
}
|
}
|
||||||
answer()
|
answer()
|
||||||
|
// Devin has no field for the answer's format: it is told in words, at
|
||||||
|
// the end of the instructions, as magpie's built-in tells it (inSystem)
|
||||||
|
const format = formatText(chat.response_format)
|
||||||
|
if (format) system.push(format)
|
||||||
const last = msgs[msgs.length - 1]
|
const last = msgs[msgs.length - 1]
|
||||||
if (!last || (last.role === ASSISTANT && !last.calls.length)) msgs.push({ role: USER, text: "Please proceed with the task." })
|
if (!last || (last.role === ASSISTANT && !last.calls.length)) msgs.push({ role: USER, text: "Please proceed with the task." })
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@magpie-community/opencode-devin-auth",
|
"name": "@magpie-community/opencode-devin-auth",
|
||||||
"version": "0.1.18",
|
"version": "0.1.19",
|
||||||
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
|
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./index.mjs",
|
"main": "./index.mjs",
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
// A chat's structured output reaches Devin in words. Devin's
|
||||||
|
// GetChatMessage has no field for the answer's format, so magpie's built-in
|
||||||
|
// told the model in the instructions (internal/gateway/devin.go:
|
||||||
|
// req.inSystem(), format.go's instruction). The plugin dropped
|
||||||
|
// response_format, so a caller asking for JSON got prose back.
|
||||||
|
import { expect, test } from "bun:test"
|
||||||
|
import { _internal } from "./index.mjs"
|
||||||
|
|
||||||
|
const dec = new TextDecoder()
|
||||||
|
|
||||||
|
// sent is each message's role and text as build() gives them to Devin.
|
||||||
|
const sent = (chat) =>
|
||||||
|
_internal
|
||||||
|
.fields(_internal.build(chat, "swe-2-high", "k"))
|
||||||
|
.filter((f) => f.num === 3 && f.wire === 2)
|
||||||
|
.map((f) => {
|
||||||
|
const m = { role: 0, text: "" }
|
||||||
|
for (const g of _internal.fields(f.data)) {
|
||||||
|
if (g.num === 2) m.role = g.n
|
||||||
|
else if (g.num === 3) m.text = dec.decode(g.data)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
})
|
||||||
|
|
||||||
|
const schema = { type: "object", properties: { answer: { type: "string" } }, required: ["answer"] }
|
||||||
|
const told = 'Respond with a single JSON value and nothing else, matching this JSON schema:\n{"type":"object","properties":{"answer":{"type":"string"}},"required":["answer"]}.'
|
||||||
|
const object = "Respond with a single JSON object and nothing else."
|
||||||
|
const chat = (response_format) => ({ messages: [{ role: "system", content: "Be brief." }, { role: "user", content: "hi" }], response_format })
|
||||||
|
|
||||||
|
test("response_format's json_schema is told at the end of the instructions, as the built-in told it", () => {
|
||||||
|
expect(sent(chat({ type: "json_schema", json_schema: { name: "r", schema, strict: true } }))[0].text).toBe("Be brief.\n\n" + told + "\n\nhi")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("json_object, or a json_schema with no schema, asks for any JSON object", () => {
|
||||||
|
expect(sent(chat({ type: "json_object" }))[0].text).toBe("Be brief.\n\n" + object + "\n\nhi")
|
||||||
|
expect(sent(chat({ type: "json_schema", json_schema: { name: "r" } }))[0].text).toBe("Be brief.\n\n" + object + "\n\nhi")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("with no system message the format is the whole of the instructions", () => {
|
||||||
|
expect(sent({ messages: [{ role: "user", content: "hi" }], response_format: { type: "json_object" } })[0].text).toBe(object + "\n\nhi")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("text, or no response_format, is sent as before", () => {
|
||||||
|
expect(sent(chat({ type: "text" }))[0].text).toBe("Be brief.\n\nhi")
|
||||||
|
expect(sent(chat(undefined))[0].text).toBe("Be brief.\n\nhi")
|
||||||
|
})
|
||||||
|
|
||||||
|
// magpie says a failed tool's result as "Error: …", as the built-in did
|
||||||
|
// (devin.go: IsError); it goes to Devin as it came
|
||||||
|
test("a failed tool's result goes to Devin as magpie worded it", () => {
|
||||||
|
const got = sent({
|
||||||
|
messages: [
|
||||||
|
{ role: "user", content: "run it" },
|
||||||
|
{ role: "assistant", content: "", tool_calls: [{ id: "call_a", type: "function", function: { name: "bash", arguments: "{}" } }] },
|
||||||
|
{ role: "tool", tool_call_id: "call_a", content: "Error: exit status 1" },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
expect(got.find((m) => m.role === 4).text).toBe("Error: exit status 1")
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user