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
1import { type WriterOptions } from "https://esm.town/v/nbbaier/WriterOptions";
2import { fetch } from "https://esm.town/v/std/fetch?v=4";
3import OpenAI, { type ClientOptions } from "npm:openai";
45export class ReadmeWriter {
6model: string;
7openai: OpenAI;
8apiKey: string;
9valtownKey: string;
1011constructor(options: WriterOptions) {
12const { model, ...openaiOptions } = options;
13this.model = model ? model : "gpt-3.5-turbo";
14this.openai = new OpenAI(openaiOptions);
15this.valtownKey = Deno.env.get("valtown");
16}
47}
4849private async performOpenAICall(prompt: string) {
50try {
51const response = await this.openai.chat.completions.create({
52messages: [{ role: "system", content: prompt }],
53model: this.model,
5556if (!response.choices || response.choices.length === 0) {
57throw new Error("No response from OpenAI");
58}
596162if (!readme) {
63throw new Error("No readme returned by OpenAI. Try again.");
64}
6592const { id, code } = await this.getVal(username, valName);
93const prompt = this.createPrompt(code, userPrompt);
94const readme = await this.performOpenAICall(prompt);
95return { id, readme };
96}
sqliteWritermain.tsx11 matches
1import { type WriterOptions } from "https://esm.town/v/nbbaier/WriterOptions";
2import { sqlite } from "https://esm.town/v/std/sqlite";
3import OpenAI from "npm:openai";
45interface QueryWriterOptons extends WriterOptions {
11model: string;
12apiKey: string;
13openai: OpenAI;
1415constructor(options: QueryWriterOptons) {
16const { table, model, ...openaiOptions } = options;
17this.table = table;
18this.model = model;
19// this.apiKey = openaiOptions.apiKey ? openaiOptions.apiKey : Deno.env.get("OPENAI_API_KEY");
20this.openai = new OpenAI(openaiOptions);
21}
225455try {
56const response = await this.openai.chat.completions.create({
57messages: [{ role: "system", content: prompt }],
58model: this.model,
6061if (!response.choices || response.choices.length === 0) {
62throw new Error("No response from OpenAI");
63}
646667if (!query) {
68throw new Error("No SQL returned from OpenAI. Try again.");
69}
708081try {
82const response = await this.openai.chat.completions.create({
83messages: [{ role: "system", content: prompt }],
84model: this.model,
8687if (!response.choices || response.choices.length === 0) {
88throw new Error("No response from OpenAI");
89}
909293if (!query) {
94throw new Error("No SQL returned from OpenAI. Try again.");
95}
96