1import { OpenAI } from "npm:openai";
2
3// Create a secret named OPENAI_API_KEY at https://www.val.town/settings/environment-variables
4
5const openai = new OpenAI();
6const functionExpression = await openai.chat.completions.create({
7 "messages": [
8 { "role": "user", "content": "Say hello in a creative way" },
1Example of using Hono to stream OpenAI's streamed chat responses!
2
3Migrated from folder: Utils/ai/examples/openAIHonoChatStreamExample
1import { fetch } from "https://esm.town/v/std/fetch";
2import { Hono } from "npm:hono";
3import { OpenAI } from "npm:openai";
4
5const gistGPT = async (input: string, about?: boolean) => {
8 const chatInput = about ? input : await (await fetch(input)).text();
9
10 const openai = new OpenAI();
11 let chatCompletion = await openai.chat.completions.create({
12 messages: [
13 {
1/** @jsxImportSource npm:hono@3/jsx */
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
3import { chat } from "https://esm.town/v/stevekrouse/openai";
4import cronstrue from "npm:cronstrue";
5import { Hono } from "npm:hono@3";
1import { Hono } from "npm:hono";
2import { OpenAI } from "npm:openai";
3
4const priestGPT = async (verse: string, about?: boolean) => {
5 const openai = new OpenAI();
6 let chatCompletion = await openai.chat.completions.create({
7 messages: [
8 {
11
12
13If you fork this, you'll need to set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).
14
15
2import { fetchWebpage } from "https://esm.town/v/jdan/fetchWebpage";
3import { weatherOfLatLon } from "https://esm.town/v/jdan/weatherOfLatLon";
4import { OpenAI } from "https://esm.town/v/std/openai?v=4";
5
6const openai = new OpenAI();
7
8const toolbox = {
9 "latLngOfCity": {
10 openAiTool: {
11 type: "function",
12 function: {
33 },
34 "weatherOfLatLon": {
35 openAiTool: {
36 type: "function",
37 function: {
60 },
61 "fetchWebpage": {
62 openAiTool: {
63 type: "function",
64 function: {
82};
83
84const tools = Object.values(toolbox).map(({ openAiTool }) => openAiTool);
85const transcript = [
86 { role: "user", content: "What's the weather in Hoboken, NJ? Do your best to follow URLs and summarize the weather instead of having the user do it." },
94
95async function runConversation() {
96 const response = await openai.chat.completions.create({
97 messages: transcript,
98 tools,
1Migrated from folder: openai_function_calling/fetchWebpage
1Migrated from folder: openai_function_calling/weatherOfLatLon
1Migrated from folder: openai_function_calling/latLngOfCity