chatgpt-api/scratch/examples/misc.ts

84 wiersze
2.2 KiB
TypeScript
Czysty Zwykły widok Historia

2023-06-01 01:53:09 +00:00
import 'dotenv/config'
2023-05-26 03:30:36 +00:00
import { OpenAIClient } from 'openai-fetch'
import { z } from 'zod'
2023-05-26 03:30:36 +00:00
import { Agentic } from '../src'
async function main() {
const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
const $ = new Agentic({ openai })
const ex0 = await $.gpt4(`give me a single boolean value: `)
.output(z.boolean())
2023-05-26 03:30:36 +00:00
// .retry({ attempts: 3 })
.call()
// LLM
// give me a single boolean value
// given an output as a boolean.
// true/false
2023-05-02 06:44:08 +00:00
const ex1 = await $.gpt4('give me a list of character names from star wars')
.output(z.array(z.string().nonempty()))
2023-05-26 03:30:36 +00:00
// .stream()
.call()
const ex2 = await $.gpt4(`Summarize the following text: {{text}}`)
.output(z.string().nonempty())
.input(z.object({ text: z.string().nonempty() }))
.call({
text: 'The quick brown fox jumps over the lazy dog.'
})
2023-05-26 03:30:36 +00:00
// const ext22 = await $.gpt4({ temperature: 0 }).call({
// messages: [
// // TEST
// ]
// })
const ex3 = await $.gpt4({
temperature: 0,
messages: [
{
role: 'system',
content: 'You extract movie titles from text.'
},
{
role: 'user',
content: `Extract the movie title from the following text or return 'none' if no movie title is found.`
}
]
})
.examples([
{
input: `Deadpool 2 | Official HD Deadpool's "Wet on Wet" Teaser | 2018`,
output: `Deadpool 2`
},
{
input: `Jordan Peele Just Became the First Black Writer-Director With a $100M Movie Debut`,
output: 'none'
},
{
input: 'Joker Officially Rated “R”',
output: 'Joker'
},
{
input: `Ryan Reynolds 'Free Guy' Receives July 3, 2020 Release Date - About a bank teller stuck in his routine that discovers hes an NPC character in a brutal open world game.`,
output: 'Free Guy'
},
{
input: 'James Cameron congratulates Kevin Feige and Marvel!',
output: 'none'
},
{
input:
'The Cast of Guardians of the Galaxy release statement on James Gunn',
output: 'Guardians of the Galaxy'
}
])
.output(z.string().nonempty())
.call()
}
2023-05-26 03:30:36 +00:00
main()