Code Monkey home page Code Monkey logo

Comments (4)

kodster28 avatar kodster28 commented on September 23, 2024

Howdy @watany-dev, the example you provided here has quite a bit more than the example in our docs (combining some of the Workers AI stuff, which is great overall but makes it harder to eval what exactly is wrong).

If you just run the example present in our docs, does that one work? Or does it also error out on you?

from cloudflare-docs.

github-actions avatar github-actions commented on September 23, 2024

This issue was closed automatically because there has been no response from the original author. As it stands currently, we don't have enough information to take action. If you believe this issue was closed in error, a) apologies and b) open a new issue and reference this one in the body.

from cloudflare-docs.

kittykatattack avatar kittykatattack commented on September 23, 2024

Hello!

I can confirm that the sample in your docs also does not work. This is the code that I am using:

import { AwsClient } from 'aws4fetch'

export default {
	async fetch(request, env, ctx) {

  
	  const requestData = {
		inputText: "What does ethereal mean?"
	  };
  
	  const headers = {
		'Content-Type': 'application/json'
	  };
  
	  // sign the original request
	  const stockUrl = new URL("https://bedrock-runtime.us-east-1.amazonaws.com/model/amazon.titan-embed-text-v1/invoke")
  
	  const awsClient = new AwsClient({
		accessKeyId: accessKey,
		secretAccessKey: secretKey,
		region: region,
		service: "bedrock"
	  });
  
	  const presignedRequest = await awsClient.sign(stockUrl.toString(), {
		method: "POST",
		headers: headers
	  });

	  console.log(presignedRequest);
  
	  // change the signed request's host to AI Gateway
	  const stockUrlSigned = new URL(presignedRequest.url);
	  stockUrlSigned.host = "gateway.ai.cloudflare.com"
	  stockUrlSigned.pathname = `/v1/${cfAccountId}/${gatewayName}/aws-bedrock/bedrock-runtime/${region}/model/amazon.titan-embed-text-v1/invoke`
  
	  // make request
	  const response = await fetch(stockUrlSigned, {
		method: 'POST',
		headers: presignedRequest.headers,
		body: JSON.stringify(requestData)
	  })
  
	  if (response.ok && response.headers.get('content-type')?.includes('application/json')) {
		const data = await response.json();
		return new Response(JSON.stringify(response));
	  } else {
		// Display the data in the console
		const data = await response.text();
		console.log(data);
		return new Response("Invalid response", { status: 500 });
	  }
	},
  };

The data response I get is always:

{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}

I can also confirm that it is not a problem with my credentials, and I can see the request reaching Cloudflare's AI Gateway in my dashboard. It dies on hitting the amazon endpoint. I think it has something to do with the presignedRequest but I have no idea what. I've tried a few different models for which I have access and the results have been the same.

from cloudflare-docs.

kodster28 avatar kodster28 commented on September 23, 2024

Thanks for re-flagging @kittykatattack, re-opening and raising for our ENG team.

from cloudflare-docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.