Replies: 2 comments 2 replies
-
Hello, @Aman9723! I'm here to assist you with any bugs, questions, or contributions you need help with. Let's tackle this together! I found a similar closed issue that might be relevant to your problem. The issue was titled "withStructuredOutput not returning the desired format" and was resolved by switching to a model that supports structured output, such as ANTHROPIC claude-3-5-sonnet-latest. Additionally, using In your case, you might want to verify if the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
-
import { ENV } from "../lib/constants";
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: ENV.ANTHROPIC_API_KEY
});
async function run() {
const msg = await anthropic.messages.create({
tool_choice: {
type: "tool",
name: "CodeGeneratorResponseSchema"
},
model: "claude-3-5-haiku-latest",
max_tokens: 8_192,
system: "You are a specialized game developer. Generate a single HTML file that includes all necessary code (HTML, CSS, and JavaScript) to create a game",
tools: [
{
name: "CodeGeneratorResponseSchema",
description: "Schema for the response containing code edits, generated code, and suggestions",
input_schema: {
type: "object",
properties: {
edits: {
type: "string",
description: "The text response from the model regarding the edits made to the code or generated code"
},
code: {
type: "string",
description: "The newly generated or edited code"
},
suggestions: {
type: "array",
items: { type: "string" },
description: "Suggestions for the user to improve the game which can be used as prompts for the next iteration"
}
},
required: ["edits", "code"]
}
}
],
messages: [
{ role: "user", content: "Generate a chess game" },
{
role: "assistant",
content: `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess Game</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
#chessboard {
display: grid;
grid-template-columns: repeat(8, 50px);
grid-template-rows: repeat(8, 50px);
border: 2px solid black;
}
.square {
width: 50px;
height: 50px;
}
.white {
background-color: #fff;
}
.black {
background-color: #000;
}
</style>
</head>
<body>
<div id="chessboard"></div>
<script>
const chessboard = document.getElementById('chessboard');
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 8; col++) {
const square = document.createElement('div');
square.className = 'square ' + ((row + col) % 2 === 0 ? 'white' : 'black');
chessboard.appendChild(square);
}
}
</script>
</body>
</html>`
},
{
role: "user",
content: "Improve the game logic"
}
]
});
console.log(msg);
}
run(); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
System Info
"@langchain/anthropic": "^0.3.15",
"@langchain/core": "^0.3.43",
"@langchain/langgraph": "^0.2.62",
"@langchain/openai": "^0.5.2",
OS Name Microsoft Windows 11 Home Single Language
npm: '11.1.0',
node: '22.13.0',
Beta Was this translation helpful? Give feedback.
All reactions