Ask.discourse.com - Impossible de trouver une annonce ici

Il n’y a rien de « top secret » ici :slight_smile:

Il y a ce thème qui est très similaire :

Et, l’outil que nous utilisons a le script suivant :

let terms ;
let API_KEY = « ... » ;

const categories = {
  61: « theme »,
  6: « support »,
  148: « data & reporting »,
  164: « Documentation > Hosted Customers »,
  177: « Community wiki »,
  31: « installation »,
  10: « Documentation »,
  22: « plugin »,
  1: « bug »,
  106: « migration »,
  120: « theme-component »,
  105: « community support program »,
  124: « General »,
  157: « site feedback > forum summaries »,
  152: « site feedback > theme feedback »,
  168: « Documentation > Contributing »,
  30: « releases »,
  126: « Documentation > Using Discourse »,
  2: « feature »,
  63: « praise > comparison »,
  9: « ux »,
  27: « dev > translations »,
  24: « sso »,
  3: « site feedback »,
  17: « Uncategorized »,
  14: « marketplace »,
  21: « support > wordpress »,
  13: « announcements > blog »,
  53: « Documentation > Site Management »,
  5: « plugin > extras »,
  65: « community »,
  8: « installation > hosting »,
  35: « praise »,
  67: « announcements »,
  178: « Community wiki > Administrators »,
  167: « Documentation > Integrations »,
  55: « Documentation > Self-Hosting »,
  169: « Documentation > Migrating to Discourse »,
  56: « Documentation > Developer Guides »,
  7: « dev »,
  179: « Community wiki > Developers »,
  181: « Community wiki > Users »,
  180: « Community wiki > Sysadmins »
};


function search(terms) {
   const encoded = encodeURIComponent(terms);
   const searchUrl = « https://meta.discourse.org/discourse-ai/embeddings/semantic-search.json?hyde=false&q= »;
   result = http.get(`${searchUrl}${encoded}`, {'Api-Key': API_KEY });
   return processResults(JSON.parse(result.body));
}

function invoke(p) {
  if (!p.question) {
      terms = « No search performed! »
      return « You must supply the question parameter »;
  }
  terms = p.question;
  let results = search(terms + «  #documentation »);
  let otherResults = search(terms);

  let topicIds = {};
  results.forEach(topic => { topicIds[topic.topic_id] = topic });
  otherResults.forEach(topic => {
      if (topicIds[topic.topic_id]) {
          return;
      }
      if (results.length > 15) {
          return;
      }

      results.push(topic);
  });

  if (results.length === 0) {
      return « No results found! »
  } else {
      return results;
  }
}

function processResults(json) {

    if (!json.topics) {
        return [];
    }

    const postData = {};
    json.posts.forEach( p => {
       postData[p.topic_id] = p;
    });

    // todo meta category map
    return json.topics.map(t => {
        let result = {};
        let post = postData[t.id];
        result.url = `/t/${t.slug}/${t.id}`;
        result.title = t.title;
        result.blurb = post.blurb;
        result.tags = t.tags;
        result.topic_id = t.id;
        result.category = categories[t.category_id];
        return result;
    });
}

function details() {
  return « Searching for: » + terms
}

L’outil de lecture utilise :

let topicId;
let url = « https://meta.discourse.org »;
const API_KEY = « ... »;
let title = « Unknown topic »;

function invoke(p) {
    topicId = p.topicId;
    let jsonUrl = `https://meta.discourse.org/t/${p.topic_id}.json?include_raw=true`;
    result = http.get(jsonUrl, { 'Api-Key' : API_KEY });

    try {
       const parsed = JSON.parse(result.body);
       url = `https://meta.discourse.org/t/${parsed.slug}/${parsed.id}`;
       title = parsed.title;
       let raw = parsed.post_stream.posts.map( post => {
          let solution = «  »;
          if (post.is_solution) {
              solution = « (solution) »;
          }
          return `post #${post.post_number}:${solution}\n${post.raw}`;
       }).join("\n\n");
       return llm.truncate(raw, 10000);
    } catch {
        return « Something went wrong, topic not found! »
    }
}
function details() {
  return `Read: <a href='${url}'>${title}</a>`;
}

3 « J'aime »