Skip to content

Commit 9e65270

Browse files
authoredSep 3, 2024
1 parent a75e01c commit 9e65270

File tree

1 file changed

+117
-1
lines changed

1 file changed

+117
-1
lines changed
 

‎dreamcode.md

+117-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ Please, any questions/feedback/feelings are welcome. This is a safe space. Pleas
1010
- Automated Payload verification
1111
- High-level APIs for different types of responses (text, confirmation, references, etc.)
1212
- High-level API for interacting with models
13+
- High-level API for function calls
14+
- High-level API for requesting user confirmation before a function is called
1315

14-
## API
16+
## Examples
17+
18+
### Tell a joke
1519

1620
```js
1721
import { createServer } from "http";
@@ -65,6 +69,118 @@ copilotExtension.on(
6569
await respond.text("Hmm, something went wrong. Please try again later.");
6670
}
6771
);
72+
```
73+
74+
### Book a flight
75+
76+
I'm using [@daveebbelaar](https://github.com/daveebbelaar)'s example of a flight booking agent that they demonstrate at https://www.youtube.com/watch?v=aqdWSYWC_LI
77+
78+
```js
79+
import { createServer } from "http";
80+
81+
import {
82+
CopilotExtension,
83+
createNodeMiddleware,
84+
} from "@octokit/copilot-extension";
85+
86+
const copilotExtension = new CopilotExtension({
87+
userAgent: "book-a-flight",
88+
89+
// TBD: are we supporting a default model? Globally, or for an enterprise/organization/user?
90+
model: {
91+
// either "gpt-3.5-turbo" or "gpt-4". Maybe "default" if we support that server-side or want to support that in the SDK?
92+
name: "gpt-4",
93+
// optional, setting to default for demo purposes
94+
endpoint: "https://api.githubcopilot.com/chat/completions",
95+
// when enabled, messages are passed through to Copilot's chat completions API
96+
// defaults to false. Set to true when `functions` is set
97+
passThrough: true,
98+
},
99+
100+
functions: [
101+
{
102+
name: "lookup_flight",
103+
description: "Look up a flight based on time, origin, and destination",
104+
parameters: {
105+
time: {
106+
type: "string",
107+
description:
108+
"The time when the flight should depart as ISO 8601 date time string",
109+
},
110+
origin: {
111+
type: "string",
112+
description: "The airport short code for the origin of the flight",
113+
},
114+
destination: {
115+
type: "string",
116+
description:
117+
"The airport short code for the destination of the flight",
118+
},
119+
},
120+
async run({ time, origin, destination }) {
121+
const result = await myFlightLookupFunction(time, origin, destination);
122+
return {
123+
departureTime: result.departureTime,
124+
timezoneDifference: result.timezoneDifference,
125+
arrivalTime: result.arrivalTime,
126+
travelTime: result.travelTime,
127+
flightNumber: result.flightNumber,
128+
airline: result.airline,
129+
originCity: result.originCity,
130+
originCode: result.originCode,
131+
destinationCity: result.destinationCity,
132+
destinationCode: result.destinationCode,
133+
travelTime: result.travelTime,
134+
};
135+
},
136+
},
137+
{
138+
name: "book_flight",
139+
description: "Book a flight based flight number and day",
140+
parameters: {
141+
flightNumber: {
142+
type: "string",
143+
description: "The flight number",
144+
},
145+
date: {
146+
type: "string",
147+
description: "The date of the flight as an ISO 8601 date string",
148+
},
149+
},
150+
// setting a confirmation key will prompt the user to confirm an action before it is taken
151+
confirmation: {
152+
title: "Confirm you want me to book the following flight",
153+
message(parameters) {
154+
return `Yes, please book flight ${parameters.flightNumber} on ${parameters.date}`;
155+
},
156+
},
157+
async run({ flightNumber, date }) {
158+
const result = await myFlightBookingFunction(flightNumber, date);
159+
return {
160+
flightNumber,
161+
departureTime: result.date,
162+
confirmationNumber: result.confirmationNumber,
163+
seat: result.seat,
164+
};
165+
},
166+
},
167+
],
168+
});
169+
170+
// you can still hook into messages and function calls before they are passed through
171+
// to the chat completions API.
172+
copilotExtension.on("message", async ({ log }) => {
173+
log.info("Received a message:", message.content);
174+
175+
// if you don't want a request to be forwarded to the chat completions API, call `await respond.done()` explicitly
176+
});
177+
copilotExtension.on("function_call", async ({ log, name, parameters }) => {
178+
log.info(
179+
"Received a function call for %s with parameters %o",
180+
name,
181+
parameters
182+
);
183+
});
68184

69185
createServer(createNodeMiddleware(copilotExtension)).listen(3000);
70186
copilotExtension.log.info("Listening on http://localhost:3000");

0 commit comments

Comments
 (0)
Failed to load comments.