copilot-extensions / preview-sdk.js

An SDK that streamlines extension development by automating request verification, response formatting, and API interactions
MIT License
0 stars 4 forks source link

Wrap completions API #5

Open alexisabril opened 2 weeks ago

alexisabril commented 2 weeks ago

Similar to the Octokit REST APIs, a method could exist to invoke the completions API for 3P integrators.

For potential consistency, here an OpenAI-inspired version:

const stream = await octokit.copilot.completions.create({...});

for await (const chunk of stream) {
    process.stdout.write(chunk?...);
}

curl for completions:

curl --request POST \
  --url https://api.githubcopilot.com/chat/completions \
  --header 'Authorization: Bearer SUPERSECRET' \
  --header 'Content-Type: application/json' \
  --header 'Copilot-Integration-Id: dev' \
  --data '{
    "messages": [{ "role": "user", "content": "What'\''s the weather like today?" }],
    "max_tokens": 50,
    "temperature": 0.5
}'
gr2m commented 2 weeks ago

This might be relevant: https://github.com/github/gr2m-projects/blob/3d2bd092dfef7c3ebd4bb1bb4a5a48fa16c1b31d/167-github-models/README.md

gr2m commented 2 weeks ago

I figured we could add a prompt API as specced in the link above (WIP) to the context of the copilot extension SDK's event handlers, see https://github.com/copilot-extensions/preview-sdk.js/blob/main/dreamcode.md#api

Relevant part as of now (dreamcode.md will likely change soon):

// https://github.com/github/copilot-partners/blob/6d1cde3a1abb147da53f1a39864661dc824d40b5/docs/confirmations.md
copilotExtension.on(
  "confirmation",
  async ({ confirmation, octokit, prompt, respond, log }) => {
    if (confirmation.id === "joke") {
      if (confirmation.state === "dismissed") {
        await respond.text("Okay, maybe next time!");
        return;
      }

      await respond.text(
        prompt.stream("Please tell me a joke about Mona Lisa, Github's mascot.")
      );
      return;
    }

    log.warn("Received an unknown confirmation:", confirmation.id);
    await respond.text("Hmm, something went wrong. Please try again later.");
  }
);

Not sure what the best way will be yet, but I want the prompt and response APIs to work together nicely.