-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Bug: A conversation must alternate between user and assistant roles. #736
Comments
1. Understand the Error Message:
} javascript 6. Update Dependencies: 7. Test with Static Data: Example of Testing Static Data: javascript // Test with static data return handler(req, res, next); Conclusion: |
Thank you chatGPT |
@abhi7dhiru do you really think that I haven't already tried to consult chatGPT or something else? Not helpful answer at all ( but hey I know It's hacktoberfest ! ). |
Ok, so after a day of debugging, if you want to integrate Bedrock with CopilotKit, you need to do the following: import express from 'express';
import {
CopilotRuntime,
copilotRuntimeNodeHttpEndpoint,
GroqAdapter,
LangChainAdapter,
UnifyAdapter
} from '@copilotkit/runtime';
import { BedrockChat } from "@langchain/community/chat_models/bedrock";
const app = express();
const runtime = new CopilotRuntime();
const serviceAdapter = new LangChainAdapter({
//@ts-ignore
chainFn: async ({ messages, tools }) => {
const model = new BedrockChat({
model: "anthropic.claude-3-5-sonnet-20240620-v1:0",
region: "xxxxxxxx",
credentials: {
accessKeyId: "xxxxxxxxxxxx",
secretAccessKey: "xxxxxxxxxx",
},
});
const llmWithTools = model.bindTools(tools);
// @ts-ignore
return llmWithTools.invoke(messages);
}
});
app.use('/api/copilotkit', (req, res, next) => {
const handler = copilotRuntimeNodeHttpEndpoint({
endpoint: '/copilotkit',
runtime,
serviceAdapter: serviceAdapter,
});
// @ts-ignore
return handler(req, res, next);
});
app.listen(4000, () => {
console.log('Listening at http://localhost:4000/api/copilotkit');
}); You need to manually bind the tools. Please verify that the model you're using is capable of handling tools. It's important to note that if you want to use Anthropic models, you should use BedrockChat (from LangChain) instead of ChatBedrockConverse, as it's more suitable for this purpose. |
Hi @ClementVanPeuter, apologies for the delay. |
♻️ Reproduction Steps
The node js endpoint with langchain adapter and bedrock
✅ Expected Behavior
CopilotKit behave normally
❌ Actual Behavior
Copilot do a firstTask but crash just after.
𝌚 CopilotKit Version
📄 Logs (Optional)
The text was updated successfully, but these errors were encountered: