kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/643/head^2
rodzic
83cf65f9d0
commit
190ef0e100
|
@ -11,11 +11,12 @@ async function main() {
|
||||||
const weather = new WeatherClient()
|
const weather = new WeatherClient()
|
||||||
|
|
||||||
const result = await generateText({
|
const result = await generateText({
|
||||||
model: openai('gpt-4-turbo'),
|
model: openai('gpt-4o'),
|
||||||
tools: createAISDKTools(weather),
|
tools: createAISDKTools(weather),
|
||||||
toolChoice: 'required',
|
toolChoice: 'required',
|
||||||
prompt:
|
temperature: 0,
|
||||||
'What is the weather in San Francisco and what attractions should I visit?'
|
system: 'You are a weather assistant. Be as concise as possible.',
|
||||||
|
prompt: 'What is the weather in San Francisco?'
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(result.toolResults[0])
|
console.log(result.toolResults[0])
|
||||||
|
|
|
@ -1,73 +1,22 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import 'dotenv/config'
|
import 'dotenv/config'
|
||||||
|
|
||||||
import {
|
import { ChatModel, createAIRunner } from '@dexaai/dexter'
|
||||||
ChatModel,
|
|
||||||
createAIFunction,
|
|
||||||
createAIRunner,
|
|
||||||
Msg
|
|
||||||
} from '@dexaai/dexter'
|
|
||||||
import { z } from 'zod'
|
|
||||||
|
|
||||||
import { WeatherClient } from '../../src/index.js'
|
import { WeatherClient } from '../../src/index.js'
|
||||||
import { createDexterFunctions } from '../../src/sdks/dexter.js'
|
import { createDexterFunctions } from '../../src/sdks/dexter.js'
|
||||||
|
|
||||||
/** Get the capital city for a given state. */
|
|
||||||
const getCapitalCity = createAIFunction(
|
|
||||||
{
|
|
||||||
name: 'get_capital_city',
|
|
||||||
description: 'Use this to get the the capital city for a given state',
|
|
||||||
argsSchema: z.object({
|
|
||||||
state: z
|
|
||||||
.string()
|
|
||||||
.length(2)
|
|
||||||
.describe(
|
|
||||||
'The state to get the capital city for, using the two letter abbreviation e.g. CA'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
async ({ state }) => {
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
||||||
let capitalCity = ''
|
|
||||||
switch (state) {
|
|
||||||
case 'CA':
|
|
||||||
capitalCity = 'Sacramento'
|
|
||||||
break
|
|
||||||
case 'NY':
|
|
||||||
capitalCity = 'Albany'
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
capitalCity = 'Unknown'
|
|
||||||
}
|
|
||||||
return { capitalCity }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const weather = new WeatherClient()
|
|
||||||
|
|
||||||
/** A runner that uses the weather and capital city functions. */
|
|
||||||
const weatherCapitalRunner = createAIRunner({
|
|
||||||
chatModel: new ChatModel({ params: { model: 'gpt-4-1106-preview' } }),
|
|
||||||
functions: [...createDexterFunctions(weather), getCapitalCity],
|
|
||||||
systemMessage: `You use functions to answer questions about the weather and capital cities.`
|
|
||||||
})
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
// Run with a string input
|
const weather = new WeatherClient()
|
||||||
const rString = await weatherCapitalRunner(
|
|
||||||
`Whats the capital of California and NY and the weather for both?`
|
|
||||||
)
|
|
||||||
console.log('rString', rString)
|
|
||||||
|
|
||||||
// Run with a message input
|
const runner = createAIRunner({
|
||||||
const rMessage = await weatherCapitalRunner({
|
chatModel: new ChatModel({ params: { model: 'gpt-4o', temperature: 0 } }),
|
||||||
messages: [
|
functions: createDexterFunctions(weather),
|
||||||
Msg.user(
|
systemMessage: 'You are a weather assistant. Be as concise as possible.'
|
||||||
`Whats the capital of California and NY and the weather for both?`
|
|
||||||
)
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
console.log('rMessage', rMessage)
|
|
||||||
|
const result = await runner('What is the weather in San Francisco?')
|
||||||
|
console.log(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
await main()
|
await main()
|
||||||
|
|
|
@ -13,7 +13,7 @@ async function main() {
|
||||||
|
|
||||||
const tools = createLangChainTools(weather)
|
const tools = createLangChainTools(weather)
|
||||||
const agent = createToolCallingAgent({
|
const agent = createToolCallingAgent({
|
||||||
llm: new ChatOpenAI({ temperature: 0 }),
|
llm: new ChatOpenAI({ model: 'gpt-4o', temperature: 0 }),
|
||||||
tools,
|
tools,
|
||||||
prompt: ChatPromptTemplate.fromMessages([
|
prompt: ChatPromptTemplate.fromMessages([
|
||||||
['system', 'You are a weather assistant. Be as concise as possible.'],
|
['system', 'You are a weather assistant. Be as concise as possible.'],
|
||||||
|
@ -25,8 +25,8 @@ async function main() {
|
||||||
|
|
||||||
const agentExecutor = new AgentExecutor({
|
const agentExecutor = new AgentExecutor({
|
||||||
agent,
|
agent,
|
||||||
tools,
|
tools
|
||||||
verbose: true
|
// verbose: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const result = await agentExecutor.invoke({
|
const result = await agentExecutor.invoke({
|
||||||
|
|
Ładowanie…
Reference in New Issue