Tool - Query

Learn how to use our tools with the GeneratedBy API.


Querying Tool

In this section, we will guide you on how to use the api/applications/:applicationId/query endpoint to query the tools provided by the GeneratedBy API. These tools include the Perfect Prompt and Reverse Prompt.

The response of this endpoint is streamed.

This means that the server sends the response in chunks, which can be processed by the client as they arrive. This is particularly useful when dealing with LLMs.

Perfect Prompt

The Perfect Prompt tool allows you to generate a prompt that is optimized for your specific use case. Here's how you can use it:

Copy code
const url = "https://generatedby.com/api/ai/complete" // replace with your endpoint
 
const data = {
  query: ""// your query data
  type: "perfect-prompt",
}
 
async function fetchData() {
  try {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: "Bearer API_KEY",
      },
      body: JSON.stringify(data),
    })
 
    if (!response.ok) {
      throw new Error(`HTTP error ${response.status}`)
    }
 
    const reader = response.body.getReader()
    const decoder = new TextDecoder()
    let done = false
    let text = ""
 
    while (!done) {
      const { value, done: doneReading } = await reader.read()
      done = doneReading
      const chunkValue = decoder.decode(value, { stream: true })
      text += chunkValue
      console.log(text)
    }
  } catch (error) {
    console.error("Error:", error)
  }
}
 
fetchData()

Replace API_KEY with your API key.

Reverse Prompt

The Reverse Prompt tool allows you to generate a prompt in reverse, which can be useful in certain scenarios. Here's how you can use it:

Copy code
const url = "https://generatedby.com/api/ai/complete"
 
const data = {
  query: ""// your query data
  type: "reverse-prompt",
}
 
async function fetchData() {
  try {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: "Bearer API_KEY",
      },
      body: JSON.stringify(data),
    })
 
    if (!response.ok) {
      throw new Error(`HTTP error ${response.status}`)
    }
 
    const reader = response.body.getReader()
    const decoder = new TextDecoder()
    let done = false
    let text = ""
 
    while (!done) {
      const { value, done: doneReading } = await reader.read()
      done = doneReading
      const chunkValue = decoder.decode(value, { stream: true })
      text += chunkValue
      console.log(text)
    }
  } catch (error) {
    console.error("Error:", error)
  }
}
 
fetchData()

Replace API_KEY with your API key.

For more details on how to use the API, please refer to the API section of the documentation.