Open2

codestral 叩く

mizchimizchi

https://www.itmedia.co.jp/news/articles/2405/30/news139.htm

https://mistral.ai/news/codestral/l

現状preview版は申込みをしないと使えないが、アーリーアクセス申し込んで一晩寝たら朝には有効になってた。

deno でスクリプトを書く

Chat

import MistralClient from 'npm:@mistralai/mistralai';
const TOKEN = '...';
const ENDPOINT = 'https://codestral.mistral.ai';
const client = new MistralClient(TOKEN, ENDPOINT);

{
  // gen code from chat
  const res = await client.chat({
    model: 'codestral-latest',
    messages: [
      {
        role: 'user',
        content: `
React Counter component by typescript-jsx(tsx).
Markup it by tailwindcss.
Do not output any commentary other than the code.
Take props: { initialCount: number }
Use useCallback for the increment and decrement functions.
`
          .trim()
      }
    ]
  });

  const result = res.choices[0].message.content;
  console.log(result);
}
mizchimizchi

補完用の completion

import MistralClient from 'npm:@mistralai/mistralai';
const TOKEN = '...';
const ENDPOINT = 'https://codestral.mistral.ai';
const client = new MistralClient(TOKEN, ENDPOINT);

{
  // gen code from completion
  const res = await client.completion({
    model: 'codestral-latest',
    prompt: 'function add(a: number, b: number): number {',
    suffix: 'return result;\n}',
  });
  console.log(res.choices[0].message.content); // let result: number = a + b;
}