Skip to content

Commit

Permalink
feat(playground): minimal content part refusal support (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Aug 8, 2024
1 parent d14d604 commit f03d4da
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/react-playground/src/lib/openai/fromOpenAIMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export const fromOpenAIMessages = (
const { role, content } = message;
switch (role) {
case "system": {
lmMessages.push({ role: "system", content });
lmMessages.push({
role: "system",
content:
typeof content === "string"
? content
: content.map((c) => c.text).join("\n"),
});
break;
}

Expand Down Expand Up @@ -57,7 +63,31 @@ export const fromOpenAIMessages = (
)[] = [];

if (content != null) {
lmContent.push({ type: "text", text: content });
lmContent.push(
...(typeof content === "string"
? [{ type: "text" as const, text: content }]
: content.map((part) => {
const type = part.type;
switch (type) {
case "text": {
return part;
}

case "refusal": {
// TODO handle refusals
return {
type: "text" as const,
text: part.refusal,
};
}

default: {
const unsupportedPart: "refusal" = type;
throw new Error(`Unsupported part: ${unsupportedPart}`);
}
}
})),
);
}

if (message.tool_calls) {
Expand Down

0 comments on commit f03d4da

Please sign in to comment.