instructorExamplemain.tsx3 matches
1import Instructor from "https://esm.sh/@instructor-ai/instructor";
2import OpenAI from "https://esm.sh/openai";
3import { z } from "https://esm.sh/zod";
45const openAISecrets = {
6apiKey: getApiKey(),
7organization: getOrganisationKey(),
8};
910const oai = new OpenAI(openAISecrets);
1112const client = Instructor({
weatherGPTmain.tsx3 matches
1import { email } from "https://esm.town/v/std/email?v=11";
2import { fetch } from "https://esm.town/v/std/fetch";
3import { OpenAI } from "npm:openai";
45let location = "shenzhen";
9).then(r => r.json());
1011const openai = new OpenAI();
12let chatCompletion = await openai.chat.completions.create({
13messages: [{
14role: "user",
weatherGPTREADME.md1 match
1If you fork this, you'll need to set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).
23
gpt4Examplemain.tsx4 matches
1import { OpenAI } from "npm:openai";
2Deno.env.get("OPENAI_API_KEY");
34const openai = new OpenAI();
5let chatCompletion = await openai.chat.completions.create({
6messages: [{
7role: "user",
gpt4ExampleREADME.md1 match
3This uses the brand new `gpt-4-1106-preview`.
45To use this, set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).
get_weather_messagemain.tsx1 match
1import { chat } from "https://esm.town/v/cosmo/chat_openai";
2import { getCurrentWeather } from "https://esm.town/v/cosmo/get_current_weather";
3
chat_openaimain.tsx3 matches
1const { default: OpenAI } = await import("npm:openai");
23export async function chat(apiKey, messages) {
4const openai = new OpenAI({ apiKey });
56return openai.chat.completions.create({
7messages,
8model: "gpt-3.5-turbo",
draftReadmemain.tsx10 matches
1import { fetch } from "https://esm.town/v/std/fetch?v=4";
2import OpenAI, { type ClientOptions } from "npm:openai";
34export interface WriterOptions extends ClientOptions {
40}
4142async function performOpenAICall(prompt: string, model: string, openaiOptions: ClientOptions) {
43const openai = new OpenAI(openaiOptions);
4445try {
46const response = await openai.chat.completions.create({
47messages: [{ role: "system", content: prompt }],
48model: model,
5051if (!response.choices || response.choices.length === 0) {
52throw new Error("No response from OpenAI");
53}
545657if (!readme) {
58throw new Error("No readme returned by OpenAI. Try again.");
59}
608384async function draftReadme(options: WriterOptions) {
85const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
86const { id, code } = await getVal(username, valName);
87const prompt = createPrompt(code, userPrompt);
88const readme = await performOpenAICall(prompt, model, openaiOptions);
89return readme;
90}
9192async function writeReadme(options: WriterOptions) {
93const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
94const { id, code } = await getVal(username, valName);
95const prompt = createPrompt(code, userPrompt);
96const readme = await performOpenAICall(prompt, model, openaiOptions);
97try {
98const update = await updateReadme(id, readme);
WriterOptionsmain.tsx1 match
1import { type ClientOptions } from "npm:openai";
23export interface WriterOptions extends ClientOptions {
draftReadmeREADME.md3 matches
1# Code Documentation Assistant
23The Code Documentation Assistant is an AI-powered tool that helps generate documentation for code. It uses the OpenAI GPT-3.5 Turbo model to generate readme files in GitHub-flavored markdown based on the provided code.
45## Usage
24- `username` (string): The username of the code owner.
25- `valName` (string): The name of the Val containing the code.
26- `model` (optional, default: "gpt-3.5-turbo"): The OpenAI model to use for generating the readme.
27- `userPrompt` (optional): Additional prompt to include in the documentation.
2844- `username` (string): The username of the code owner.
45- `valName` (string): The name of the Val containing the code.
46- `model` (optional, default: "gpt-3.5-turbo"): The OpenAI model to use for generating the readme.
47- `userPrompt` (optional): Additional prompt to include in the documentation.
48